Skip to content

Commit fcbeaae

Browse files
authored
fix: properly resolve packages with version (#609)
adjusts the regex for this Fixes #605
1 parent 32c4d26 commit fcbeaae

File tree

1 file changed

+3
-3
lines changed
  • packages/repl/src/lib/workers/bundler

1 file changed

+3
-3
lines changed

packages/repl/src/lib/workers/bundler/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,14 @@ async function get_bundle(
287287
// fetch from unpkg
288288
self.postMessage({ type: 'status', uid, message: `resolving ${importee}` });
289289

290-
const match = /^((?:@[^/]+\/)?[^/]+)(\/.+)?$/.exec(importee);
290+
const match = /^((?:@[^/]+\/)?[^/@]+)(?:@([^/]+))?(\/.+)?$/.exec(importee);
291291
if (!match) {
292292
return console.error(`Invalid import "${importee}"`);
293293
}
294294

295295
const pkg_name = match[1];
296-
const subpath = `.${match[2] ?? ''}`;
296+
const version = pkg_name === 'svelte' ? svelte.VERSION : match[2] ?? 'latest';
297+
const subpath = `.${match[3] ?? ''}`;
297298

298299
// if this was imported by one of our files, add it to the `imports` set
299300
if (importer && local_files_lookup.has(importer)) {
@@ -302,7 +303,6 @@ async function get_bundle(
302303

303304
const fetch_package_info = async () => {
304305
try {
305-
const version = pkg_name === 'svelte' ? svelte.VERSION : 'latest';
306306
const pkg_url = await follow_redirects(
307307
`${packages_url}/${pkg_name}@${version}/package.json`,
308308
uid

0 commit comments

Comments
 (0)