@@ -49,8 +49,7 @@ type WorkspaceManagerOptions = {
49
49
isStrict : boolean ;
50
50
isCache : boolean ;
51
51
cacheLocation : string ;
52
- allConfigFilePaths : Set < string > ;
53
- allConfigFilesMap : Map < string , Map < PluginName , Set < string > > > ;
52
+ configFilesMap : Map < string , Map < PluginName , Set < string > > > ;
54
53
} ;
55
54
56
55
type CacheItem = { resolveEntryPaths ?: Input [ ] ; resolveConfig ?: Input [ ] ; resolveFromAST ?: Input [ ] } ;
@@ -91,8 +90,7 @@ export class WorkspaceWorker {
91
90
92
91
cache : CacheConsultant < CacheItem > ;
93
92
94
- allConfigFilePaths : Set < string > ;
95
- allConfigFilesMap : Map < string , Map < PluginName , Set < string > > > ;
93
+ configFilesMap : Map < string , Map < PluginName , Set < string > > > ;
96
94
97
95
constructor ( {
98
96
name,
@@ -112,8 +110,7 @@ export class WorkspaceWorker {
112
110
getSourceFile,
113
111
isCache,
114
112
cacheLocation,
115
- allConfigFilePaths,
116
- allConfigFilesMap,
113
+ configFilesMap,
117
114
} : WorkspaceManagerOptions ) {
118
115
this . name = name ;
119
116
this . dir = dir ;
@@ -127,8 +124,7 @@ export class WorkspaceWorker {
127
124
this . negatedWorkspacePatterns = negatedWorkspacePatterns ;
128
125
this . ignoredWorkspacePatterns = ignoredWorkspacePatterns ;
129
126
this . enabledPluginsInAncestors = enabledPluginsInAncestors ;
130
- this . allConfigFilePaths = allConfigFilePaths ;
131
- this . allConfigFilesMap = allConfigFilesMap ;
127
+ this . configFilesMap = configFilesMap ;
132
128
133
129
this . getReferencedInternalFilePath = getReferencedInternalFilePath ;
134
130
this . findWorkspaceByFilePath = findWorkspaceByFilePath ;
@@ -260,7 +256,7 @@ export class WorkspaceWorker {
260
256
}
261
257
262
258
public async runPlugins ( ) {
263
- const name = this . name ;
259
+ const wsName = this . name ;
264
260
const cwd = this . dir ;
265
261
const rootCwd = this . cwd ;
266
262
const manifest = this . manifest ;
@@ -296,17 +292,19 @@ export class WorkspaceWorker {
296
292
}
297
293
} ;
298
294
295
+ const configFilesMap = this . configFilesMap ;
296
+ const configFiles = this . configFilesMap . get ( wsName ) ;
297
+
299
298
const handleConfigInput = ( pluginName : PluginName , input : ConfigInput ) => {
300
299
const configFilePath = this . getReferencedInternalFilePath ( input ) ;
301
300
if ( configFilePath ) {
302
301
const workspace = this . findWorkspaceByFilePath ( configFilePath ) ;
303
302
if ( workspace ) {
304
303
// We can only handle root → child transfers, otherwise add to and run in current workspace
305
304
const name = this . name === ROOT_WORKSPACE_NAME ? workspace . name : this . name ;
306
- const files = this . allConfigFilesMap ;
307
- if ( ! files . has ( name ) ) files . set ( name , new Map ( ) ) ;
308
- if ( ! files . get ( name ) ?. has ( pluginName ) ) files . get ( name ) ?. set ( pluginName , new Set ( ) ) ;
309
- files . get ( name ) ?. get ( pluginName ) ?. add ( configFilePath ) ;
305
+ if ( ! configFilesMap . has ( name ) ) configFilesMap . set ( name , new Map ( ) ) ;
306
+ if ( ! configFilesMap . get ( name ) ?. has ( pluginName ) ) configFilesMap . get ( name ) ?. set ( pluginName , new Set ( ) ) ;
307
+ configFilesMap . get ( name ) ?. get ( pluginName ) ?. add ( configFilePath ) ;
310
308
}
311
309
}
312
310
} ;
@@ -329,15 +327,6 @@ export class WorkspaceWorker {
329
327
const label = 'config file' ;
330
328
const configFilePaths = await _glob ( { patterns, cwd : rootCwd , dir : cwd , gitignore : false , label } ) ;
331
329
332
- const remainingConfigFilePaths = configFilePaths . filter ( filePath => ! this . allConfigFilePaths . has ( filePath ) ) ;
333
- for ( const filePath of remainingConfigFilePaths ) {
334
- if ( basename ( filePath ) !== 'package.json' ) {
335
- this . allConfigFilePaths . add ( filePath ) ;
336
- addInput ( toEntry ( filePath ) ) ;
337
- addInput ( toConfig ( pluginName , filePath ) ) ;
338
- }
339
- }
340
-
341
330
const options = {
342
331
...baseScriptOptions ,
343
332
config,
@@ -349,13 +338,16 @@ export class WorkspaceWorker {
349
338
350
339
if ( config . entry ) {
351
340
const toInput = isProduction && plugin . production && plugin . production . length > 0 ? toProductionEntry : toEntry ;
352
- for ( const input of config . entry . map ( id => toInput ( id ) ) ) addInput ( input ) ;
353
- } else if ( ( ! plugin . resolveEntryPaths && ! plugin . resolveFromAST ) || remainingConfigFilePaths . length === 0 ) {
354
- if ( plugin . entry ) for ( const input of plugin . entry . map ( id => toEntry ( id ) ) ) addInput ( input ) ;
355
- if ( plugin . production ) for ( const input of plugin . production . map ( id => toProductionEntry ( id ) ) ) addInput ( input ) ;
341
+ for ( const id of config . entry ) addInput ( toInput ( id ) ) ;
342
+ } else if (
343
+ ( ! plugin . resolveEntryPaths && ! plugin . resolveFromAST ) ||
344
+ ( configFilePaths . length === 0 && ( ! configFiles ?. get ( pluginName ) || configFiles ?. get ( pluginName ) ?. size === 0 ) )
345
+ ) {
346
+ if ( plugin . entry ) for ( const id of plugin . entry ) addInput ( toEntry ( id ) ) ;
347
+ if ( plugin . production ) for ( const id of plugin . production ) addInput ( toProductionEntry ( id ) ) ;
356
348
}
357
349
358
- for ( const configFilePath of remainingConfigFilePaths ) {
350
+ for ( const configFilePath of configFilePaths ) {
359
351
const isManifest = basename ( configFilePath ) === 'package.json' ;
360
352
const fd = isManifest ? undefined : this . cache . getFileDescriptor ( configFilePath ) ;
361
353
@@ -375,10 +367,11 @@ export class WorkspaceWorker {
375
367
configFileName : basename ( configFilePath ) ,
376
368
} ;
377
369
370
+ const seen = configFiles ?. get ( pluginName ) ?. has ( configFilePath ) ;
378
371
const cache : CacheItem = { } ;
379
372
let loadedConfig : unknown ;
380
373
381
- if ( plugin . resolveEntryPaths ) {
374
+ if ( plugin . resolveEntryPaths && ! seen ) {
382
375
if ( ! loadedConfig ) loadedConfig = await loadConfigForPlugin ( configFilePath , plugin , resolveOpts , pluginName ) ;
383
376
if ( loadedConfig ) {
384
377
const inputs = await plugin . resolveEntryPaths ( loadedConfig , resolveOpts ) ;
@@ -387,7 +380,7 @@ export class WorkspaceWorker {
387
380
}
388
381
}
389
382
390
- if ( plugin . resolveConfig ) {
383
+ if ( plugin . resolveConfig && ! seen ) {
391
384
if ( ! loadedConfig ) loadedConfig = await loadConfigForPlugin ( configFilePath , plugin , resolveOpts , pluginName ) ;
392
385
if ( loadedConfig ) {
393
386
const inputs = await plugin . resolveConfig ( loadedConfig , resolveOpts ) ;
@@ -410,6 +403,11 @@ export class WorkspaceWorker {
410
403
}
411
404
}
412
405
406
+ if ( basename ( configFilePath ) !== 'package.json' ) {
407
+ addInput ( toEntry ( configFilePath ) ) ;
408
+ addInput ( toConfig ( pluginName , configFilePath ) ) ;
409
+ }
410
+
413
411
if ( ! isManifest && fd ?. changed && fd . meta ) fd . meta . data = cache ;
414
412
}
415
413
@@ -422,8 +420,6 @@ export class WorkspaceWorker {
422
420
const enabledPluginTitles = this . enabledPlugins . map ( name => Plugins [ name ] . title ) ;
423
421
debugLogObject ( this . name , 'Enabled plugins' , enabledPluginTitles ) ;
424
422
425
- const configFiles = this . allConfigFilesMap . get ( name ) ;
426
-
427
423
for ( const pluginName of this . enabledPlugins ) {
428
424
const patterns = [ ...this . getConfigurationFilePatterns ( pluginName ) , ...( configFiles ?. get ( pluginName ) ?? [ ] ) ] ;
429
425
configFiles ?. delete ( pluginName ) ;
@@ -433,7 +429,7 @@ export class WorkspaceWorker {
433
429
434
430
{
435
431
// Handle config files added from root or current workspace recursively
436
- const configFiles = this . allConfigFilesMap . get ( name ) ;
432
+ const configFiles = this . configFilesMap . get ( wsName ) ;
437
433
if ( configFiles ) {
438
434
do {
439
435
for ( const [ pluginName , dependencies ] of configFiles . entries ( ) ) {
@@ -445,7 +441,7 @@ export class WorkspaceWorker {
445
441
}
446
442
}
447
443
448
- debugLogArray ( name , 'Plugin dependencies' , ( ) => compact ( inputs . map ( toDebugString ) ) ) ;
444
+ debugLogArray ( wsName , 'Plugin dependencies' , ( ) => compact ( inputs . map ( toDebugString ) ) ) ;
449
445
450
446
return inputs ;
451
447
}
0 commit comments