mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Improve resolution of imports in esmPlugin in some cases
This commit is contained in:
1 file changed
+21
@@ -44,6 +44,23 @@ export function esmPlugin(packageLock: PackageLock, target?: string): Plugin {
|
||||
};
|
||||
});
|
||||
|
||||
// node built-in modules
|
||||
build.onResolve({ filter: /^node:/ }, (args) => {
|
||||
const moduleName = args.path.slice(5);
|
||||
|
||||
switch (moduleName) {
|
||||
case "buffer":
|
||||
return {
|
||||
path: `https://esm.sh/${moduleName}?target=${target ?? "esnext"}`,
|
||||
namespace: "esm",
|
||||
};
|
||||
default:
|
||||
return {
|
||||
errors: [{ text: `Module not found: ${args.path}` }],
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
// Handle bare imports like "react"
|
||||
build.onResolve({ filter: /^[^./].*/ }, (args) => {
|
||||
const packageName = args.path.startsWith("@")
|
||||
@@ -63,6 +80,10 @@ export function esmPlugin(packageLock: PackageLock, target?: string): Plugin {
|
||||
|
||||
keys.push(`node_modules/${packageName}`);
|
||||
|
||||
if (packageName.startsWith("@jsr/")) {
|
||||
keys.push(`node_modules/@${packageName.slice(5).replace("__", "/")}`);
|
||||
}
|
||||
|
||||
const packageInfo = keys
|
||||
.map((key) => packageLock.packages[key])
|
||||
.find((info) => info);
|
||||
|
||||
Reference in new issue
Block a user