From 8a1110d7b6a2a5e3c2abc7c24e8a3de8b0f31c61 Mon Sep 17 00:00:00 2001 From: paoloricciuti Date: Tue, 22 Apr 2025 11:19:18 +0200 Subject: [PATCH] fix: resolve imports for `local` version --- packages/repl/src/lib/workers/bundler/index.ts | 9 ++++++--- packages/repl/src/lib/workers/npm.ts | 11 ++++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/repl/src/lib/workers/bundler/index.ts b/packages/repl/src/lib/workers/bundler/index.ts index b6e0287173..eee445c075 100644 --- a/packages/repl/src/lib/workers/bundler/index.ts +++ b/packages/repl/src/lib/workers/bundler/index.ts @@ -219,9 +219,12 @@ async function get_bundle( } // importing a file from the same package via pkg.imports - if (importee[0] === '#' && current) { - const subpath = resolve_subpath(current, importee); - return normalize_path(current, subpath.slice(2)); + if (importee[0] === '#') { + if (current) { + const subpath = resolve_subpath(current, importee); + return normalize_path(current, subpath.slice(2)); + } + return await resolve_local(importee); } // importing an external package -> `npm://$/@/` diff --git a/packages/repl/src/lib/workers/npm.ts b/packages/repl/src/lib/workers/npm.ts index 232a0f7dfd..bf6a00d3b8 100644 --- a/packages/repl/src/lib/workers/npm.ts +++ b/packages/repl/src/lib/workers/npm.ts @@ -219,9 +219,14 @@ let local_svelte_pkg: Promise; export async function resolve_local(specifier: string) { const pkg = await (local_svelte_pkg ??= fetch(LOCAL_PKG_URL).then((r) => r.json())); - const subpath = resolve.exports(pkg, specifier.replace('svelte', '.'), { - browser: true - })![0] as string; + const subpath = + specifier[0] === '#' + ? (resolve.imports(pkg, specifier, { + browser: true + })![0] as string) + : (resolve.exports(pkg, specifier.replace('svelte', '.'), { + browser: true + })![0] as string); return new URL(subpath, LOCAL_PKG_URL).href; }