fix: harden native workspace root capabilities

This commit is contained in:
2026-08-11 19:33:59 +02:00
parent 29a2e507a9
commit e35e62a5c6
7 changed files with 155 additions and 182 deletions
+10 -1
View File
@@ -7,7 +7,16 @@ if (major !== 22 || Number(process.versions.napi ?? 0) < 8) throw new Error(`wor
if (process.platform !== "linux" && process.platform !== "darwin") throw new Error(`workspace-fs-at unsupported platform: ${process.platform}`);
const root = resolve(dirname(fileURLToPath(import.meta.url)), "../native/workspace-fs-at");
const npm = process.platform === "win32" ? "npm.cmd" : "npm";
const result = spawnSync(npm, ["exec", "--offline", "--", "node-gyp@11.2.0", "rebuild", "--offline"], { cwd: root, stdio: "inherit" });
const headerCandidates = [
process.env.npm_config_nodedir,
"/usr/local/include/node",
"/usr/include/node",
resolve(process.execPath, "../../include/node"),
].filter((p) => p && existsSync(resolve(p, "node_api.h")));
if (headerCandidates.length === 0) throw new Error("workspace-fs-at requires installed Node 22 headers; network downloads are forbidden");
const headerRoot = headerCandidates[0].endsWith("/include/node") ? resolve(headerCandidates[0], "../..") : headerCandidates[0];
const env = { ...process.env, npm_config_nodedir: headerRoot, npm_config_offline: "true", npm_config_node_gyp: undefined };
const result = spawnSync(npm, ["exec", "--offline", "--", "node-gyp@11.2.0", "rebuild", "--offline"], { cwd: root, stdio: "inherit", env });
if (result.error) throw result.error;
if (result.status !== 0) process.exit(result.status ?? 1);
const output = resolve(root, "build/Release/workspace_fs_at.node");