@@ -76,43 +76,49 @@ async function main() {
7676 await mkdir ( staging , { recursive : true } ) ;
7777 await mkdir ( dist , { recursive : true } ) ;
7878
79- // Splitting OFF: each entry is a single self-contained file with no
80- // shared `chunk-*.js`. The browser surface is one request
81- // (`webjs-core-browser.js`); the handful of other entries (the Node
82- // full bundle, the on-demand lazy loader, the test helpers) duplicate
83- // the small amount of code they share, which is a cheap tarball cost
84- // (never shipped to a browser) in exchange for a clean, waterfall-free
85- // network graph. The few entries mean little duplication in practice.
86- const result = await build ( {
87- entryPoints : ENTRIES . map ( ( e ) => ( { in : join ( CORE , e . in ) , out : e . out } ) ) ,
88- outdir : staging ,
89- bundle : true ,
90- splitting : false ,
91- format : 'esm' ,
92- target : 'es2022' ,
93- platform : 'browser' ,
94- sourcemap : 'linked' ,
95- sourcesContent : false ,
96- minify : true ,
97- treeShaking : true ,
98- metafile : true ,
99- logLevel : 'info' ,
100- legalComments : 'none' ,
101- } ) ;
102-
103- // Move every bundle into place (a rename over an existing file is atomic on
104- // the same filesystem), then drop whatever the previous build left that this
105- // one did not produce, then the empty staging dir.
10679 const produced = new Set ( ) ;
107- for ( const outFile of Object . keys ( result . metafile . outputs ) ) {
108- const name = basename ( outFile ) ;
109- await rename ( outFile , join ( dist , name ) ) ;
110- produced . add ( name ) ;
111- }
112- for ( const stale of await readdir ( dist ) ) {
113- if ( ! produced . has ( stale ) ) await rm ( join ( dist , stale ) , { recursive : true , force : true } ) ;
80+ try {
81+ // Splitting OFF: each entry is a single self-contained file with no
82+ // shared `chunk-*.js`. The browser surface is one request
83+ // (`webjs-core-browser.js`); the handful of other entries (the Node
84+ // full bundle, the on-demand lazy loader, the test helpers) duplicate
85+ // the small amount of code they share, which is a cheap tarball cost
86+ // (never shipped to a browser) in exchange for a clean, waterfall-free
87+ // network graph. The few entries mean little duplication in practice.
88+ const result = await build ( {
89+ entryPoints : ENTRIES . map ( ( e ) => ( { in : join ( CORE , e . in ) , out : e . out } ) ) ,
90+ outdir : staging ,
91+ bundle : true ,
92+ splitting : false ,
93+ format : 'esm' ,
94+ target : 'es2022' ,
95+ platform : 'browser' ,
96+ sourcemap : 'linked' ,
97+ sourcesContent : false ,
98+ minify : true ,
99+ treeShaking : true ,
100+ metafile : true ,
101+ logLevel : 'info' ,
102+ legalComments : 'none' ,
103+ } ) ;
104+
105+ // Move every bundle into place (a rename over an existing file is atomic
106+ // on the same filesystem), then drop whatever the previous build left that
107+ // this one did not produce.
108+ for ( const outFile of Object . keys ( result . metafile . outputs ) ) {
109+ const name = basename ( outFile ) ;
110+ await rename ( outFile , join ( dist , name ) ) ;
111+ produced . add ( name ) ;
112+ }
113+ for ( const stale of await readdir ( dist ) ) {
114+ if ( ! produced . has ( stale ) ) await rm ( join ( dist , stale ) , { recursive : true , force : true } ) ;
115+ }
116+ } finally {
117+ // On every path, including an esbuild failure: the staging sibling is not
118+ // matched by the `.gitignore` `dist` pattern, so one left behind by a
119+ // build that threw would show up untracked and ride a `git add -A`.
120+ await rm ( staging , { recursive : true , force : true } ) ;
114121 }
115- await rm ( staging , { recursive : true , force : true } ) ;
116122
117123 // Sanity-check: every entry produced an output file with the
118124 // expected name. If esbuild ever changes its naming, fail loud
0 commit comments