hunkdiff 0.2.0 → 0.3.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -242,6 +242,25 @@ bun run build:npm
242
242
  bun run check:pack
243
243
  ```
244
244
 
245
+ Stage the prebuilt npm packages for the current host and smoke test the install path without Bun on `PATH`:
246
+
247
+ ```bash
248
+ bun run build:prebuilt:npm
249
+ bun run check:prebuilt-pack
250
+ bun run smoke:prebuilt-install
251
+ ```
252
+
253
+ Prepare the multi-platform release directories from downloaded build artifacts and dry-run the publish order:
254
+
255
+ ```bash
256
+ bun run build:prebuilt:artifact
257
+ bun run stage:prebuilt:release
258
+ bun run check:prebuilt-pack
259
+ bun run publish:prebuilt:npm -- --dry-run
260
+ ```
261
+
262
+ The automated tag/manual release workflow lives in `.github/workflows/release-prebuilt-npm.yml`.
263
+
245
264
  ## License
246
265
 
247
266
  [MIT](LICENSE)
package/bin/hunk.cjs CHANGED
@@ -1,32 +1,103 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const { spawnSync } = require("node:child_process");
3
+ const childProcess = require("node:child_process");
4
+ const fs = require("node:fs");
5
+ const os = require("node:os");
4
6
  const path = require("node:path");
5
7
 
6
- const entrypoint = path.join(__dirname, "..", "dist", "npm", "main.js");
8
+ function run(target, args) {
9
+ const result = childProcess.spawnSync(target, args, {
10
+ stdio: "inherit",
11
+ env: process.env,
12
+ });
7
13
 
8
- let bunBinary;
14
+ if (result.error) {
15
+ console.error(result.error.message);
16
+ process.exit(1);
17
+ }
18
+
19
+ process.exit(typeof result.status === "number" ? result.status : 1);
20
+ }
21
+
22
+ function hostCandidates() {
23
+ const platformMap = {
24
+ darwin: "darwin",
25
+ linux: "linux",
26
+ win32: "windows",
27
+ };
28
+ const archMap = {
29
+ x64: "x64",
30
+ arm64: "arm64",
31
+ };
32
+
33
+ const platform = platformMap[os.platform()] || os.platform();
34
+ const arch = archMap[os.arch()] || os.arch();
35
+ const binary = platform === "windows" ? "hunk.exe" : "hunk";
9
36
 
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);
37
+ if (platform === "darwin") {
38
+ if (arch === "arm64") return [{ packageName: "hunkdiff-darwin-arm64", binary }];
39
+ if (arch === "x64") return [{ packageName: "hunkdiff-darwin-x64", binary }];
18
40
  }
19
- process.exit(1);
41
+
42
+ if (platform === "linux") {
43
+ if (arch === "arm64") return [{ packageName: "hunkdiff-linux-arm64", binary }];
44
+ if (arch === "x64") return [{ packageName: "hunkdiff-linux-x64", binary }];
45
+ }
46
+
47
+ return [];
20
48
  }
21
49
 
22
- const result = spawnSync(bunBinary, [entrypoint, ...process.argv.slice(2)], {
23
- stdio: "inherit",
24
- env: process.env,
25
- });
50
+ function findInstalledBinary(startDir) {
51
+ let current = startDir;
52
+
53
+ for (;;) {
54
+ const modulesDir = path.join(current, "node_modules");
55
+ if (fs.existsSync(modulesDir)) {
56
+ for (const candidate of hostCandidates()) {
57
+ const resolved = path.join(modulesDir, candidate.packageName, "bin", candidate.binary);
58
+ if (fs.existsSync(resolved)) {
59
+ return resolved;
60
+ }
61
+ }
62
+ }
63
+
64
+ const parent = path.dirname(current);
65
+ if (parent === current) {
66
+ return null;
67
+ }
68
+ current = parent;
69
+ }
70
+ }
71
+
72
+ function bundledBunRuntime() {
73
+ try {
74
+ return require.resolve("bun/bin/bun.exe");
75
+ } catch {
76
+ return null;
77
+ }
78
+ }
79
+
80
+ const overrideBinary = process.env.HUNK_BIN_PATH;
81
+ if (overrideBinary) {
82
+ run(overrideBinary, process.argv.slice(2));
83
+ }
84
+
85
+ const scriptDir = path.dirname(fs.realpathSync(__filename));
86
+ const prebuiltBinary = findInstalledBinary(scriptDir);
87
+ if (prebuiltBinary) {
88
+ run(prebuiltBinary, process.argv.slice(2));
89
+ }
26
90
 
27
- if (result.error) {
28
- console.error(result.error.message);
29
- process.exit(1);
91
+ const bunBinary = bundledBunRuntime();
92
+ if (bunBinary) {
93
+ const entrypoint = path.join(__dirname, "..", "dist", "npm", "main.js");
94
+ run(bunBinary, [entrypoint, ...process.argv.slice(2)]);
30
95
  }
31
96
 
32
- process.exit(typeof result.status === "number" ? result.status : 1);
97
+ const printablePackages = hostCandidates().map((candidate) => `"${candidate.packageName}"`).join(" or ");
98
+ console.error(
99
+ printablePackages.length > 0
100
+ ? `Failed to locate a matching prebuilt Hunk binary. Try reinstalling hunkdiff or manually installing ${printablePackages}.`
101
+ : `Unsupported platform for prebuilt Hunk binaries: ${os.platform()} ${os.arch()}`,
102
+ );
103
+ process.exit(1);
package/package.json CHANGED
@@ -1,33 +1,15 @@
1
1
  {
2
2
  "name": "hunkdiff",
3
- "version": "0.2.0",
3
+ "version": "0.3.0-beta.1",
4
4
  "description": "Desktop-inspired terminal diff viewer for understanding agent-authored changesets.",
5
- "type": "module",
6
- "packageManager": "bun@1.3.10",
7
5
  "bin": {
8
6
  "hunk": "./bin/hunk.cjs"
9
7
  },
10
8
  "files": [
11
9
  "bin",
12
- "dist/npm",
13
10
  "README.md",
14
11
  "LICENSE"
15
12
  ],
16
- "scripts": {
17
- "start": "bun run src/main.tsx",
18
- "dev": "bun --watch src/main.tsx",
19
- "build:npm": "bash ./scripts/build-npm.sh",
20
- "build:bin": "bash ./scripts/build-bin.sh",
21
- "install:bin": "bash ./scripts/install-bin.sh",
22
- "typecheck": "tsc --noEmit",
23
- "test": "bun test",
24
- "test:tty-smoke": "bun test test/tty-render-smoke.test.ts",
25
- "check:pack": "bun run ./scripts/check-pack.ts",
26
- "prepack": "bun run build:npm",
27
- "bench:bootstrap-load": "bun run test/bootstrap-load-benchmark.ts",
28
- "bench:highlight-prefetch": "bun run test/adjacent-highlight-prefetch-benchmark.ts",
29
- "bench:large-stream": "bun run test/large-stream-windowing-benchmark.ts"
30
- },
31
13
  "keywords": [
32
14
  "diff",
33
15
  "git",
@@ -47,23 +29,13 @@
47
29
  "engines": {
48
30
  "node": ">=18"
49
31
  },
32
+ "optionalDependencies": {
33
+ "hunkdiff-darwin-arm64": "0.3.0-beta.1",
34
+ "hunkdiff-darwin-x64": "0.3.0-beta.1",
35
+ "hunkdiff-linux-x64": "0.3.0-beta.1"
36
+ },
37
+ "license": "MIT",
50
38
  "publishConfig": {
51
39
  "access": "public"
52
- },
53
- "devDependencies": {
54
- "@types/bun": "latest",
55
- "@types/react": "^19.2.14",
56
- "typescript": "^5.9.3"
57
- },
58
- "dependencies": {
59
- "@opentui/core": "^0.1.88",
60
- "@opentui/react": "^0.1.88",
61
- "@pierre/diffs": "^1.1.0",
62
- "bun": "^1.3.10",
63
- "commander": "^14.0.3",
64
- "diff": "^8.0.3",
65
- "parse-diff": "^0.11.1",
66
- "react": "^19.2.4"
67
- },
68
- "license": "MIT"
40
+ }
69
41
  }