Skip to content

Commit 23a9d3b

Browse files
authored
fix: bundle bun for npm installs (#11)
1 parent e56390f commit 23a9d3b

6 files changed

Lines changed: 75 additions & 5 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

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ Hunk is a terminal diff viewer for reviewing agent-authored changesets with a de
1414
npm i -g hunkdiff
1515
```
1616

17-
For now, the published `hunk` executable still expects [Bun](https://bun.sh) 1.3.10+ to be available on your `PATH` at runtime.
17+
## Requirements
18+
19+
- Node.js 18+
20+
- Git for `hunk diff`, `hunk show`, `hunk stash show`, and pager integration
1821

1922
## Quick start
2023

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"
@@ -44,7 +45,7 @@
4445
"url": "https://github.com/modem-dev/hunk/issues"
4546
},
4647
"engines": {
47-
"bun": ">=1.3.10"
48+
"node": ">=18"
4849
},
4950
"publishConfig": {
5051
"access": "public"
@@ -58,6 +59,7 @@
5859
"@opentui/core": "^0.1.88",
5960
"@opentui/react": "^0.1.88",
6061
"@pierre/diffs": "^1.1.0",
62+
"bun": "^1.3.10",
6163
"commander": "^14.0.3",
6264
"diff": "^8.0.3",
6365
"parse-diff": "^0.11.1",

scripts/check-pack.ts

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

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

4848
for (const path of requiredPaths) {
4949
if (!publishedPaths.has(path)) {

0 commit comments

Comments
 (0)