@@ -39,7 +39,7 @@ type BuildData = {
3939type FileEvent = "add" | "change" | "delete"
4040
4141function newBuildId ( ) {
42- return new Date ( ) . toISOString ( )
42+ return Math . random ( ) . toString ( 36 ) . substring ( 2 , 8 )
4343}
4444
4545async function buildQuartz ( argv : Argv , mut : Mutex , clientRefresh : ( ) => void ) {
@@ -162,17 +162,19 @@ async function partialRebuildFromEntrypoint(
162162 return
163163 }
164164
165- const buildStart = new Date ( ) . getTime ( )
166- buildData . lastBuildMs = buildStart
165+ const buildId = newBuildId ( )
166+ ctx . buildId = buildId
167+ buildData . lastBuildMs = new Date ( ) . getTime ( )
167168 const release = await mut . acquire ( )
168- if ( buildData . lastBuildMs > buildStart ) {
169+
170+ // if there's another build after us, release and let them do it
171+ if ( ctx . buildId !== buildId ) {
169172 release ( )
170173 return
171174 }
172175
173176 const perf = new PerfTimer ( )
174177 console . log ( chalk . yellow ( "Detected change, rebuilding..." ) )
175- ctx . buildId = newBuildId ( )
176178
177179 // UPDATE DEP GRAPH
178180 const fp = joinSegments ( argv . directory , toPosixPath ( filepath ) ) as FilePath
@@ -357,19 +359,19 @@ async function rebuildFromEntrypoint(
357359 toRemove . add ( filePath )
358360 }
359361
360- const buildStart = new Date ( ) . getTime ( )
361- buildData . lastBuildMs = buildStart
362+ const buildId = newBuildId ( )
363+ ctx . buildId = buildId
364+ buildData . lastBuildMs = new Date ( ) . getTime ( )
362365 const release = await mut . acquire ( )
363366
364367 // there's another build after us, release and let them do it
365- if ( buildData . lastBuildMs > buildStart ) {
368+ if ( ctx . buildId !== buildId ) {
366369 release ( )
367370 return
368371 }
369372
370373 const perf = new PerfTimer ( )
371374 console . log ( chalk . yellow ( "Detected change, rebuilding..." ) )
372- ctx . buildId = newBuildId ( )
373375
374376 try {
375377 const filesToRebuild = [ ...toRebuild ] . filter ( ( fp ) => ! toRemove . has ( fp ) )
@@ -405,10 +407,10 @@ async function rebuildFromEntrypoint(
405407 }
406408 }
407409
408- release ( )
409410 clientRefresh ( )
410411 toRebuild . clear ( )
411412 toRemove . clear ( )
413+ release ( )
412414}
413415
414416export default async ( argv : Argv , mut : Mutex , clientRefresh : ( ) => void ) => {
0 commit comments