From d9ec69477b6489ccfd3415b07d2b5c69a46f6573 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 9 Feb 2026 22:16:51 +0000 Subject: [PATCH] Make prepack independent of PATH bun setup Co-authored-by: Theo Browne --- package.json | 2 +- scripts/prepack.mjs | 48 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 scripts/prepack.mjs diff --git a/package.json b/package.json index afd4f3d7fa..8ae77f71cc 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "lint": "oxlint --report-unused-disable-directives", "test": "turbo run test", "fmt": "oxfmt", - "prepack": "bun run build", + "prepack": "node scripts/prepack.mjs", "build:contracts": "bun run --cwd packages/contracts build" }, "dependencies": { diff --git a/scripts/prepack.mjs b/scripts/prepack.mjs new file mode 100644 index 0000000000..68baa2f0fa --- /dev/null +++ b/scripts/prepack.mjs @@ -0,0 +1,48 @@ +import { spawnSync } from "node:child_process"; +import os from "node:os"; +import path from "node:path"; + +function canExecute(command) { + const result = spawnSync(command, ["--version"], { + stdio: "ignore", + shell: false, + }); + return result.status === 0; +} + +function resolveBunPath() { + const candidates = [ + process.env.BUN_BIN, + "bun", + path.join(os.homedir(), ".bun", "bin", "bun"), + path.join(os.homedir(), ".bun", "bin", "bun.exe"), + ].filter(Boolean); + + for (const candidate of candidates) { + if (canExecute(candidate)) { + return candidate; + } + } + + throw new Error( + "Bun is required for prepack. Install from https://bun.sh and ensure bun is available.", + ); +} + +const bunPath = resolveBunPath(); +const buildSteps = [ + ["run", "--cwd", "packages/contracts", "build"], + ["run", "--cwd", "apps/renderer", "build"], + ["run", "--cwd", "apps/t3", "build"], +]; + +for (const step of buildSteps) { + const result = spawnSync(bunPath, step, { + stdio: "inherit", + shell: false, + env: process.env, + }); + if (result.status !== 0) { + process.exit(result.status ?? 1); + } +}