Restore lightningFsPlugin

This commit is contained in:
Alex Gleason committed 2025-08-07 15:43:27 -05:00
1 parent 6d6e928854
commit 5fe4a8fa97
1 file changed
+10 -27
+10 -27
View File
@@ -11,18 +11,11 @@ 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 {
// Initial entry point or fallback to resolveDir
resolved = path.join(cwd, args.resolveDir || '', args.path);
resolved = path.join(cwd, args.resolveDir, args.path);
}
try {
@@ -47,8 +40,6 @@ 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),
};
});
},
@@ -59,24 +50,18 @@ async function tryFileVariants(fs: JSRuntimeFS, basePath: string): Promise<strin
const extensions = ['.ts', '.tsx', '.js', '.jsx', '.css'];
try {
const stat = await fs.stat(basePath);
// If it's a file, return it directly
if (stat.isFile()) {
return basePath;
}
// If it's a directory, continue to check for index files
await fs.stat(basePath);
return basePath;
} catch {
// File doesn't exist, try with extensions
// Ignore
}
// Try direct file with extensions
for (const ext of extensions) {
const full = basePath + ext;
try {
const stat = await fs.stat(full);
if (stat.isFile()) {
return full;
}
await fs.stat(full);
return full;
} catch {
// Ignore
}
@@ -86,14 +71,12 @@ async function tryFileVariants(fs: JSRuntimeFS, basePath: string): Promise<strin
for (const ext of extensions) {
const indexFile = path.join(basePath, 'index' + ext);
try {
const stat = await fs.stat(indexFile);
if (stat.isFile()) {
return indexFile;
}
await fs.stat(indexFile);
return indexFile;
} catch {
// Ignore
}
}
throw new Error(`File not found: ${basePath}`);
}
throw new Error('File not found');
}