From 9786d8f1059e1df95fcdcb132dd16c3962134be6 Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Thu, 24 Oct 2024 11:26:40 +0200 Subject: [PATCH] fix: properly resolve packages with version adjusts the regex for this Fixes #605 --- packages/repl/src/lib/workers/bundler/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/repl/src/lib/workers/bundler/index.ts b/packages/repl/src/lib/workers/bundler/index.ts index f17bc6dc53..6ca5f928f9 100644 --- a/packages/repl/src/lib/workers/bundler/index.ts +++ b/packages/repl/src/lib/workers/bundler/index.ts @@ -287,13 +287,14 @@ async function get_bundle( // fetch from unpkg self.postMessage({ type: 'status', uid, message: `resolving ${importee}` }); - const match = /^((?:@[^/]+\/)?[^/]+)(\/.+)?$/.exec(importee); + const match = /^((?:@[^/]+\/)?[^/@]+)(?:@([^/]+))?(\/.+)?$/.exec(importee); if (!match) { return console.error(`Invalid import "${importee}"`); } const pkg_name = match[1]; - const subpath = `.${match[2] ?? ''}`; + const version = pkg_name === 'svelte' ? svelte.VERSION : match[2] ?? 'latest'; + const subpath = `.${match[3] ?? ''}`; // if this was imported by one of our files, add it to the `imports` set if (importer && local_files_lookup.has(importer)) { @@ -302,7 +303,6 @@ async function get_bundle( const fetch_package_info = async () => { try { - const version = pkg_name === 'svelte' ? svelte.VERSION : 'latest'; const pkg_url = await follow_redirects( `${packages_url}/${pkg_name}@${version}/package.json`, uid