fix: fall back to source-mode install when bundled build fails (#707)

bun 1.3.8 in Termux proot cannot resolve packages with --packages bundle
even with bun.lock present and after --force reinstall. When the bundled
build fails, install source + node_modules to ~/.spawn/ and create a
wrapper script that runs via `bun` directly.

Co-authored-by: Sprite <noreply@sprite.dev>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
L 2026-02-12 12:13:19 -08:00 committed by GitHub
parent ac1f8239c8
commit db72074e0a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 5 deletions

View file

@ -163,16 +163,39 @@ build_and_install() {
cd "${tmpdir}/cli"
bun install
if ! bun run build; then
local build_ok=0
if bun run build 2>/dev/null; then
build_ok=1
else
log_warn "Build failed, retrying with forced reinstall..."
bun install --force
bun run build
if bun run build 2>/dev/null; then
build_ok=1
fi
fi
INSTALL_DIR="$(find_install_dir)"
mkdir -p "${INSTALL_DIR}"
cp cli.js "${INSTALL_DIR}/spawn"
chmod +x "${INSTALL_DIR}/spawn"
if [ "$build_ok" = "1" ]; then
cp cli.js "${INSTALL_DIR}/spawn"
chmod +x "${INSTALL_DIR}/spawn"
else
# Bundled build failed — fall back to source mode.
# Install source + node_modules to ~/.spawn/ and create a wrapper.
log_warn "Bundled build unavailable, installing from source..."
local spawn_lib="${HOME}/.spawn"
rm -rf "${spawn_lib}"
mkdir -p "${spawn_lib}"
cp -r node_modules src package.json "${spawn_lib}/"
cat > "${INSTALL_DIR}/spawn" <<'WRAPPER'
#!/usr/bin/env bash
exec bun "$HOME/.spawn/src/index.ts" "$@"
WRAPPER
chmod +x "${INSTALL_DIR}/spawn"
fi
log_info "Installed spawn to ${INSTALL_DIR}/spawn"
ensure_in_path "${INSTALL_DIR}"
}

View file

@ -1,6 +1,6 @@
{
"name": "@openrouter/spawn",
"version": "0.2.60",
"version": "0.2.61",
"type": "module",
"bin": {
"spawn": "cli.js"