99import { BuilderContext } from '@angular-devkit/architect' ;
1010import { existsSync } from 'node:fs' ;
1111import path from 'node:path' ;
12- import { ExecutionResult , RebuildState } from '../../tools/esbuild/bundler-execution-result' ;
12+ import {
13+ BuildOutputAsset ,
14+ ExecutionResult ,
15+ RebuildState ,
16+ } from '../../tools/esbuild/bundler-execution-result' ;
1317import { BuildOutputFile , BuildOutputFileType } from '../../tools/esbuild/bundler-files' ;
1418import { shutdownSassWorkerPool } from '../../tools/esbuild/stylesheets/sass-language' ;
1519import { logMessages , withNoProgress , withSpinner } from '../../tools/esbuild/utils' ;
@@ -279,34 +283,15 @@ function* emitOutputResults(
279283
280284 // Use a full result if there is no rebuild state (no prior build result)
281285 if ( ! rebuildState || ! changes ) {
282- const result : FullResult = {
283- kind : ResultKind . Full ,
284- warnings : warnings as ResultMessage [ ] ,
285- files : { } ,
286- detail : {
287- externalMetadata,
288- htmlIndexPath,
289- htmlBaseHref,
290- outputOptions,
291- } ,
292- } ;
293- for ( const file of assetFiles ) {
294- result . files [ file . destination ] = {
295- type : BuildOutputFileType . Browser ,
296- inputPath : file . source ,
297- origin : 'disk' ,
298- } ;
299- }
300- for ( const file of outputFiles ) {
301- result . files [ file . path ] = {
302- type : file . type ,
303- contents : file . contents ,
304- origin : 'memory' ,
305- hash : file . hash ,
306- } ;
307- }
308-
309- yield result ;
286+ yield createFullResult (
287+ outputFiles ,
288+ assetFiles ,
289+ warnings ,
290+ outputOptions ,
291+ externalMetadata ,
292+ htmlIndexPath ,
293+ htmlBaseHref ,
294+ ) ;
310295
311296 return ;
312297 }
@@ -326,7 +311,7 @@ function* emitOutputResults(
326311 added : [ ] ,
327312 removed : [ ] ,
328313 modified : [ ] ,
329- files : { } ,
314+ files : [ ] ,
330315 detail : {
331316 externalMetadata,
332317 htmlIndexPath,
@@ -340,9 +325,10 @@ function* emitOutputResults(
340325 // Initially assume all previous output files have been removed
341326 const removedOutputFiles = new Map ( previousOutputInfo ) ;
342327 for ( const file of outputFiles ) {
343- removedOutputFiles . delete ( file . path ) ;
328+ const key = `${ file . type } :${ file . path } ` ;
329+ removedOutputFiles . delete ( key ) ;
344330
345- const previousHash = previousOutputInfo . get ( file . path ) ?. hash ;
331+ const previousHash = previousOutputInfo . get ( key ) ?. hash ;
346332 let needFile = false ;
347333 if ( previousHash === undefined ) {
348334 needFile = true ;
@@ -359,12 +345,13 @@ function* emitOutputResults(
359345 incrementalResult . background = false ;
360346 }
361347
362- incrementalResult . files [ file . path ] = {
348+ incrementalResult . files . push ( {
349+ path : file . path ,
363350 type : file . type ,
364351 contents : file . contents ,
365352 origin : 'memory' ,
366353 hash : file . hash ,
367- } ;
354+ } ) ;
368355 }
369356 }
370357
@@ -385,11 +372,12 @@ function* emitOutputResults(
385372
386373 hasCssUpdates ||= destination . endsWith ( '.css' ) ;
387374
388- incrementalResult . files [ destination ] = {
375+ incrementalResult . files . push ( {
376+ path : destination ,
389377 type : BuildOutputFileType . Browser ,
390378 inputPath : source ,
391379 origin : 'disk' ,
392- } ;
380+ } ) ;
393381 }
394382
395383 // Do not remove stale files yet if there are template updates.
@@ -403,12 +391,12 @@ function* emitOutputResults(
403391
404392 // Include the removed output and asset files
405393 incrementalResult . removed . push (
406- ...Array . from ( removedOutputFiles , ( [ file , { type } ] ) => ( {
407- path : file ,
394+ ...Array . from ( removedOutputFiles . values ( ) , ( { type, path } ) => ( {
395+ path,
408396 type,
409397 } ) ) ,
410- ...Array . from ( removedAssetFiles . values ( ) , ( file ) => ( {
411- path : file ,
398+ ...Array . from ( removedAssetFiles . values ( ) , ( path ) => ( {
399+ path,
412400 type : BuildOutputFileType . Browser ,
413401 } ) ) ,
414402 ) ;
@@ -425,9 +413,7 @@ function* emitOutputResults(
425413 added : incrementalResult . added . filter ( isCssFilePath ) ,
426414 removed : incrementalResult . removed . filter ( ( { path } ) => isCssFilePath ( path ) ) ,
427415 modified : incrementalResult . modified . filter ( isCssFilePath ) ,
428- files : Object . fromEntries (
429- Object . entries ( incrementalResult . files ) . filter ( ( [ path ] ) => isCssFilePath ( path ) ) ,
430- ) ,
416+ files : incrementalResult . files . filter ( ( file ) => isCssFilePath ( file . path ) ) ,
431417 } ;
432418
433419 yield styleResult ;
@@ -446,6 +432,42 @@ function* emitOutputResults(
446432 }
447433}
448434
435+ function createFullResult (
436+ outputFiles : readonly BuildOutputFile [ ] ,
437+ assetFiles : readonly BuildOutputAsset [ ] ,
438+ warnings : readonly unknown [ ] ,
439+ outputOptions : NormalizedApplicationBuildOptions [ 'outputOptions' ] ,
440+ externalMetadata : unknown ,
441+ htmlIndexPath : unknown ,
442+ htmlBaseHref : unknown ,
443+ ) : FullResult {
444+ return {
445+ kind : ResultKind . Full ,
446+ warnings : warnings as ResultMessage [ ] ,
447+ files : [
448+ ...assetFiles . map ( ( { source, destination } ) => ( {
449+ path : destination ,
450+ type : BuildOutputFileType . Browser ,
451+ inputPath : source ,
452+ origin : 'disk' as const ,
453+ } ) ) ,
454+ ...outputFiles . map ( ( file ) => ( {
455+ path : file . path ,
456+ type : file . type ,
457+ contents : file . contents ,
458+ origin : 'memory' as const ,
459+ hash : file . hash ,
460+ } ) ) ,
461+ ] ,
462+ detail : {
463+ externalMetadata,
464+ htmlIndexPath,
465+ htmlBaseHref,
466+ outputOptions,
467+ } ,
468+ } ;
469+ }
470+
449471function isCssFilePath ( filePath : string ) : boolean {
450472 return / \. c s s (?: \. m a p ) ? $ / i. test ( filePath ) ;
451473}
0 commit comments