fix(tui): externalize koffi from bun binary builds

Changed koffi import from top-level to dynamic require in
enableWindowsVTInput() and added --external koffi to bun build.
This prevents embedding all 18 platform .node files (~74MB) into
every compiled binary. For Windows builds, only the win32_x64
koffi.node is shipped alongside the binary.

Binary size reduction: darwin-arm64 142MB -> 67MB, archive 43MB -> 28MB.
This commit is contained in:
Mario Zechner 2026-02-22 14:29:21 +01:00
parent 3a3e37d390
commit 8386a807ff
4 changed files with 26 additions and 3 deletions

View file

@ -2,6 +2,10 @@
## [Unreleased]
### Fixed
- Externalized koffi from bun binary builds, reducing archive sizes by ~15MB per platform (e.g. darwin-arm64: 43MB -> 28MB). Koffi's Windows-only `.node` file is now shipped alongside the Windows binary only.
## [0.54.0] - 2026-02-19
### Added

View file

@ -2,6 +2,10 @@
## [Unreleased]
### Fixed
- Changed koffi import from top-level to dynamic require in `enableWindowsVTInput()` to prevent bun from embedding all 18 platform `.node` files (~74MB) into every compiled binary. Koffi is only needed on Windows.
## [0.54.0] - 2026-02-19
## [0.53.1] - 2026-02-19

View file

@ -1,5 +1,4 @@
import * as fs from "node:fs";
import koffi from "koffi";
import { setKittyProtocolActive } from "./keys.js";
import { StdinBuffer } from "./stdin-buffer.js";
@ -174,6 +173,10 @@ export class ProcessTerminal implements Terminal {
private enableWindowsVTInput(): void {
if (process.platform !== "win32") return;
try {
// Dynamic require to avoid bundling koffi's 74MB of cross-platform
// native binaries into every compiled binary. Koffi is only needed
// on Windows for VT input support.
const koffi = require("koffi");
const k32 = koffi.load("kernel32.dll");
const GetStdHandle = k32.func("void* __stdcall GetStdHandle(int)");
const GetConsoleMode = k32.func("bool __stdcall GetConsoleMode(void*, _Out_ uint32_t*)");