@@ -11,6 +11,7 @@ import {
11
11
PackageName
12
12
} from '@rushstack/node-core-library' ;
13
13
import { ReleaseTag } from '@microsoft/api-extractor-model' ;
14
+ import minimatch from 'minimatch' ;
14
15
15
16
import { ExtractorMessageId } from '../api/ExtractorMessageId' ;
16
17
@@ -157,56 +158,57 @@ export class Collector {
157
158
}
158
159
159
160
/**
160
- * Searches the provided package.json for dependencies that match the provided package names and/or RegExp patterns
161
+ * Searches the provided package.json for dependencies that match the provided package names and/or glob patterns
161
162
* in `bundledPackages`.
162
- * @param bundledPackages - The list of package names and/or RegExp patterns to search for in the package.json.
163
+ * @param bundledPackages - The list of package names and/or glob patterns to search for in the package.json.
163
164
* @param packageJson - The package.json of the package being processed.
164
165
* @returns The set of matching package names.
165
166
*/
166
167
private static _resolveBundledPackagePatterns (
167
168
bundledPackages : string [ ] ,
168
169
packageJson : INodePackageJson | undefined
169
170
) : ReadonlySet < string > {
170
- // The set to be built up and returned
171
- const packageNames : Set < string > = new Set < string > ( ) ;
172
-
173
171
if ( bundledPackages . length === 0 ) {
174
172
// If no `bundledPackages` were specified, then there is nothing to resolve.
175
173
// Return an empty set.
176
- return packageNames ;
174
+ return new Set < string > ( ) ;
177
175
}
178
176
179
177
if ( packageJson === undefined ) {
180
178
// If no package.json is present, then there are no possible package matches.
181
179
// Return an empty set.
182
- return packageNames ;
180
+ return new Set < string > ( ) ;
183
181
}
184
182
185
183
const dependencyNames : string [ ] = Object . keys ( packageJson . dependencies ?? { } ) ;
186
184
187
185
if ( dependencyNames . length === 0 ) {
188
186
// If there are no dependencies, then there are no possible package matches.
189
187
// Return an empty set.
190
- return packageNames ;
188
+ return new Set < string > ( ) ;
191
189
}
192
190
191
+ // The set of resolved package names to be populated and returned
192
+ const packageNames : Set < string > = new Set < string > ( ) ;
193
+
193
194
for ( const packageNameOrPattern of bundledPackages ) {
194
195
// If the string is an exact package name, search for exact match
195
196
if ( PackageName . isValidName ( packageNameOrPattern ) ) {
196
197
if ( dependencyNames . includes ( packageNameOrPattern ) ) {
197
198
packageNames . add ( packageNameOrPattern ) ;
198
199
}
199
200
} else {
200
- // If the entry isn't an exact package name, assume RegExp and search for matches
201
- const regexp : RegExp = new RegExp ( packageNameOrPattern ) ;
202
- const matches : string [ ] = dependencyNames . filter ( ( dependencyName ) => regexp . test ( dependencyName ) ) ;
201
+ // If the entry isn't an exact package name, assume glob pattern and search for matches
202
+ const matches : string [ ] = dependencyNames . filter ( ( dependencyName ) =>
203
+ minimatch ( dependencyName , packageNameOrPattern )
204
+ ) ;
203
205
matches . forEach ( ( match ) => packageNames . add ( match ) ) ;
204
206
}
205
207
}
206
208
return packageNames ;
207
209
}
208
210
209
- /**
211
+ /**a
210
212
* Returns a list of names (e.g. "example-library") that should appear in a reference like this:
211
213
*
212
214
* ```
0 commit comments