mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Correctly resolve transitive deps
This commit is contained in:
1 parent
ebc180a850
commit
c1e4f19327
3 files changed
+43
-20
No files matched your search
@@ -50,7 +50,17 @@ export function esmPlugin(packageLock: PackageLock, target?: string): Plugin {
|
||||
? args.path.split("/").slice(0, 2).join("/")
|
||||
: args.path.split("/")[0];
|
||||
|
||||
const packageInfo = packageLock.packages["node_modules/" + packageName];
|
||||
let packageKey = `node_modules/${packageName}`;
|
||||
if (args.importer.startsWith("https://esm.sh/")) {
|
||||
try {
|
||||
const importerPackage = new URL(args.importer).pathname.split('/')[1]?.split('@')[0].replace(/^\*/, '');
|
||||
packageKey = `node_modules/${importerPackage}/node_modules/${packageName}`;
|
||||
} catch {
|
||||
// fallthrough
|
||||
}
|
||||
}
|
||||
|
||||
const packageInfo = packageLock.packages[packageKey] || packageLock.packages[`node_modules/${packageName}`];
|
||||
const packagePath = args.path.slice(packageName.length);
|
||||
const version = packageInfo?.version;
|
||||
|
||||
|
||||
+29
-19
@@ -57,35 +57,45 @@ async function tryFileVariants(
|
||||
basePath: string,
|
||||
): Promise<string> {
|
||||
const extensions = [".ts", ".tsx", ".js", ".jsx", ".css"];
|
||||
const stat = await statSafe(fs, basePath);
|
||||
|
||||
try {
|
||||
await fs.stat(basePath);
|
||||
// If it's a file, check if it exists
|
||||
if (stat.isFile()) {
|
||||
return basePath;
|
||||
} catch {
|
||||
// Ignore
|
||||
}
|
||||
|
||||
// If it's a directory, try index files
|
||||
if (stat.isDirectory()) {
|
||||
for (const ext of extensions) {
|
||||
const indexFile = path.join(basePath, "index" + ext);
|
||||
const indexStat = await statSafe(fs, indexFile);
|
||||
if (indexStat.isFile()) {
|
||||
return indexFile;
|
||||
}
|
||||
}
|
||||
throw new Error("Directory without index file");
|
||||
}
|
||||
|
||||
// Try direct file with extensions
|
||||
for (const ext of extensions) {
|
||||
const full = basePath + ext;
|
||||
try {
|
||||
await fs.stat(full);
|
||||
const fullStat = await statSafe(fs, full);
|
||||
if (fullStat.isFile()) {
|
||||
return full;
|
||||
} catch {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
|
||||
// Try directory index files
|
||||
for (const ext of extensions) {
|
||||
const indexFile = path.join(basePath, "index" + ext);
|
||||
try {
|
||||
await fs.stat(indexFile);
|
||||
return indexFile;
|
||||
} catch {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
|
||||
// If no file found, throw an error
|
||||
throw new Error("File not found");
|
||||
}
|
||||
|
||||
async function statSafe(fs: JSRuntimeFS, filePath: string): Promise<{ isFile(): boolean; isDirectory(): boolean }> {
|
||||
try {
|
||||
return await fs.stat(filePath);
|
||||
} catch {
|
||||
return {
|
||||
isFile: () => false,
|
||||
isDirectory: () => false,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -50,6 +50,9 @@ export async function buildProject(
|
||||
fsPlugin(fs, `${projectPath}/src`),
|
||||
esmPlugin(JSON.parse(packageLockText), target),
|
||||
],
|
||||
define: {
|
||||
"import.meta.env": JSON.stringify({}),
|
||||
},
|
||||
});
|
||||
|
||||
const dist: Record<string, Uint8Array> = {};
|
||||
|
||||
Reference in new issue
Block a user