@@ -47,12 +47,12 @@ export interface PackageInfo {
47
47
48
48
// Modelled after traverseWorkspace in https://github.com/yarnpkg/berry/blob/master/packages/plugin-essentials/sources/commands/info.ts#L88
49
49
/**
50
- * Recursively traveses workspace and its transitive dependencies.
50
+ * Recursively traverses workspaces and their transitive dependencies.
51
51
* @returns Packages and their resolved dependencies.
52
52
*/
53
- export async function traverseWorkspace (
53
+ export async function traverseWorkspaces (
54
54
project : Project ,
55
- workspace : Workspace ,
55
+ workspaces : Workspace [ ] ,
56
56
config : Configuration
57
57
) : Promise < Set < PackageInfo > > {
58
58
// Instantiate fetcher to be able to retrieve package manifest. Conversion to CycloneDX model needs this later.
@@ -67,62 +67,64 @@ export async function traverseWorkspace (
67
67
cacheOptions : { skipIntegrityCheck : true }
68
68
}
69
69
70
- const workspaceHash = workspace . anchoredLocator . locatorHash
71
-
72
- /** Packages that have been added to allPackages. */
73
- const seen = new Set < LocatorHash > ( )
74
70
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
+ }
93
87
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
+ )
118
93
}
119
- packageInfo . dependencies . add ( resolution )
120
94
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
+ }
123
125
}
124
126
}
125
127
}
126
128
127
129
return allPackages
128
- }
130
+ } ;
0 commit comments