@@ -175,14 +175,12 @@ async function createDepsOptimizer(
175
175
}
176
176
| undefined
177
177
178
- let optimizingNewDeps : Promise < DepOptimizationResult > | undefined
179
178
async function close ( ) {
180
179
closed = true
181
180
await Promise . allSettled ( [
182
181
discover ?. cancel ( ) ,
183
182
depsOptimizer . scanProcessing ,
184
183
optimizationResult ?. cancel ( ) ,
185
- optimizingNewDeps ,
186
184
] )
187
185
}
188
186
@@ -261,27 +259,6 @@ async function createDepsOptimizer(
261
259
depOptimizationProcessing = newDepOptimizationProcessing ( )
262
260
}
263
261
264
- async function optimizeNewDeps ( ) {
265
- // a successful completion of the optimizeDeps rerun will end up
266
- // creating new bundled version of all current and discovered deps
267
- // in the cache dir and a new metadata info object assigned
268
- // to _metadata. A fullReload is only issued if the previous bundled
269
- // dependencies have changed.
270
-
271
- // if the rerun fails, _metadata remains untouched, current discovered
272
- // deps are cleaned, and a fullReload is issued
273
-
274
- // All deps, previous known and newly discovered are rebundled,
275
- // respect insertion order to keep the metadata file stable
276
-
277
- const knownDeps = prepareKnownDeps ( )
278
-
279
- startNextDiscoveredBatch ( )
280
-
281
- optimizationResult = runOptimizeDeps ( config , knownDeps )
282
- return await optimizationResult . result
283
- }
284
-
285
262
function prepareKnownDeps ( ) {
286
263
const knownDeps : Record < string , OptimizedDepInfo > = { }
287
264
// Clone optimized info objects, fileHash, browserHash may be changed for them
@@ -297,6 +274,18 @@ async function createDepsOptimizer(
297
274
}
298
275
299
276
async function runOptimizer ( preRunResult ?: DepOptimizationResult ) {
277
+ // a successful completion of the optimizeDeps rerun will end up
278
+ // creating new bundled version of all current and discovered deps
279
+ // in the cache dir and a new metadata info object assigned
280
+ // to _metadata. A fullReload is only issued if the previous bundled
281
+ // dependencies have changed.
282
+
283
+ // if the rerun fails, _metadata remains untouched, current discovered
284
+ // deps are cleaned, and a fullReload is issued
285
+
286
+ // All deps, previous known and newly discovered are rebundled,
287
+ // respect insertion order to keep the metadata file stable
288
+
300
289
const isRerun = firstRunCalled
301
290
firstRunCalled = true
302
291
@@ -314,9 +303,17 @@ async function createDepsOptimizer(
314
303
currentlyProcessing = true
315
304
316
305
try {
317
- const processingResult =
318
- preRunResult ?? ( await ( optimizingNewDeps = optimizeNewDeps ( ) ) )
319
- optimizingNewDeps = undefined
306
+ let processingResult : DepOptimizationResult
307
+ if ( preRunResult ) {
308
+ processingResult = preRunResult
309
+ } else {
310
+ const knownDeps = prepareKnownDeps ( )
311
+ startNextDiscoveredBatch ( )
312
+
313
+ optimizationResult = runOptimizeDeps ( config , knownDeps )
314
+ processingResult = await optimizationResult . result
315
+ optimizationResult = undefined
316
+ }
320
317
321
318
if ( closed ) {
322
319
currentlyProcessing = false
0 commit comments