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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ All notable user-visible changes to Hunk are documented in this file.

- Added Windows x64 prebuilt artifact publishing to the release workflow.
- Added Nix flake app outputs for `nix run` and a named `hunk` package output.
- Documented native Windows support in the README and contributor guide.

### Changed

- Ported `build:npm`, `build:bin`, and `install:bin` from bash scripts to cross-platform Bun-runnable TypeScript so native Windows contributors no longer need Git Bash to build or install Hunk locally.

### Fixed

## [0.12.0-beta.1] - 2026-05-10
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Requirements:
- Bun 1.3+
- Node.js 18+
- Git
- macOS, Linux, or Windows. The Windows path uses native Node/Bun on Windows 10/11 (x64); no WSL or Git Bash required.

> Nix users can use `nix develop` or [direnv](https://direnv.net/) to enter a development shell.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ brew install modem-dev/tap/hunk
Requirements:

- Node.js 18+
- macOS or Linux
- macOS, Linux, or Windows
- Git recommended for most workflows

> Nix users can use the `default` package exported in `flake.nix` instead. See [nix/README.md](./nix/README.md) for details.
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@
"scripts": {
"start": "bun run src/main.tsx",
"dev": "bun --watch src/main.tsx",
"build:npm": "bash ./scripts/build-npm.sh",
"build:bin": "bash ./scripts/build-bin.sh",
"build:npm": "bun run ./scripts/build-npm.ts",
"build:bin": "bun run ./scripts/build-bin.ts",
"build:prebuilt:npm": "bun run build:npm && bun run build:bin && bun run ./scripts/stage-prebuilt-npm.ts",
"build:prebuilt:artifact": "bun run build:bin && bun run ./scripts/build-prebuilt-artifact.ts",
"stage:prebuilt:release": "bun run build:npm && bun run ./scripts/stage-prebuilt-npm.ts --artifact-root ./dist/release/artifacts",
"install:bin": "bash ./scripts/install-bin.sh",
"install:bin": "bun run ./scripts/install-bin.ts",
"typecheck": "tsc --noEmit",
"format": "oxfmt --write .",
"format:check": "oxfmt --check .",
Expand Down
16 changes: 0 additions & 16 deletions scripts/build-bin.sh

This file was deleted.

34 changes: 34 additions & 0 deletions scripts/build-bin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bun

import { mkdirSync, rmSync } from "node:fs";
import path from "node:path";

const repoRoot = path.resolve(import.meta.dir, "..");
const distDir = path.join(repoRoot, "dist");
const binaryName = process.platform === "win32" ? "hunk.exe" : "hunk";
const outfile = path.join(distDir, binaryName);
const legacyOutfile = path.join(distDir, process.platform === "win32" ? "otdiff.exe" : "otdiff");

mkdirSync(distDir, { recursive: true });
rmSync(legacyOutfile, { force: true });

const proc = Bun.spawnSync(
["bun", "build", "--compile", path.join(repoRoot, "src", "main.tsx"), "--outfile", outfile],
{
cwd: repoRoot,
stdin: "inherit",
stdout: "inherit",
stderr: "inherit",
env: {
...process.env,
BUN_TMPDIR: path.join(repoRoot, ".bun-tmp"),
BUN_INSTALL: path.join(repoRoot, ".bun-install"),
},
},
);

if (proc.exitCode !== 0) {
throw new Error(`bun build --compile failed with exit ${proc.exitCode}`);
}

console.log(`Built ${outfile}`);
44 changes: 0 additions & 44 deletions scripts/build-npm.sh

This file was deleted.

95 changes: 95 additions & 0 deletions scripts/build-npm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/usr/bin/env bun

import { chmodSync, copyFileSync, mkdirSync, readdirSync, rmSync } from "node:fs";
import path from "node:path";

const repoRoot = path.resolve(import.meta.dir, "..");
const outdir = path.join(repoRoot, "dist", "npm");
const typesOutdir = path.join(repoRoot, "dist", "npm-types");
const opentuiOutdir = path.join(outdir, "opentui");
const opentuiTypesDir = path.join(typesOutdir, "opentui");

const bunEnv = {
...process.env,
BUN_TMPDIR: path.join(repoRoot, ".bun-tmp"),
BUN_INSTALL: path.join(repoRoot, ".bun-install"),
};

function runBun(args: string[]) {
const proc = Bun.spawnSync(["bun", ...args], {
cwd: repoRoot,
stdin: "inherit",
stdout: "inherit",
stderr: "inherit",
env: bunEnv,
});

if (proc.exitCode !== 0) {
throw new Error(`bun ${args.join(" ")} failed with exit ${proc.exitCode}`);
}
}

rmSync(outdir, { recursive: true, force: true });
rmSync(typesOutdir, { recursive: true, force: true });
mkdirSync(opentuiOutdir, { recursive: true });

runBun([
"build",
path.join(repoRoot, "src", "main.tsx"),
"--target",
"bun",
"--format",
"esm",
"--outdir",
outdir,
"--entry-naming",
"main.js",
]);

const mainJs = path.join(outdir, "main.js");
// chmod is a no-op on Windows; preserve exec bits on Unix so the bin runs in npm-installed packages.
if (process.platform !== "win32") {
chmodSync(mainJs, 0o755);
}

runBun([
"build",
path.join(repoRoot, "src", "opentui", "index.ts"),
"--target",
"node",
"--format",
"esm",
"--external",
"react",
"--external",
"react/jsx-runtime",
"--external",
"react/jsx-dev-runtime",
"--external",
"@opentui/core",
"--external",
"@opentui/react",
"--external",
"@opentui/react/jsx-runtime",
"--external",
"@opentui/react/jsx-dev-runtime",
"--external",
"@pierre/diffs",
"--outdir",
opentuiOutdir,
"--entry-naming",
"index.js",
]);

runBun(["x", "tsc", "-p", path.join(repoRoot, "tsconfig.opentui.json")]);

for (const entry of readdirSync(opentuiTypesDir)) {
if (entry.endsWith(".d.ts")) {
copyFileSync(path.join(opentuiTypesDir, entry), path.join(opentuiOutdir, entry));
}
}

rmSync(typesOutdir, { recursive: true, force: true });

console.log(`Built ${mainJs}`);
console.log(`Built ${path.join(opentuiOutdir, "index.js")}`);
4 changes: 3 additions & 1 deletion scripts/check-pack.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bun

import { npmCommand } from "./script-helpers";

interface PackedFile {
path: string;
size: number;
Expand All @@ -13,7 +15,7 @@ interface PackResult {
files: PackedFile[];
}

const proc = Bun.spawnSync(["npm", "pack", "--dry-run", "--json"], {
const proc = Bun.spawnSync([npmCommand, "pack", "--dry-run", "--json"], {
cwd: process.cwd(),
stdin: "ignore",
stdout: "pipe",
Expand Down
3 changes: 2 additions & 1 deletion scripts/check-prebuilt-pack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { existsSync, readdirSync } from "node:fs";
import path from "node:path";
import { releaseNpmDir } from "./prebuilt-package-helpers";
import { npmCommand } from "./script-helpers";

interface PackedFile {
path: string;
Expand All @@ -15,7 +16,7 @@ interface PackResult {
}

function runPackDryRun(cwd: string) {
const proc = Bun.spawnSync(["npm", "pack", "--dry-run", "--json"], {
const proc = Bun.spawnSync([npmCommand, "pack", "--dry-run", "--json"], {
cwd,
stdin: "ignore",
stdout: "pipe",
Expand Down
23 changes: 0 additions & 23 deletions scripts/install-bin.sh

This file was deleted.

60 changes: 60 additions & 0 deletions scripts/install-bin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env bun

import { chmodSync, copyFileSync, mkdirSync, rmSync } from "node:fs";
import os from "node:os";
import path from "node:path";

const repoRoot = path.resolve(import.meta.dir, "..");
const isWindows = process.platform === "win32";
const binaryName = isWindows ? "hunk.exe" : "hunk";
const legacyBinaryName = isWindows ? "otdiff.exe" : "otdiff";
const binaryPath = path.join(repoRoot, "dist", binaryName);

function defaultInstallDir() {
if (isWindows) {
const base = process.env.LOCALAPPDATA ?? path.join(os.homedir(), "AppData", "Local");
return path.join(base, "Programs", "hunk");
}

return path.join(os.homedir(), ".local", "bin");
}

const installDir = process.env.HUNK_INSTALL_DIR ?? defaultInstallDir();
const installPath = path.join(installDir, binaryName);
const legacyInstallPath = path.join(installDir, legacyBinaryName);

const buildScript = path.join(repoRoot, "scripts", "build-bin.ts");
const build = Bun.spawnSync(["bun", "run", buildScript], {
cwd: repoRoot,
stdin: "inherit",
stdout: "inherit",
stderr: "inherit",
env: process.env,
});

if (build.exitCode !== 0) {
throw new Error(`scripts/build-bin.ts failed with exit ${build.exitCode}`);
}

mkdirSync(installDir, { recursive: true });
copyFileSync(binaryPath, installPath);
if (!isWindows) {
chmodSync(installPath, 0o755);
}
rmSync(legacyInstallPath, { force: true });

console.log(`Installed ${installPath}`);

const pathEntries = (process.env.PATH ?? "").split(path.delimiter).filter(Boolean);
const installDirOnPath = pathEntries.some((entry) => {
// Windows paths are case-insensitive; normalize both sides for the comparison.
Comment thread
Ofekw marked this conversation as resolved.
const normalizedEntry = isWindows ? path.normalize(entry).toLowerCase() : path.normalize(entry);
const normalizedInstallDir = isWindows
? path.normalize(installDir).toLowerCase()
: path.normalize(installDir);
return normalizedEntry === normalizedInstallDir;
});

if (!installDirOnPath) {
console.warn(`Warning: ${installDir} is not on PATH`);
}
5 changes: 3 additions & 2 deletions scripts/publish-prebuilt-npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { existsSync, readdirSync, readFileSync } from "node:fs";
import path from "node:path";
import { releaseNpmDir } from "./prebuilt-package-helpers";
import { npmCommand } from "./script-helpers";

type PackageJson = {
name: string;
Expand Down Expand Up @@ -41,7 +42,7 @@ function parseArgs(argv: string[]) {
}

function npmViewExists(name: string, version: string) {
const proc = Bun.spawnSync(["npm", "view", `${name}@${version}`, "version"], {
const proc = Bun.spawnSync([npmCommand, "view", `${name}@${version}`, "version"], {
stdin: "ignore",
stdout: "pipe",
stderr: "ignore",
Expand Down Expand Up @@ -70,7 +71,7 @@ function publishDirectory(directory: string, dryRun: boolean, npmTag: string) {
args.push("--dry-run");
}

const proc = Bun.spawnSync(["npm", ...args], {
const proc = Bun.spawnSync([npmCommand, ...args], {
cwd: directory,
stdin: "ignore",
stdout: "inherit",
Expand Down
Loading
Loading