@@ -185,52 +185,50 @@ async function createDepsOptimizer(
185
185
186
186
if ( ! isBuild ) {
187
187
// Important, the scanner is dev only
188
- runScanner ( )
189
- }
190
- }
188
+ const scanPhaseProcessing = newDepOptimizationProcessing ( )
189
+ depsOptimizer . scanProcessing = scanPhaseProcessing . promise
190
+ // Ensure server listen is called before the scanner
191
+ setTimeout ( async ( ) => {
192
+ try {
193
+ debug ( colors . green ( `scanning for dependencies...` ) )
191
194
192
- async function runScanner ( ) {
193
- const scanPhaseProcessing = newDepOptimizationProcessing ( )
194
- depsOptimizer . scanProcessing = scanPhaseProcessing . promise
195
+ const deps = await discoverProjectDependencies ( config )
195
196
196
- try {
197
- debug ( colors . green ( `scanning for dependencies...` ) )
197
+ debug (
198
+ colors . green (
199
+ Object . keys ( deps ) . length > 0
200
+ ? `dependencies found by scanner: ${ depsLogString (
201
+ Object . keys ( deps )
202
+ ) } `
203
+ : `no dependencies found by scanner`
204
+ )
205
+ )
198
206
199
- const deps = await discoverProjectDependencies ( config )
207
+ // Add these dependencies to the discovered list, as these are currently
208
+ // used by the preAliasPlugin to support aliased and optimized deps.
209
+ // This is also used by the CJS externalization heuristics in legacy mode
210
+ for ( const id of Object . keys ( deps ) ) {
211
+ if ( ! metadata . discovered [ id ] ) {
212
+ addMissingDep ( id , deps [ id ] )
213
+ }
214
+ }
200
215
201
- debug (
202
- colors . green (
203
- Object . keys ( deps ) . length > 0
204
- ? `dependencies found by scanner: ${ depsLogString (
205
- Object . keys ( deps )
206
- ) } `
207
- : `no dependencies found by scanner`
208
- )
209
- )
216
+ if ( ! isBuild ) {
217
+ const knownDeps = prepareKnownDeps ( )
210
218
211
- // Add these dependencies to the discovered list, as these are currently
212
- // used by the preAliasPlugin to support aliased and optimized deps.
213
- // This is also used by the CJS externalization heuristics in legacy mode
214
- for ( const id of Object . keys ( deps ) ) {
215
- if ( ! metadata . discovered [ id ] ) {
216
- addMissingDep ( id , deps [ id ] )
219
+ // For dev, we run the scanner and the first optimization
220
+ // run on the background, but we wait until crawling has ended
221
+ // to decide if we send this result to the browser or we need to
222
+ // do another optimize step
223
+ postScanOptimizationResult = runOptimizeDeps ( config , knownDeps )
224
+ }
225
+ } catch ( e ) {
226
+ logger . error ( e . message )
227
+ } finally {
228
+ scanPhaseProcessing . resolve ( )
229
+ depsOptimizer . scanProcessing = undefined
217
230
}
218
- }
219
-
220
- if ( ! isBuild ) {
221
- const knownDeps = prepareKnownDeps ( )
222
-
223
- // For dev, we run the scanner and the first optimization
224
- // run on the background, but we wait until crawling has ended
225
- // to decide if we send this result to the browser or we need to
226
- // do another optimize step
227
- postScanOptimizationResult = runOptimizeDeps ( config , knownDeps )
228
- }
229
- } catch ( e ) {
230
- logger . error ( e . message )
231
- } finally {
232
- scanPhaseProcessing . resolve ( )
233
- depsOptimizer . scanProcessing = undefined
231
+ } , 0 )
234
232
}
235
233
}
236
234
0 commit comments