@@ -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
yield emitOutputResult (
200
201
result ,
201
202
outputOptions ,
202
- incrementalResults ? rebuildState . previousOutputInfo : undefined ,
203
+ changes ,
204
+ incrementalResults ? rebuildState : undefined ,
203
205
) ;
204
206
}
205
207
} finally {
@@ -222,7 +224,8 @@ function emitOutputResult(
222
224
templateUpdates,
223
225
} : ExecutionResult ,
224
226
outputOptions : NormalizedApplicationBuildOptions [ 'outputOptions' ] ,
225
- previousOutputInfo ?: ReadonlyMap < string , { hash : string ; type : BuildOutputFileType } > ,
227
+ changes ?: ChangedFiles ,
228
+ rebuildState ?: RebuildState ,
226
229
) : Result {
227
230
if ( errors . length > 0 ) {
228
231
return {
@@ -251,7 +254,9 @@ function emitOutputResult(
251
254
}
252
255
253
256
// Use an incremental result if previous output information is available
254
- if ( previousOutputInfo ) {
257
+ if ( rebuildState && changes ) {
258
+ const { previousAssetsInfo, previousOutputInfo } = rebuildState ;
259
+
255
260
const incrementalResult : IncrementalResult = {
256
261
kind : ResultKind . Incremental ,
257
262
warnings : warnings as ResultMessage [ ] ,
@@ -269,7 +274,6 @@ function emitOutputResult(
269
274
270
275
// Initially assume all previous output files have been removed
271
276
const removedOutputFiles = new Map ( previousOutputInfo ) ;
272
-
273
277
for ( const file of outputFiles ) {
274
278
removedOutputFiles . delete ( file . path ) ;
275
279
@@ -293,24 +297,37 @@ function emitOutputResult(
293
297
}
294
298
}
295
299
296
- // Include the removed output files
300
+ // Initially assume all previous assets files have been removed
301
+ const removedAssetFiles = new Map ( previousAssetsInfo ) ;
302
+ for ( const { source, destination } of assetFiles ) {
303
+ removedAssetFiles . delete ( source ) ;
304
+
305
+ if ( changes . modified . has ( source ) ) {
306
+ incrementalResult . modified . push ( destination ) ;
307
+ } else if ( ! previousAssetsInfo . has ( source ) ) {
308
+ incrementalResult . added . push ( destination ) ;
309
+ } else {
310
+ continue ;
311
+ }
312
+
313
+ incrementalResult . files [ destination ] = {
314
+ type : BuildOutputFileType . Browser ,
315
+ inputPath : source ,
316
+ origin : 'disk' ,
317
+ } ;
318
+ }
319
+
320
+ // Include the removed output and asset files
297
321
incrementalResult . removed . push (
298
322
...Array . from ( removedOutputFiles , ( [ file , { type } ] ) => ( {
299
323
path : file ,
300
324
type,
301
325
} ) ) ,
302
- ) ;
303
-
304
- // Always consider asset files as added to ensure new/modified assets are available.
305
- // TODO: Consider more comprehensive asset analysis.
306
- for ( const file of assetFiles ) {
307
- incrementalResult . added . push ( file . destination ) ;
308
- incrementalResult . files [ file . destination ] = {
326
+ ...Array . from ( removedAssetFiles . values ( ) , ( file ) => ( {
327
+ path : file ,
309
328
type : BuildOutputFileType . Browser ,
310
- inputPath : file . source ,
311
- origin : 'disk' ,
312
- } ;
313
- }
329
+ } ) ) ,
330
+ ) ;
314
331
315
332
return incrementalResult ;
316
333
}
0 commit comments