Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,16 @@ jobs:
run: |
pkg_dir="$(mktemp -d)"
install_dir="$(mktemp -d)"
node_dir="$(dirname "$(command -v node)")"
npm pack --pack-destination "$pkg_dir" >/dev/null
pkg="$(find "$pkg_dir" -maxdepth 1 -name 'hunkdiff-*.tgz' | head -n1)"
npm install -g --prefix "$install_dir" "$pkg"
PATH="$install_dir/bin:$PATH" hunk --help | grep 'Usage: hunk'
PATH="$install_dir/bin:$node_dir:/usr/bin:/bin"
if command -v bun >/dev/null 2>&1; then
echo "bun unexpectedly available on the sanitized PATH" >&2
exit 1
fi
hunk --help | grep 'Usage: hunk'

build-bin:
name: Build compiled binary
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ Hunk is a terminal diff viewer for reviewing agent-authored changesets with a de
npm i -g hunkdiff
```

For now, the published `hunk` executable still expects [Bun](https://bun.sh) 1.3.10+ to be available on your `PATH` at runtime.
## Requirements

- Node.js 18+
- Git for `hunk diff`, `hunk show`, `hunk stash show`, and pager integration

## Quick start

Expand Down
32 changes: 32 additions & 0 deletions bin/hunk.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env node

const { spawnSync } = require("node:child_process");
const path = require("node:path");

const entrypoint = path.join(__dirname, "..", "dist", "npm", "main.js");

let bunBinary;

try {
bunBinary = require.resolve("bun/bin/bun.exe");
} catch (error) {
console.error(
"Failed to resolve the bundled Bun runtime. Try reinstalling hunkdiff.",
);
if (error && error.message) {
console.error(error.message);
}
process.exit(1);
}

const result = spawnSync(bunBinary, [entrypoint, ...process.argv.slice(2)], {
stdio: "inherit",
env: process.env,
});

if (result.error) {
console.error(result.error.message);
process.exit(1);
}

process.exit(typeof result.status === "number" ? result.status : 1);
27 changes: 27 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
"type": "module",
"packageManager": "bun@1.3.10",
"bin": {
"hunk": "dist/npm/main.js"
"hunk": "./bin/hunk.cjs"
},
"files": [
"bin",
"dist/npm",
"README.md",
"LICENSE"
Expand Down Expand Up @@ -44,7 +45,7 @@
"url": "https://github.com/modem-dev/hunk/issues"
},
"engines": {
"bun": ">=1.3.10"
"node": ">=18"
},
"publishConfig": {
"access": "public"
Expand All @@ -58,6 +59,7 @@
"@opentui/core": "^0.1.88",
"@opentui/react": "^0.1.88",
"@pierre/diffs": "^1.1.0",
"bun": "^1.3.10",
"commander": "^14.0.3",
"diff": "^8.0.3",
"parse-diff": "^0.11.1",
Expand Down
2 changes: 1 addition & 1 deletion scripts/check-pack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ if (!pack) {
}

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

for (const path of requiredPaths) {
if (!publishedPaths.has(path)) {
Expand Down
Loading