Correctly resolve transitive deps

This commit is contained in:
Alex Gleason committed 2025-08-11 17:21:29 -07:00
1 parent 4f608d2dd2
commit 4a9bf570f8
3 files changed
+43 -20

No files matched your search

+11 -1
View File
@@ -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
View File
@@ -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,
};
}
}
+3
View File
@@ -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> = {};