Skip to content

Commit 69b8eba

Browse files
ochafikclaude
authored andcommitted
fix: use run-bun.mjs wrapper for prepare hook compatibility
During npm install's prepare hook, node_modules/.bin is not in PATH, so calling 'bun' directly fails. The new run-bun.mjs wrapper finds bun at node_modules/.bin/bun and runs it with the correct path. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent e60adf6 commit 69b8eba

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"scripts": {
3535
"postinstall": "node scripts/setup-bun.mjs || echo 'setup-bun.mjs failed or not available'",
3636
"generate:schemas": "tsx scripts/generate-schemas.ts && prettier --write \"src/generated/**/*\"",
37-
"build": "npm run generate:schemas && bun build.bun.ts",
37+
"build": "npm run generate:schemas && node scripts/run-bun.mjs build.bun.ts",
3838
"prepack": "npm run build",
3939
"build:all": "npm run build && npm run examples:build",
4040
"test": "bun test src",

scripts/run-bun.mjs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env node
2+
/**
3+
* Wrapper script to run bun with the correct path.
4+
* This is needed because during npm install's prepare hook,
5+
* node_modules/.bin is not in PATH yet.
6+
*/
7+
import { spawn } from "child_process";
8+
import { existsSync } from "fs";
9+
import { join, dirname } from "path";
10+
import { fileURLToPath } from "url";
11+
12+
const __dirname = dirname(fileURLToPath(import.meta.url));
13+
const projectRoot = join(__dirname, "..");
14+
const isWindows = process.platform === "win32";
15+
const bunExe = isWindows ? "bun.exe" : "bun";
16+
17+
// Find bun binary
18+
const bunPaths = [
19+
join(projectRoot, "node_modules", ".bin", bunExe),
20+
// Fallback to system bun
21+
"bun",
22+
];
23+
24+
let bunPath = null;
25+
for (const p of bunPaths) {
26+
if (p === "bun" || existsSync(p)) {
27+
bunPath = p;
28+
break;
29+
}
30+
}
31+
32+
if (!bunPath) {
33+
console.error("Could not find bun binary");
34+
process.exit(1);
35+
}
36+
37+
// Run bun with the provided arguments
38+
const args = process.argv.slice(2);
39+
const child = spawn(bunPath, args, {
40+
stdio: "inherit",
41+
shell: isWindows,
42+
});
43+
44+
child.on("exit", (code) => {
45+
process.exit(code ?? 0);
46+
});
47+
48+
child.on("error", (err) => {
49+
console.error("Failed to run bun:", err.message);
50+
process.exit(1);
51+
});

0 commit comments

Comments
 (0)