Skip to content

Commit a73cc4b

Browse files
committed
don't detach server
1 parent 3f4bd39 commit a73cc4b

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

‎apps/cli/src/build.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,30 @@ const binaryName = (t: Target) =>
7676
const isCurrentPlatform = (t: Target) =>
7777
t.os === process.platform && t.arch === process.arch && !t.abi;
7878

79+
/** Resolve the platform-specific secure-exec-v8 binary for a given target. */
80+
const resolveSecureExecV8 = (t: Target): string | null => {
81+
const platformMap: Record<string, string> = {
82+
"darwin-arm64": "@secure-exec/v8-darwin-arm64",
83+
"darwin-x64": "@secure-exec/v8-darwin-x64",
84+
"linux-arm64": "@secure-exec/v8-linux-arm64-gnu",
85+
"linux-x64": "@secure-exec/v8-linux-x64-gnu",
86+
};
87+
const key = `${t.os}-${t.arch}`;
88+
const pkg = platformMap[key];
89+
if (!pkg) return null;
90+
try {
91+
// Resolve from @secure-exec/v8 which has these as optional deps
92+
const req = createRequire(join(repoRoot, "node_modules", "secure-exec", "package.json"));
93+
const pkgJson = req.resolve(`${pkg}/package.json`);
94+
return join(dirname(pkgJson), "secure-exec-v8");
95+
} catch {
96+
// Try bun's flat node_modules layout
97+
const bunPath = join(repoRoot, `node_modules/.bun/${pkg.replace("/", "+")}@0.2.1/node_modules/${pkg}/secure-exec-v8`);
98+
if (existsSync(bunPath)) return bunPath;
99+
return null;
100+
}
101+
};
102+
79103
// ---------------------------------------------------------------------------
80104
// Build web app
81105
// ---------------------------------------------------------------------------
@@ -231,6 +255,14 @@ const buildBinaries = async (targets: Target[]) => {
231255
// Copy QuickJS WASM next to binary — loaded at runtime by the server
232256
await cp(quickJsWasmPath, join(binDir, "emscripten-module.wasm"));
233257

258+
// Copy secure-exec-v8 binary next to executor — needed for code execution
259+
const secureExecBin = resolveSecureExecV8(target);
260+
if (secureExecBin && existsSync(secureExecBin)) {
261+
const destName = target.os === "win32" ? "secure-exec-v8.exe" : "secure-exec-v8";
262+
await cp(secureExecBin, join(binDir, destName));
263+
await chmod(join(binDir, destName), 0o755);
264+
}
265+
234266
// Smoke test on current platform
235267
if (isCurrentPlatform(target)) {
236268
const bin = join(binDir, binaryName(target));

‎apps/cli/src/main.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
// Pre-load QuickJS WASM for compiled binaries — must run before server imports
1+
// Ensure binaries next to the executor (e.g. secure-exec-v8) are on $PATH
22
import { dirname, join } from "node:path";
3-
const wasmOnDisk = join(dirname(process.execPath), "emscripten-module.wasm");
3+
const execDir = dirname(process.execPath);
4+
if (process.env.PATH && !process.env.PATH.includes(execDir)) {
5+
process.env.PATH = `${execDir}:${process.env.PATH}`;
6+
}
7+
8+
// Pre-load QuickJS WASM for compiled binaries — must run before server imports
9+
const wasmOnDisk = join(execDir, "emscripten-module.wasm");
410
if (typeof Bun !== "undefined" && await Bun.file(wasmOnDisk).exists()) {
511
const { setQuickJSModule } = await import("@executor/runtime-quickjs");
612
const { newQuickJSWASMModule } = await import("quickjs-emscripten");

0 commit comments

Comments
 (0)