@@ -70,17 +70,19 @@ function normalizeJSDelivr(
70
70
}
71
71
72
72
const TEMP_USE_JSDELIVR = false ;
73
+ // Strips the version of a path, eg. test/1.3.0 -> test
74
+ const ALIAS_REGEX = / \/ \d * \. \d * \. \d * .* ?( \/ | $ ) / ;
73
75
74
76
function getUnpkgUrl ( name : string , version : string ) {
75
- const nameWithoutAlias = name . replace ( / \/ \d * \. \d * \. \d * $ / , '' ) ;
77
+ const nameWithoutAlias = name . replace ( ALIAS_REGEX , '' ) ;
76
78
77
79
return TEMP_USE_JSDELIVR
78
80
? `https://cdn.jsdelivr.net/npm/${ nameWithoutAlias } @${ version } `
79
81
: `https://unpkg.com/${ nameWithoutAlias } @${ version } ` ;
80
82
}
81
83
82
84
function getMeta ( name : string , packageJSONPath : string , version : string ) {
83
- const nameWithoutAlias = name . replace ( / \/ \d * \. \d * \. \d * $ / , '' ) ;
85
+ const nameWithoutAlias = name . replace ( ALIAS_REGEX , '' ) ;
84
86
const id = `${ packageJSONPath } @${ version } ` ;
85
87
if ( metas [ id ] ) {
86
88
return metas [ id ] ;
@@ -245,10 +247,10 @@ async function findDependencyVersion(
245
247
const packageJSON =
246
248
manager . transpiledModules [ foundPackageJSONPath ] &&
247
249
manager . transpiledModules [ foundPackageJSONPath ] . module . code ;
248
- const { version } = JSON . parse ( packageJSON ) ;
250
+ const { version, name } = JSON . parse ( packageJSON ) ;
249
251
250
252
if ( packageJSON !== '//empty.js' ) {
251
- return { packageJSONPath : foundPackageJSONPath , version } ;
253
+ return { packageJSONPath : foundPackageJSONPath , version, name } ;
252
254
}
253
255
} catch ( e ) {
254
256
/* do nothing */
0 commit comments