@@ -122,7 +122,7 @@ function isDependency(moduleSpecifier: string): boolean {
122
122
123
123
// This seems like a reasonable test for "is a relative path" as long as
124
124
// absolute path imports are forbidden.
125
- const isRelativePath = / ^ \. \. ? \/ / . test ( moduleSpecifier ) ;
125
+ const isRelativePath = / ^ \. \. ? [ \/ \\ ] / . test ( moduleSpecifier ) ;
126
126
return ! isRelativePath ;
127
127
}
128
128
@@ -280,6 +280,21 @@ async function collect<T>(i: AsyncIterableIterator<T>): Promise<T[]> {
280
280
return out ;
281
281
}
282
282
283
+ /**
284
+ * Processes a segmented module path to return the first segment. This is useful for packages that have nested imports
285
+ * such as "dayjs/plugin/duration".
286
+ *
287
+ * @param specifier - the module specifier to resolve to a package name
288
+ * @returns a package name
289
+ */
290
+ function resolveModule ( specifier : string ) : string {
291
+ const parts = specifier . split ( "/" , 2 ) ;
292
+
293
+ // The first part could be a namespace, in which case we need to join them
294
+ if ( parts . length > 1 && parts [ 0 ] . startsWith ( "@" ) ) return parts [ 0 ] + "/" + parts [ 1 ] ;
295
+ else return parts [ 0 ] ;
296
+ }
297
+
283
298
/**
284
299
* Extracts the sample generation metainformation from the sample sources and
285
300
* configuration in package.json.
@@ -346,7 +361,7 @@ async function makeSampleGenerationInfo(
346
361
. slice ( - 1 ) [ 0 ]
347
362
. replace ( "\\" , "/" ) ,
348
363
// This'll be good enough most of the time, but products like Azure Form Recognizer will have
349
- // too adjust using the sample configuration.
364
+ // to adjust using the sample configuration.
350
365
productName :
351
366
sampleConfiguration . productName ??
352
367
fail ( `The sample configuration does not specify a "productName".` ) ,
@@ -377,7 +392,7 @@ async function makeSampleGenerationInfo(
377
392
return {
378
393
dependencies : moduleInfos . reduce ( ( prev , source ) => {
379
394
const current : Record < string , string > = { } ;
380
- for ( const dependency of source . importedModules ) {
395
+ for ( const dependency of source . importedModules . map ( resolveModule ) ) {
381
396
if ( prev [ dependency ] === undefined ) {
382
397
const dependencyVersion =
383
398
sampleConfiguration . dependencyOverrides ?. [ dependency ] ??
0 commit comments