@@ -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,18 @@ 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 &&
345
+ ( ! this . configFilesMap . get ( wsName ) ?. get ( pluginName ) ||
346
+ this . configFilesMap . get ( wsName ) ?. get ( pluginName ) ?. size === 0 ) )
347
+ ) {
348
+ if ( plugin . entry ) for ( const id of plugin . entry ) addInput ( toEntry ( id ) ) ;
349
+ if ( plugin . production ) for ( const id of plugin . production ) addInput ( toProductionEntry ( id ) ) ;
356
350
}
357
351
358
- for ( const configFilePath of remainingConfigFilePaths ) {
352
+ for ( const configFilePath of configFilePaths ) {
359
353
const isManifest = basename ( configFilePath ) === 'package.json' ;
360
354
const fd = isManifest ? undefined : this . cache . getFileDescriptor ( configFilePath ) ;
361
355
@@ -375,10 +369,11 @@ export class WorkspaceWorker {
375
369
configFileName : basename ( configFilePath ) ,
376
370
} ;
377
371
372
+ const seen = this . configFilesMap . get ( wsName ) ?. get ( pluginName ) ?. has ( configFilePath ) ;
378
373
const cache : CacheItem = { } ;
379
374
let loadedConfig : unknown ;
380
375
381
- if ( plugin . resolveEntryPaths ) {
376
+ if ( plugin . resolveEntryPaths && ! seen ) {
382
377
if ( ! loadedConfig ) loadedConfig = await loadConfigForPlugin ( configFilePath , plugin , resolveOpts , pluginName ) ;
383
378
if ( loadedConfig ) {
384
379
const inputs = await plugin . resolveEntryPaths ( loadedConfig , resolveOpts ) ;
@@ -387,7 +382,7 @@ export class WorkspaceWorker {
387
382
}
388
383
}
389
384
390
- if ( plugin . resolveConfig ) {
385
+ if ( plugin . resolveConfig && ! seen ) {
391
386
if ( ! loadedConfig ) loadedConfig = await loadConfigForPlugin ( configFilePath , plugin , resolveOpts , pluginName ) ;
392
387
if ( loadedConfig ) {
393
388
const inputs = await plugin . resolveConfig ( loadedConfig , resolveOpts ) ;
@@ -410,6 +405,11 @@ export class WorkspaceWorker {
410
405
}
411
406
}
412
407
408
+ if ( basename ( configFilePath ) !== 'package.json' ) {
409
+ addInput ( toEntry ( configFilePath ) ) ;
410
+ addInput ( toConfig ( pluginName , configFilePath ) ) ;
411
+ }
412
+
413
413
if ( ! isManifest && fd ?. changed && fd . meta ) fd . meta . data = cache ;
414
414
}
415
415
@@ -422,8 +422,6 @@ export class WorkspaceWorker {
422
422
const enabledPluginTitles = this . enabledPlugins . map ( name => Plugins [ name ] . title ) ;
423
423
debugLogObject ( this . name , 'Enabled plugins' , enabledPluginTitles ) ;
424
424
425
- const configFiles = this . allConfigFilesMap . get ( name ) ;
426
-
427
425
for ( const pluginName of this . enabledPlugins ) {
428
426
const patterns = [ ...this . getConfigurationFilePatterns ( pluginName ) , ...( configFiles ?. get ( pluginName ) ?? [ ] ) ] ;
429
427
configFiles ?. delete ( pluginName ) ;
@@ -433,7 +431,7 @@ export class WorkspaceWorker {
433
431
434
432
{
435
433
// Handle config files added from root or current workspace recursively
436
- const configFiles = this . allConfigFilesMap . get ( name ) ;
434
+ const configFiles = this . configFilesMap . get ( wsName ) ;
437
435
if ( configFiles ) {
438
436
do {
439
437
for ( const [ pluginName , dependencies ] of configFiles . entries ( ) ) {
@@ -445,7 +443,7 @@ export class WorkspaceWorker {
445
443
}
446
444
}
447
445
448
- debugLogArray ( name , 'Plugin dependencies' , ( ) => compact ( inputs . map ( toDebugString ) ) ) ;
446
+ debugLogArray ( wsName , 'Plugin dependencies' , ( ) => compact ( inputs . map ( toDebugString ) ) ) ;
449
447
450
448
return inputs ;
451
449
}
0 commit comments