22import process from "process" ;
33import * as esbuild from "esbuild" ;
44
5- let watchConfig = ( entry ) => {
6- return {
7- onRebuild ( error , result ) {
8- console . log ( `[watch] build started (rebuild for ${ entry } )` ) ;
9- if ( error ) {
10- error . errors . forEach ( ( error ) =>
11- console . error (
12- `> ${ error . location . file } :${ error . location . line } :${ error . location . column } : error: ${ error . text } `
13- )
14- ) ;
15- } else console . log ( `[watch] build finished (rebuild for ${ entry } ` ) ;
16- } ,
17- } ;
18- } ;
19-
20- let watch = process . argv . includes ( "--watch" ) ? watchConfig : ( entry ) => false ;
215let minify = process . argv . includes ( "--minify" ) ;
226let disable_sourcemap = process . argv . includes ( "--sourcemap=no" ) ;
237let sourcemap_client = disable_sourcemap ? null : { sourcemap : true } ;
248let sourcemap_view = disable_sourcemap ? null : { sourcemap : "inline" } ;
259
10+ let enableMeta = false ;
11+
12+ const plugins = [
13+ {
14+ name : "esbuild-problem-matcher" ,
15+ setup ( build ) {
16+ let file = build . initialOptions . entryPoints [ 0 ] ;
17+
18+ build . onStart ( ( ) => {
19+ console . log ( `[watch] build started for ${ file } ` ) ;
20+ } ) ;
21+
22+ build . onEnd ( ( result ) => {
23+ if ( result . errors . length > 0 ) {
24+ result . errors . forEach ( ( e ) =>
25+ console . error (
26+ `> ${ e . location . file } :${ e . location . line } :${ e . location . column } : error: ${ e . text } `
27+ )
28+ ) ;
29+ } else {
30+ console . log ( `[watch] build finished for ${ file } ` ) ;
31+ if ( enableMeta ) {
32+ fs . writeFileSync (
33+ `${ file } .json` ,
34+ JSON . stringify ( result . metafile , null , 2 )
35+ ) ;
36+ }
37+ }
38+ } ) ;
39+ } ,
40+ } ,
41+ ] ;
42+
43+ const watchContext = async ( ctxp ) => {
44+ let ctx = await ctxp ;
45+
46+ if ( process . argv . includes ( "--watch" ) ) {
47+ await ctx . watch ( ) ;
48+ } else {
49+ await ctx . rebuild ( ) ;
50+ await ctx . dispose ( ) ;
51+ }
52+ } ;
53+
2654// Build of the VS Code extension, for electron (hence cjs + node)
27- var node = esbuild
28- . build ( {
55+ var node = watchContext (
56+ esbuild . context ( {
2957 entryPoints : [ "./src/node.ts" ] ,
3058 bundle : true ,
3159 ...sourcemap_client ,
@@ -34,15 +62,12 @@ var node = esbuild
3462 external : [ "vscode" ] ,
3563 outfile : "out/src/node.js" ,
3664 minify,
37- watch : watch ( "./src/node.ts" ) ,
65+ plugins ,
3866 } )
39- . then ( ( ) => {
40- console . log ( "[watch] build finished for ./src/node.ts" ) ;
41- } )
42- . catch ( ( ) => process . exit ( 1 ) ) ;
67+ ) ;
4368
44- var browser = esbuild
45- . build ( {
69+ var browser = watchContext (
70+ esbuild . context ( {
4671 entryPoints : [ "./src/browser.ts" ] ,
4772 bundle : true ,
4873 ...sourcemap_client ,
@@ -51,30 +76,24 @@ var browser = esbuild
5176 external : [ "vscode" ] ,
5277 outfile : "out/src/browser.js" ,
5378 minify,
54- watch : watch ( "./src/browser.ts" ) ,
55- } )
56- . then ( ( ) => {
57- console . log ( "[watch] build finished for ./src/browser.ts" ) ;
79+ plugins,
5880 } )
59- . catch ( ( ) => process . exit ( 1 ) ) ;
81+ ) ;
6082
6183// Build of the VS Code view, for modern Chrome (webview)
6284function viewBuild ( file ) {
63- return esbuild
64- . build ( {
85+ return watchContext (
86+ esbuild . context ( {
6587 entryPoints : [ file ] ,
6688 bundle : true ,
6789 ...sourcemap_view ,
6890 platform : "browser" ,
6991 outdir : "out" ,
7092 outbase : "." ,
7193 minify,
72- watch : watch ( file ) ,
73- } )
74- . then ( ( ) => {
75- console . log ( `[watch] build finished for ${ file } ` ) ;
94+ plugins,
7695 } )
77- . catch ( ( ) => process . exit ( 1 ) ) ;
96+ ) ;
7897}
7998
8099var infoView = viewBuild ( "./views/info/index.tsx" ) ;
0 commit comments