Skip to content

Commit 77b8020

Browse files
committed
fix: bundle bun for npm installs
1 parent 0203393 commit 77b8020

5 files changed

Lines changed: 71 additions & 4 deletions

File tree

.github/workflows/ci.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,16 @@ jobs:
8585
run: |
8686
pkg_dir="$(mktemp -d)"
8787
install_dir="$(mktemp -d)"
88+
node_dir="$(dirname "$(command -v node)")"
8889
npm pack --pack-destination "$pkg_dir" >/dev/null
8990
pkg="$(find "$pkg_dir" -maxdepth 1 -name 'hunkdiff-*.tgz' | head -n1)"
9091
npm install -g --prefix "$install_dir" "$pkg"
91-
PATH="$install_dir/bin:$PATH" hunk --help | grep 'Usage: hunk'
92+
PATH="$install_dir/bin:$node_dir:/usr/bin:/bin"
93+
if command -v bun >/dev/null 2>&1; then
94+
echo "bun unexpectedly available on the sanitized PATH" >&2
95+
exit 1
96+
fi
97+
hunk --help | grep 'Usage: hunk'
9298
9399
build-bin:
94100
name: Build compiled binary

bin/hunk.cjs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env node
2+
3+
const { spawnSync } = require("node:child_process");
4+
const path = require("node:path");
5+
6+
const entrypoint = path.join(__dirname, "..", "dist", "npm", "main.js");
7+
8+
let bunBinary;
9+
10+
try {
11+
bunBinary = require.resolve("bun/bin/bun.exe");
12+
} catch (error) {
13+
console.error(
14+
"Failed to resolve the bundled Bun runtime. Try reinstalling hunkdiff.",
15+
);
16+
if (error && error.message) {
17+
console.error(error.message);
18+
}
19+
process.exit(1);
20+
}
21+
22+
const result = spawnSync(bunBinary, [entrypoint, ...process.argv.slice(2)], {
23+
stdio: "inherit",
24+
env: process.env,
25+
});
26+
27+
if (result.error) {
28+
console.error(result.error.message);
29+
process.exit(1);
30+
}
31+
32+
process.exit(typeof result.status === "number" ? result.status : 1);

bun.lock

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
"type": "module",
66
"packageManager": "bun@1.3.10",
77
"bin": {
8-
"hunk": "dist/npm/main.js"
8+
"hunk": "./bin/hunk.cjs"
99
},
1010
"files": [
11+
"bin",
1112
"dist/npm",
1213
"README.md",
1314
"LICENSE",
@@ -46,7 +47,7 @@
4647
"url": "https://github.com/modem-dev/hunk/issues"
4748
},
4849
"engines": {
49-
"bun": ">=1.3.10"
50+
"node": ">=18"
5051
},
5152
"publishConfig": {
5253
"access": "public"
@@ -60,6 +61,7 @@
6061
"@opentui/core": "^0.1.88",
6162
"@opentui/react": "^0.1.88",
6263
"@pierre/diffs": "^1.1.0",
64+
"bun": "^1.3.10",
6365
"commander": "^14.0.3",
6466
"diff": "^8.0.3",
6567
"parse-diff": "^0.11.1",

scripts/check-pack.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ if (!pack) {
4545
}
4646

4747
const publishedPaths = new Set(pack.files.map((file) => file.path));
48-
const requiredPaths = ["dist/npm/main.js", "README.md", "LICENSE", "package.json"];
48+
const requiredPaths = ["bin/hunk.cjs", "dist/npm/main.js", "README.md", "LICENSE", "package.json"];
4949
const optionalPaths = ["CONTRIBUTING.md", "SECURITY.md"];
5050

5151
for (const path of requiredPaths) {

0 commit comments

Comments
 (0)