@@ -161,17 +161,12 @@ async function createDepsOptimizer(
161
161
let firstRunCalled = ! ! cachedMetadata
162
162
163
163
let postScanOptimizationResult : Promise < DepOptimizationResult > | undefined
164
- let discoverProjectDependenciesPromise :
165
- | Promise < Record < string , string > >
166
- | undefined
167
164
168
165
let optimizingNewDeps : Promise < DepOptimizationResult > | undefined
169
166
async function close ( ) {
170
167
closed = true
171
168
await Promise . allSettled ( [
172
- discoverProjectDependenciesPromise ?. catch ( ( ) => {
173
- /* ignore error for scanner because it's not important */
174
- } ) ,
169
+ depsOptimizer . scanProcessing ,
175
170
postScanOptimizationResult ,
176
171
optimizingNewDeps ,
177
172
] )
@@ -203,52 +198,50 @@ async function createDepsOptimizer(
203
198
204
199
if ( ! isBuild ) {
205
200
// Important, the scanner is dev only
206
- const scanPhaseProcessing = newDepOptimizationProcessing ( )
207
- depsOptimizer . scanProcessing = scanPhaseProcessing . promise
208
- // Ensure server listen is called before the scanner
209
- setTimeout ( async ( ) => {
210
- try {
211
- debug ( colors . green ( `scanning for dependencies...` ) )
212
-
213
- discoverProjectDependenciesPromise =
214
- discoverProjectDependencies ( config )
215
- const deps = await discoverProjectDependenciesPromise
216
-
217
- debug (
218
- colors . green (
219
- Object . keys ( deps ) . length > 0
220
- ? `dependencies found by scanner: ${ depsLogString (
221
- Object . keys ( deps ) ,
222
- ) } `
223
- : `no dependencies found by scanner` ,
224
- ) ,
225
- )
201
+ depsOptimizer . scanProcessing = new Promise ( ( resolve ) => {
202
+ // Ensure server listen is called before the scanner
203
+ setTimeout ( async ( ) => {
204
+ try {
205
+ debug ( colors . green ( `scanning for dependencies...` ) )
206
+
207
+ const deps = await discoverProjectDependencies ( config )
208
+
209
+ debug (
210
+ colors . green (
211
+ Object . keys ( deps ) . length > 0
212
+ ? `dependencies found by scanner: ${ depsLogString (
213
+ Object . keys ( deps ) ,
214
+ ) } `
215
+ : `no dependencies found by scanner` ,
216
+ ) ,
217
+ )
226
218
227
- // Add these dependencies to the discovered list, as these are currently
228
- // used by the preAliasPlugin to support aliased and optimized deps.
229
- // This is also used by the CJS externalization heuristics in legacy mode
230
- for ( const id of Object . keys ( deps ) ) {
231
- if ( ! metadata . discovered [ id ] ) {
232
- addMissingDep ( id , deps [ id ] )
219
+ // Add these dependencies to the discovered list, as these are currently
220
+ // used by the preAliasPlugin to support aliased and optimized deps.
221
+ // This is also used by the CJS externalization heuristics in legacy mode
222
+ for ( const id of Object . keys ( deps ) ) {
223
+ if ( ! metadata . discovered [ id ] ) {
224
+ addMissingDep ( id , deps [ id ] )
225
+ }
233
226
}
234
- }
235
227
236
- if ( ! isBuild ) {
237
- const knownDeps = prepareKnownDeps ( )
228
+ if ( ! isBuild ) {
229
+ const knownDeps = prepareKnownDeps ( )
238
230
239
- // For dev, we run the scanner and the first optimization
240
- // run on the background, but we wait until crawling has ended
241
- // to decide if we send this result to the browser or we need to
242
- // do another optimize step
243
- postScanOptimizationResult = runOptimizeDeps ( config , knownDeps )
231
+ // For dev, we run the scanner and the first optimization
232
+ // run on the background, but we wait until crawling has ended
233
+ // to decide if we send this result to the browser or we need to
234
+ // do another optimize step
235
+ postScanOptimizationResult = runOptimizeDeps ( config , knownDeps )
236
+ }
237
+ } catch ( e ) {
238
+ logger . error ( e . message )
239
+ } finally {
240
+ resolve ( )
241
+ depsOptimizer . scanProcessing = undefined
244
242
}
245
- } catch ( e ) {
246
- logger . error ( e . message )
247
- } finally {
248
- scanPhaseProcessing . resolve ( )
249
- depsOptimizer . scanProcessing = undefined
250
- }
251
- } , 0 )
243
+ } , 0 )
244
+ } )
252
245
}
253
246
}
254
247
0 commit comments