Skip to content

Commit 521b8bb

Browse files
committed
Fix downloading aliased dynamic dependencies with characters in their version names
Fixes #1394
1 parent d338e5c commit 521b8bb

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

packages/app/src/sandbox/eval/npm/fetch-npm-module.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,19 @@ function normalizeJSDelivr(
7070
}
7171

7272
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*.*?(\/|$)/;
7375

7476
function 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

8284
function 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

Comments
 (0)