11import { existsSync , rm , rmSync , writeFileSync } from "fs" ;
22// import { buildOptions } from "./context";
33import { request } from "http" ;
4- import { readFile } from "fs/promises" ;
4+ import { readFile , writeFile } from "fs/promises" ;
55import { basename , join , relative , resolve } from "path" ;
66import { checkPath , dist_resolve , SendError , SendErrorReasonData , ServerRequest , ServerRoute } from "@tiddlywiki/server" ;
77import { createHash } from "crypto" ;
@@ -63,7 +63,7 @@ function parseMetafileEntryPoints({ entryPoints, result, publicdir }: {
6363 relative ( publicdir , e [ 1 ] . cssBundle ! )
6464 ) ;
6565
66- writeFileSync ( publicdir + ".json" , JSON . stringify ( result . metafile ) ) ;
66+
6767
6868 const maxwidth = outputs . reduce ( ( a , [ b ] ) => Math . max ( a , b . length ) , 0 ) ;
6969
@@ -162,9 +162,9 @@ export async function runBuildOnce({ rootdir, publicdir }: { rootdir: string; pu
162162 // errors cause this to reject
163163 const result = await esbuild . build ( options ) ;
164164 console . timeEnd ( timeTag ) ;
165-
166165 const { js, css } = parseMetafileEntryPoints ( { entryPoints, result, publicdir } ) ;
167166
167+ await writeFile ( publicdir + ".json" , JSON . stringify ( result . metafile ) ) ;
168168 await generateHtml ( { js, css, rootdir, publicdir } ) ;
169169
170170 return result ;
@@ -196,6 +196,7 @@ async function startDevServer({ rootdir, publicdir }: { rootdir: string; publicd
196196 // errors cause this to reject
197197 const result = await ctx . rebuild ( ) ;
198198 const { css, js } = parseMetafileEntryPoints ( { entryPoints, result, publicdir } ) ;
199+ await writeFile ( publicdir + ".json" , JSON . stringify ( result . metafile ) ) ;
199200 await generateHtml ( { js, css, rootdir, publicdir } ) ;
200201 }
201202
@@ -204,8 +205,8 @@ async function startDevServer({ rootdir, publicdir }: { rootdir: string; publicd
204205 return async function sendDevServer ( state : ServerRequest , indexOptions ?: { status : number , serverResponse : ServerToReactAdmin } ) : Promise < typeof STREAM_ENDED > {
205206 // this will rebuild the html on page load
206207 // if the build fails, esbuild will serve the error so we just ignore it
207-
208- if ( state . headers [ "sec-fetch-dest" ] === "document" ) await rebuild ( ) . catch ( ( ) => { } ) ;
208+ if ( state . headers [ "sec-fetch-dest" ] === "document" )
209+ await rebuild ( ) . catch ( ( e ) => { if ( ! ( e . errors && e . warnings ) ) throw e ; } ) ;
209210
210211 if ( indexOptions ) return await serveIndex ( { state, publicdir, status : indexOptions . status , serverResponse : indexOptions . serverResponse } ) ;
211212
0 commit comments