From 31ab27a79a4210c7e1250f7d937a4a5d349a1825 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 20 Jan 2026 16:50:46 -0600 Subject: [PATCH] Polyfill node:crypto, allow building with files outside of project directory --- src/lib/build/esmPlugin.ts | 5 +++++ src/lib/build/fsPlugin.ts | 7 +------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib/build/esmPlugin.ts b/src/lib/build/esmPlugin.ts index 47db9992..02602cd4 100644 --- a/src/lib/build/esmPlugin.ts +++ b/src/lib/build/esmPlugin.ts @@ -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}` }], diff --git a/src/lib/build/fsPlugin.ts b/src/lib/build/fsPlugin.ts index b7bea340..4a8f24eb 100644 --- a/src/lib/build/fsPlugin.ts +++ b/src/lib/build/fsPlugin.ts @@ -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';