Make prepack independent of PATH bun setup

Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
Cursor AgentandTheo Browne committed 2026-02-09 22:16:51 +00:00
1 parent 9e804c3c85
commit d9ec69477b
2 files changed
+49 -1

No files matched your search

+1 -1
View File
@@ -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": {
+48
View File
@@ -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);
}
}