mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Restore lightningFsPlugin
This commit is contained in:
1 parent
30465d1fd1
commit
16863fd209
1 file changed
+10
-27
@@ -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');
|
||||
}
|
||||
Reference in new issue
Block a user