@@ -202,8 +202,12 @@ async function getPackageInformationStores(
202
202
return { pkg , ref , loc } ;
203
203
} ;
204
204
205
- const visit = async ( seedPatterns : Array < string > , parentData : Array < string > = [ ] ) = > {
206
- const resolutions = new Map ( ) ;
205
+ const visit = async (
206
+ precomputedResolutions : Map < string , string > ,
207
+ seedPatterns : Array < string > ,
208
+ parentData : Array < string > = [ ] ,
209
+ ) = > {
210
+ const resolutions = new Map ( precomputedResolutions ) ;
207
211
const locations = new Map ( ) ;
208
212
209
213
// This first pass will compute the package reference of each of the given patterns
@@ -337,11 +341,14 @@ async function getPackageInformationStores(
337
341
return ! pkg || ! peerDependencies . has ( pkg . name ) ;
338
342
} ) ;
339
343
340
- // We do this in two steps to prevent cyclic dependencies from looping indefinitely
344
+ // We inject the partial information in the store right now so that we won't cycle indefinitely
341
345
packageInformationStore . set ( packageReference , packageInformation ) ;
342
- packageInformation . packageDependencies = await visit ( directDependencies , [ packageName , packageReference ] ) ;
343
346
344
- // We now have to inject the peer dependencies
347
+ // We must inject the peer dependencies before iterating; one of our dependencies might have a peer dependency
348
+ // on one of our peer dependencies, so it must be available from the start (we don't have to do that for direct
349
+ // dependencies, because the "visit" function that will iterate over them will automatically add the to the
350
+ // candidate resolutions as part of the first step, cf above)
351
+
345
352
for ( const dependencyName of peerDependencies ) {
346
353
const dependencyReference = resolutions . get ( dependencyName ) ;
347
354
@@ -350,6 +357,16 @@ async function getPackageInformationStores(
350
357
}
351
358
}
352
359
360
+ const childResolutions = await visit ( packageInformation . packageDependencies , directDependencies , [
361
+ packageName ,
362
+ packageReference ,
363
+ ] ) ;
364
+
365
+ // We can now inject into our package the resolutions we got from the visit function
366
+ for ( const [ name , reference ] of childResolutions . entries ( ) ) {
367
+ packageInformation . packageDependencies . set ( name , reference ) ;
368
+ }
369
+
353
370
// Finally, unless a package depends on a previous version of itself (that would be weird but correct...), we
354
371
// inject them an implicit dependency to themselves (so that they can require themselves)
355
372
if ( ! packageInformation . packageDependencies . has ( packageName ) ) {
@@ -389,7 +406,7 @@ async function getPackageInformationStores(
389
406
390
407
packageInformationStore . set ( pkg . version , {
391
408
packageLocation : normalizeDirectoryPath ( loc ) ,
392
- packageDependencies : await visit ( ref . dependencies , [ name , pkg . version ] ) ,
409
+ packageDependencies : await visit ( new Map ( ) , ref . dependencies , [ name , pkg . version ] ) ,
393
410
} ) ;
394
411
}
395
412
}
@@ -403,7 +420,7 @@ async function getPackageInformationStores(
403
420
null ,
404
421
{
405
422
packageLocation : normalizeDirectoryPath ( config . lockfileFolder ) ,
406
- packageDependencies : await visit ( seedPatterns ) ,
423
+ packageDependencies : await visit ( new Map ( ) , seedPatterns ) ,
407
424
} ,
408
425
] ,
409
426
] ) ,
0 commit comments