fix(desktop): build 脚本加 fresh-build 保险,避免 sidecar 缓存复用

修 src/ 后 build 出来的 .app 里 sidecar 还是旧代码的诡异问题 ——
Bun.build/Tauri bundler 某层缓存把 desktop/src-tauri/binaries/ 里的
旧 sidecar binary 复用进了新 .app,即便删掉 .app 也救不回来,因为
binary 源目录不在 .app 里。

加 3 道保险:
- 硬删 sidecar 源 binary + Tauri bundle + 前端 dist 目录
- 显式跑 bun run build + bun run build:sidecars(set -e 会捕获失败)
- tauri build 用 --config 覆盖 beforeBuildCommand 为 no-op,避免
  build:sidecars 被重复执行浪费 ~10s

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
程序员阿江(Relakkes) 2026-04-16 20:40:46 +08:00
parent ec3be47108
commit bea8153d17

View File

@ -61,6 +61,30 @@ if [[ "${SKIP_INSTALL:-0}" != "1" ]]; then
(cd "${DESKTOP_DIR}" && bun install)
fi
# ── 清理 + 显式预热前端 / sidecar ────────────────────────────
# 之前遇到过"改了 src/ 代码,build 的 .app 里 sidecar 还是旧的"的诡异
# case —— 根因是 Bun.build / Tauri bundler 某一层的缓存把旧 sidecar
# binary 复用进了新 .app(.app 被删干净了也救不回来,因为 binary 源在
# desktop/src-tauri/binaries/)。
#
# 这里做三件事强制 fresh build:
# 1) 硬删 sidecar 源 binary + Tauri bundle 目录 + 前端 dist
# 2) 显式跑 bun run build + bun run build:sidecars
# 3) tauri build 用 --config 覆盖 beforeBuildCommand 为 true(no-op),
# 避免 sidecar 被重复编译浪费 ~10s
# 任一步失败,整个脚本立即退出(set -e)。
echo "[build-macos-arm64] Cleaning stale sidecar binaries and bundle output..."
rm -rf "${DESKTOP_DIR}/src-tauri/binaries/claude-sidecar-"*
rm -rf "${DESKTOP_DIR}/src-tauri/target/${TARGET_TRIPLE}/release/bundle"
rm -rf "${DESKTOP_DIR}/src-tauri/target/release/bundle"
rm -rf "${DESKTOP_DIR}/dist"
echo "[build-macos-arm64] Rebuilding frontend (tsc + vite)..."
(cd "${DESKTOP_DIR}" && bun run build)
echo "[build-macos-arm64] Rebuilding sidecar for ${TARGET_TRIPLE}..."
(cd "${DESKTOP_DIR}" && TAURI_ENV_TARGET_TRIPLE="${TARGET_TRIPLE}" bun run build:sidecars)
TAURI_ARGS=(
bunx
tauri
@ -70,6 +94,8 @@ TAURI_ARGS=(
--bundles
app,dmg
--ci
--config
'{"build":{"beforeBuildCommand":"true"}}'
)
if [[ "${SIGN_BUILD:-0}" != "1" ]]; then