-
Notifications
You must be signed in to change notification settings - Fork 74
feat: complete native Windows 11 support #285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+255
−103
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e51b4a8
feat(scripts): port build/install bash scripts to TypeScript
Ofekw 2747520
fix(scripts): make repo scripts work on native Windows
Ofekw d088701
docs: declare native Windows support
Ofekw a38e516
fix(scripts): address review nits in install-bin and stage-prebuilt-npm
Ofekw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}`); |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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")}`); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
| 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`); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.