diff --git a/.github/scripts/build-binaries.sh b/.github/scripts/build-binaries.sh index 1ba7133..ba306af 100755 --- a/.github/scripts/build-binaries.sh +++ b/.github/scripts/build-binaries.sh @@ -16,17 +16,14 @@ # linux binary — the only one it can execute — so no artifact ships unexecuted. set -euo pipefail -# `ct --version` reads a build-time constant (src/version.ts); bun's --define -# substitutes it, exactly as tsup.config.ts does for the npm bundle. The value has -# to arrive as a JS string *expression*, hence the JSON quoting. +# `ct --version` reads a build-time constant (src/version.ts); build-binary.ts +# defines it, exactly as tsup.config.ts does for the npm bundle. version="$(node -p 'require("./package.json").version')" -version_literal="$(node -p 'JSON.stringify(process.argv[1])' "$version")" echo "Compiling ct binaries for version ${version}" mkdir -p release for target in darwin-arm64 darwin-x64 linux-x64; do - bun build --compile --target="bun-${target}" \ - --define "__CT_VERSION__=${version_literal}" \ - ./src/index.ts --outfile "release/ct-${target}" + # build-binary.ts wraps `bun build --compile` with a stub for Ink's optional devtools. + bun .github/scripts/build-binary.ts "bun-${target}" "release/ct-${target}" "$version" done chmod +x release/ct-darwin-arm64 release/ct-darwin-x64 release/ct-linux-x64 diff --git a/.github/scripts/build-binary.ts b/.github/scripts/build-binary.ts new file mode 100644 index 0000000..b9fc2e6 --- /dev/null +++ b/.github/scripts/build-binary.ts @@ -0,0 +1,39 @@ +// Compiles one standalone `ct` binary with Bun (called by build-binaries.sh). +// +// Ink (the `ct dupes --tui` view) imports `react-devtools-core` from a module it only +// loads when DEV=true. Bun hoists that import into the bundle, so a missing package breaks +// every binary at startup, and `--external` only moves the failure to runtime. The plugin +// swaps the package for an empty stub instead: devtools are never available in a binary. +// +// Usage: bun .github/scripts/build-binary.ts +const [target, outfile, version] = process.argv.slice(2); +if (!target || !outfile || !version) { + console.error("usage: build-binary.ts "); + process.exit(2); +} + +const result = await Bun.build({ + entrypoints: ["./src/index.ts"], + compile: { target: target as Bun.Build.Target, outfile }, + define: { __CT_VERSION__: JSON.stringify(version) }, + plugins: [ + { + name: "stub-react-devtools-core", + setup(build) { + build.onResolve({ filter: /^react-devtools-core$/ }, () => ({ + path: "react-devtools-core", + namespace: "ct-stub", + })); + build.onLoad({ filter: /.*/, namespace: "ct-stub" }, () => ({ + contents: "export default { initialize() {}, connectToDevTools() {} };", + loader: "js", + })); + }, + }, + ], +}); + +if (!result.success) { + for (const log of result.logs) console.error(log); + process.exit(1); +}