@@ -47,12 +47,12 @@ export interface PackageInfo {
4747
4848// Modelled after traverseWorkspace in https://github.com/yarnpkg/berry/blob/master/packages/plugin-essentials/sources/commands/info.ts#L88
4949/**
50- * Recursively traveses workspace and its transitive dependencies.
50+ * Recursively traverses workspaces and their transitive dependencies.
5151 * @returns Packages and their resolved dependencies.
5252 */
53- export async function traverseWorkspace (
53+ export async function traverseWorkspaces (
5454 project : Project ,
55- workspace : Workspace ,
55+ workspaces : Workspace [ ] ,
5656 config : Configuration
5757) : Promise < Set < PackageInfo > > {
5858 // Instantiate fetcher to be able to retrieve package manifest. Conversion to CycloneDX model needs this later.
@@ -67,62 +67,64 @@ export async function traverseWorkspace (
6767 cacheOptions : { skipIntegrityCheck : true }
6868 }
6969
70- const workspaceHash = workspace . anchoredLocator . locatorHash
71-
72- /** Packages that have been added to allPackages. */
73- const seen = new Set < LocatorHash > ( )
7470 const allPackages = new Set < PackageInfo > ( )
75- /** Resolved dependencies that still need processing to find their dependencies. */
76- const pending = [ workspaceHash ]
77-
78- while ( true ) {
79- // pop to take most recently added job which traverses packages in depth-first style.
80- // Doing probably results in smaller 'pending' array which makes includes-search cheaper below.
81- const hash = pending . pop ( )
82- if ( hash === undefined ) {
83- // Nothing left to do as undefined value means no more item was in 'pending' array.
84- break
85- }
86-
87- const pkg = project . storedPackages . get ( hash )
88- if ( pkg === undefined ) {
89- throw new Error (
90- 'All package locator hashes should be resovable for consistent lockfiles.'
91- )
92- }
71+ for ( const workspace of workspaces ) {
72+ const workspaceHash = workspace . anchoredLocator . locatorHash
73+
74+ /** Packages that have been added to allPackages. */
75+ const seen = new Set < LocatorHash > ( )
76+ /** Resolved dependencies that still need processing to find their dependencies. */
77+ const pending = [ workspaceHash ]
78+
79+ while ( true ) {
80+ // pop to take most recently added job which traverses packages in depth-first style.
81+ // Doing probably results in smaller 'pending' array which makes includes-search cheaper below.
82+ const hash = pending . pop ( )
83+ if ( hash === undefined ) {
84+ // Nothing left to do as undefined value means no more item was in 'pending' array.
85+ break
86+ }
9387
94- const fetchResult = await fetcher . fetch ( pkg , fetcherOptions )
95- let manifest : Manifest
96- try {
97- manifest = await Manifest . find ( fetchResult . prefixPath , {
98- baseFs : fetchResult . packageFs
99- } )
100- } finally {
101- fetchResult . releaseFs ?.( )
102- }
103- const packageInfo : PackageInfo = {
104- package : pkg ,
105- manifest,
106- dependencies : new Set ( )
107- }
108- seen . add ( hash )
109- allPackages . add ( packageInfo )
110-
111- // pkg.dependencies has dependencies+peerDependencies for transitive dependencies but not their devDependencies.
112- for ( const dependency of pkg . dependencies . values ( ) ) {
113- const resolution = project . storedResolutions . get (
114- dependency . descriptorHash
115- )
116- if ( typeof resolution === 'undefined' ) {
117- throw new Error ( 'All package descriptor hashes should be resolvable for consistent lockfiles.' )
88+ const pkg = project . storedPackages . get ( hash )
89+ if ( pkg === undefined ) {
90+ throw new Error (
91+ 'All package locator hashes should be resovable for consistent lockfiles.'
92+ )
11893 }
119- packageInfo . dependencies . add ( resolution )
12094
121- if ( ! seen . has ( resolution ) && ! pending . includes ( resolution ) ) {
122- pending . push ( resolution )
95+ const fetchResult = await fetcher . fetch ( pkg , fetcherOptions )
96+ let manifest : Manifest
97+ try {
98+ manifest = await Manifest . find ( fetchResult . prefixPath , {
99+ baseFs : fetchResult . packageFs
100+ } )
101+ } finally {
102+ fetchResult . releaseFs ?.( )
103+ }
104+ const packageInfo : PackageInfo = {
105+ package : pkg ,
106+ manifest,
107+ dependencies : new Set ( )
108+ }
109+ seen . add ( hash )
110+ allPackages . add ( packageInfo )
111+
112+ // pkg.dependencies has dependencies+peerDependencies for transitive dependencies but not their devDependencies.
113+ for ( const dependency of pkg . dependencies . values ( ) ) {
114+ const resolution = project . storedResolutions . get (
115+ dependency . descriptorHash
116+ )
117+ if ( typeof resolution === 'undefined' ) {
118+ throw new Error ( 'All package descriptor hashes should be resolvable for consistent lockfiles.' )
119+ }
120+ packageInfo . dependencies . add ( resolution )
121+
122+ if ( ! seen . has ( resolution ) && ! pending . includes ( resolution ) ) {
123+ pending . push ( resolution )
124+ }
123125 }
124126 }
125127 }
126128
127129 return allPackages
128- }
130+ } ;
0 commit comments