Polyfill node:crypto, allow building with files outside of project directory

This commit is contained in:
Alex Gleason committed 2026-01-20 16:50:46 -06:00
1 parent 13ea7c192e
commit 31ab27a79a
2 files changed
+6 -6

No files matched your search

+5
View File
@@ -226,6 +226,11 @@ export function esmPlugin(options: EsmPluginOptions): Plugin {
path: `${esmUrl}/${moduleName}?target=${target ?? "esnext"}`,
namespace: "esm",
};
case "crypto":
return {
path: `${esmUrl}/crypto-browserify?target=${target ?? "esnext"}`,
namespace: "esm",
};
default:
return {
errors: [{ text: `Module not found: ${args.path}` }],
+1 -6
View File
@@ -99,11 +99,6 @@ export function fsPlugin(options: FsPluginOptions): Plugin {
return;
}
// Security: prevent accessing files outside the project directory
if (resolved.startsWith("/") && !resolved.startsWith(cwd)) {
throw new Error(`Access to files outside the project directory is not allowed: ${resolved}`);
}
// Vite query parameters https://vite.dev/guide/assets
const [cleaned, query] = resolved.split("?");
@@ -174,7 +169,7 @@ async function tryFileVariants(
const packageJson = JSON.parse(packageJsonText);
// Check for various entry point fields
const entryPoint = packageJson.exports?.['.']
const entryPoint = packageJson.exports?.['.']
|| packageJson.module
|| packageJson.main
|| 'index.js';