@@ -70,17 +70,19 @@ function normalizeJSDelivr(
7070}
7171
7272const TEMP_USE_JSDELIVR = false ;
73+ // Strips the version of a path, eg. test/1.3.0 -> test
74+ const ALIAS_REGEX = / \/ \d * \. \d * \. \d * .* ?( \/ | $ ) / ;
7375
7476function getUnpkgUrl ( name : string , version : string ) {
75- const nameWithoutAlias = name . replace ( / \/ \d * \. \d * \. \d * $ / , '' ) ;
77+ const nameWithoutAlias = name . replace ( ALIAS_REGEX , '' ) ;
7678
7779 return TEMP_USE_JSDELIVR
7880 ? `https://cdn.jsdelivr.net/npm/${ nameWithoutAlias } @${ version } `
7981 : `https://unpkg.com/${ nameWithoutAlias } @${ version } ` ;
8082}
8183
8284function getMeta ( name : string , packageJSONPath : string , version : string ) {
83- const nameWithoutAlias = name . replace ( / \/ \d * \. \d * \. \d * $ / , '' ) ;
85+ const nameWithoutAlias = name . replace ( ALIAS_REGEX , '' ) ;
8486 const id = `${ packageJSONPath } @${ version } ` ;
8587 if ( metas [ id ] ) {
8688 return metas [ id ] ;
@@ -245,10 +247,10 @@ async function findDependencyVersion(
245247 const packageJSON =
246248 manager . transpiledModules [ foundPackageJSONPath ] &&
247249 manager . transpiledModules [ foundPackageJSONPath ] . module . code ;
248- const { version } = JSON . parse ( packageJSON ) ;
250+ const { version, name } = JSON . parse ( packageJSON ) ;
249251
250252 if ( packageJSON !== '//empty.js' ) {
251- return { packageJSONPath : foundPackageJSONPath , version } ;
253+ return { packageJSONPath : foundPackageJSONPath , version, name } ;
252254 }
253255 } catch ( e ) {
254256 /* do nothing */
0 commit comments