@@ -13,6 +13,7 @@ import { BuildOutputFileType } from '../../tools/esbuild/bundler-context';
13
13
import { ExecutionResult , RebuildState } from '../../tools/esbuild/bundler-execution-result' ;
14
14
import { shutdownSassWorkerPool } from '../../tools/esbuild/stylesheets/sass-language' ;
15
15
import { logMessages , withNoProgress , withSpinner } from '../../tools/esbuild/utils' ;
16
+ import { ChangedFiles } from '../../tools/esbuild/watcher' ;
16
17
import { shouldWatchRoot } from '../../utils/environment-options' ;
17
18
import { NormalizedCachedOptions } from '../../utils/normalize-cache' ;
18
19
import { NormalizedApplicationBuildOptions , NormalizedOutputOptions } from './options' ;
@@ -199,7 +200,8 @@ export async function* runEsBuildBuildAction(
199
200
for ( const outputResult of emitOutputResults (
200
201
result ,
201
202
outputOptions ,
202
- incrementalResults ? rebuildState . previousOutputInfo : undefined ,
203
+ changes ,
204
+ incrementalResults ? rebuildState : undefined ,
203
205
) ) {
204
206
yield outputResult ;
205
207
}
@@ -224,7 +226,8 @@ function* emitOutputResults(
224
226
templateUpdates,
225
227
} : ExecutionResult ,
226
228
outputOptions : NormalizedApplicationBuildOptions [ 'outputOptions' ] ,
227
- previousOutputInfo ?: ReadonlyMap < string , { hash : string ; type : BuildOutputFileType } > ,
229
+ changes ?: ChangedFiles ,
230
+ rebuildState ?: RebuildState ,
228
231
) : Iterable < Result > {
229
232
if ( errors . length > 0 ) {
230
233
yield {
@@ -255,7 +258,9 @@ function* emitOutputResults(
255
258
}
256
259
257
260
// Use an incremental result if previous output information is available
258
- if ( previousOutputInfo ) {
261
+ if ( rebuildState && changes ) {
262
+ const { previousAssetsInfo, previousOutputInfo } = rebuildState ;
263
+
259
264
const incrementalResult : IncrementalResult = {
260
265
kind : ResultKind . Incremental ,
261
266
warnings : warnings as ResultMessage [ ] ,
@@ -273,7 +278,6 @@ function* emitOutputResults(
273
278
274
279
// Initially assume all previous output files have been removed
275
280
const removedOutputFiles = new Map ( previousOutputInfo ) ;
276
-
277
281
for ( const file of outputFiles ) {
278
282
removedOutputFiles . delete ( file . path ) ;
279
283
@@ -304,24 +308,37 @@ function* emitOutputResults(
304
308
}
305
309
}
306
310
307
- // Include the removed output files
311
+ // Initially assume all previous assets files have been removed
312
+ const removedAssetFiles = new Map ( previousAssetsInfo ) ;
313
+ for ( const { source, destination } of assetFiles ) {
314
+ removedAssetFiles . delete ( source ) ;
315
+
316
+ if ( changes . modified . has ( source ) ) {
317
+ incrementalResult . modified . push ( destination ) ;
318
+ } else if ( ! previousAssetsInfo . has ( source ) ) {
319
+ incrementalResult . added . push ( destination ) ;
320
+ } else {
321
+ continue ;
322
+ }
323
+
324
+ incrementalResult . files [ destination ] = {
325
+ type : BuildOutputFileType . Browser ,
326
+ inputPath : source ,
327
+ origin : 'disk' ,
328
+ } ;
329
+ }
330
+
331
+ // Include the removed output and asset files
308
332
incrementalResult . removed . push (
309
333
...Array . from ( removedOutputFiles , ( [ file , { type } ] ) => ( {
310
334
path : file ,
311
335
type,
312
336
} ) ) ,
313
- ) ;
314
-
315
- // Always consider asset files as added to ensure new/modified assets are available.
316
- // TODO: Consider more comprehensive asset analysis.
317
- for ( const file of assetFiles ) {
318
- incrementalResult . added . push ( file . destination ) ;
319
- incrementalResult . files [ file . destination ] = {
337
+ ...Array . from ( removedAssetFiles . values ( ) , ( file ) => ( {
338
+ path : file ,
320
339
type : BuildOutputFileType . Browser ,
321
- inputPath : file . source ,
322
- origin : 'disk' ,
323
- } ;
324
- }
340
+ } ) ) ,
341
+ ) ;
325
342
326
343
yield incrementalResult ;
327
344
0 commit comments