Files
kandev/scripts/release/package-cli.sh
T
José Almeida ed35215818 fix(release): release-bundle bin/cli.js must require the esbuild bundle
The previous package-cli.sh copied apps/cli/bin/cli.js verbatim into the
release bundle. That file requires `../dist/cli.js` (unbundled), which
only works when node_modules is present alongside it.

In the GitHub release bundle (used by Homebrew and manual installs),
there is no node_modules — `require('tree-kill')` and `require('tar')`
inside dist/cli.js would crash at startup.

Now package-cli.sh writes a release-specific bin/cli.js that requires
`../dist/cli.bundle.js` instead. The bundled file has all Node deps
inlined via esbuild, so it runs standalone in the Cellar.

The npm package keeps its own bin/cli.js (in apps/cli/bin/) requiring
the unbundled dist/cli.js, since npm installs tree-kill etc. normally.

Caught while smoke-testing the release bundle locally with
KANDEV_BUNDLE_DIR — backend + web boot succeeded after this fix.
2026-05-04 22:44:26 +01:00

50 lines
1.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# Build the CLI and copy artifacts into dist/kandev/cli/ for inclusion in release bundles.
#
# The CLI bundle (dist/cli.bundle.js) is a single-file esbuild output with all Node
# dependencies inlined. This is required for Homebrew installs where there is no
# node_modules directory in the Cellar.
#
# Output layout inside dist/kandev/cli/:
# bin/cli.js - Node entrypoint (requires #!/usr/bin/env node shebang + chmod +x)
# dist/cli.bundle.js - Self-contained bundle with inlined deps (used by Homebrew)
# package.json - Package metadata (used to read version at runtime)
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
CLI_DIR="$ROOT_DIR/apps/cli"
OUT_DIR="$ROOT_DIR/dist/kandev/cli"
echo "Building CLI for release bundle..."
# Build TypeScript
pnpm -C "$ROOT_DIR/apps" --filter kandev build
echo " TypeScript build complete"
# Bundle with esbuild (inlines tree-kill and all other deps)
pnpm -C "$ROOT_DIR/apps/cli" bundle
echo " esbuild bundle complete"
# Copy artifacts into dist/kandev/cli/
rm -rf "$OUT_DIR"
mkdir -p "$OUT_DIR/bin" "$OUT_DIR/dist"
# Write a bin/cli.js that points at the bundled dist (for Homebrew/manual installs
# where there is no node_modules to resolve the unbundled dist/cli.js's deps).
# The npm package's bin/cli.js is different — it requires the unbundled dist/cli.js
# because tree-kill etc. are installed normally via npm.
cat > "$OUT_DIR/bin/cli.js" <<'EOF'
#!/usr/bin/env node
require("../dist/cli.bundle.js");
EOF
chmod +x "$OUT_DIR/bin/cli.js"
cp "$CLI_DIR/dist/cli.bundle.js" "$OUT_DIR/dist/cli.bundle.js"
cp "$CLI_DIR/package.json" "$OUT_DIR/package.json"
echo "CLI artifacts packaged at $OUT_DIR"
echo " bin/cli.js (entrypoint, requires dist/cli.bundle.js, chmod +x)"
echo " dist/cli.bundle.js (self-contained bundle, deps inlined)"
echo " package.json"