Externalize node-forge

This commit is contained in:
Sander Declerck 2025-11-28 15:03:36 +01:00
parent bb3e50008a
commit 1d00084202
No known key found for this signature in database
2 changed files with 9 additions and 11 deletions

View file

@ -32,7 +32,7 @@ async function bundleSafeChain() {
platform: "node", platform: "node",
target: "node24", target: "node24",
outfile: "./build/bin/safe-chain.cjs", outfile: "./build/bin/safe-chain.cjs",
external: ["certifi"], external: ["certifi", "node-forge"],
}); });
} }
@ -53,11 +53,13 @@ async function copyShellScripts() {
async function copyCertifi() { async function copyCertifi() {
await mkdir("./build/node_modules/certifi", { recursive: true }); await mkdir("./build/node_modules/certifi", { recursive: true });
await cp( await mkdir("./build/node_modules/certifi", { recursive: true });
"./node_modules/certifi/", await cp("./node_modules/certifi/", "./build/node_modules/certifi", {
"./build/node_modules/certifi", recursive: true,
{ recursive: true } });
); await cp("./node_modules/node-forge/", "./build/node_modules/node-forge", {
recursive: true,
});
} }
async function copyAndModifyPackageJson() { async function copyAndModifyPackageJson() {
const packageJsonContent = await readFile( const packageJsonContent = await readFile(
@ -80,6 +82,7 @@ async function copyAndModifyPackageJson() {
outputPath: "dist", outputPath: "dist",
assets: [ assets: [
"node_modules/certifi/**/*", "node_modules/certifi/**/*",
"node_modules/node-forge/**/*",
"bin/startup-scripts/**/*", "bin/startup-scripts/**/*",
"bin/path-wrappers/**/*", "bin/path-wrappers/**/*",
], ],

View file

@ -3,11 +3,6 @@ import path from "path";
import fs from "fs"; import fs from "fs";
import os from "os"; import os from "os";
// Force node-forge to use pure JavaScript instead of native crypto
// This prevents segmentation faults in pkg binaries on Linux
// @ts-ignore - options exists but isn't in the type definitions
forge.options.usePureJavaScript = true;
const certFolder = path.join(os.homedir(), ".safe-chain", "certs"); const certFolder = path.join(os.homedir(), ".safe-chain", "certs");
const ca = loadCa(); const ca = loadCa();