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
11 changes: 4 additions & 7 deletions .github/scripts/build-binaries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
39 changes: 39 additions & 0 deletions .github/scripts/build-binary.ts
Original file line number Diff line number Diff line change
@@ -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 <bun-target> <outfile> <version>
const [target, outfile, version] = process.argv.slice(2);
if (!target || !outfile || !version) {
console.error("usage: build-binary.ts <bun-target> <outfile> <version>");
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);
}
Loading