From 9622a33cbd7ae463d94105114ad27c70218e337e Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 7 Aug 2025 14:45:48 -0500 Subject: [PATCH] Fix LightningFS resolver --- src/lib/build/lightningFsPlugin.ts | 37 ++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/lib/build/lightningFsPlugin.ts b/src/lib/build/lightningFsPlugin.ts index 366ec1cd..778390ae 100644 --- a/src/lib/build/lightningFsPlugin.ts +++ b/src/lib/build/lightningFsPlugin.ts @@ -11,11 +11,18 @@ export function lightningFsPlugin(fs: JSRuntimeFS, cwd: string): Plugin { let resolved: string; if (args.path.startsWith('@/')) { + // Handle alias paths resolved = path.join(cwd, args.path.slice(2)); } else if (args.path.startsWith('/')) { + // Handle absolute paths resolved = args.path; + } else if (args.importer) { + // Handle relative imports - use the directory of the importing file + const importerDir = path.dirname(args.importer); + resolved = path.join(importerDir, args.path); } else { - resolved = path.join(cwd, args.resolveDir, args.path); + // Initial entry point or fallback to resolveDir + resolved = path.join(cwd, args.resolveDir || '', args.path); } try { @@ -40,6 +47,8 @@ export function lightningFsPlugin(fs: JSRuntimeFS, cwd: string): Plugin { return { contents: await fs.readFile(args.path, 'utf8'), loader: ext as Loader, + // Set resolveDir for subsequent imports from this file + resolveDir: path.dirname(args.path), }; }); }, @@ -50,18 +59,24 @@ async function tryFileVariants(fs: JSRuntimeFS, basePath: string): Promise