From d8fb2f91759201f2a389e67084c6faa8ded6c886 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 9 Dec 2025 17:36:24 +0000 Subject: [PATCH] chore(mac): make package/restart skip ts relay --- scripts/package-mac-app.sh | 110 ++++++++++++++++++++----------------- scripts/restart-mac.sh | 33 +++++++++-- 2 files changed, 87 insertions(+), 56 deletions(-) diff --git a/scripts/package-mac-app.sh b/scripts/package-mac-app.sh index f4094c3d8..7577337de 100755 --- a/scripts/package-mac-app.sh +++ b/scripts/package-mac-app.sh @@ -25,8 +25,12 @@ fi echo "📦 Ensuring deps (pnpm install)" (cd "$ROOT_DIR" && pnpm install --no-frozen-lockfile --config.node-linker=hoisted) -echo "📦 Building JS (pnpm exec tsc)" -(cd "$ROOT_DIR" && pnpm exec tsc -p tsconfig.json) +if [[ "${SKIP_TSC:-0}" != "1" ]]; then + echo "📦 Building JS (pnpm exec tsc)" + (cd "$ROOT_DIR" && pnpm exec tsc -p tsconfig.json) +else + echo "📦 Skipping TS build (SKIP_TSC=1)" +fi cd "$ROOT_DIR/apps/macos" @@ -114,57 +118,61 @@ rm -rf "$APP_ROOT/Contents/Resources/WebChat/vendor/pdfjs-dist/legacy" RELAY_DIR="$APP_ROOT/Contents/Resources/Relay" -echo "🧰 Staging relay payload (dist + node_modules; expects system Node ≥22)" -rsync -a --delete --exclude "Clawdis.app" "$ROOT_DIR/dist/" "$RELAY_DIR/dist/" -cp "$ROOT_DIR/package.json" "$RELAY_DIR/" -cp "$ROOT_DIR/pnpm-lock.yaml" "$RELAY_DIR/" -if [ -f "$ROOT_DIR/.npmrc" ]; then - cp "$ROOT_DIR/.npmrc" "$RELAY_DIR/" +if [[ "${SKIP_RELAY_PACKAGE:-0}" != "1" ]]; then + echo "🧰 Staging relay payload (dist + node_modules; expects system Node ≥22)" + rsync -a --delete --exclude "Clawdis.app" "$ROOT_DIR/dist/" "$RELAY_DIR/dist/" + cp "$ROOT_DIR/package.json" "$RELAY_DIR/" + cp "$ROOT_DIR/pnpm-lock.yaml" "$RELAY_DIR/" + if [ -f "$ROOT_DIR/.npmrc" ]; then + cp "$ROOT_DIR/.npmrc" "$RELAY_DIR/" + fi + + echo "📦 Installing prod node_modules into bundle via temp project" + TMP_DEPLOY=$(mktemp -d /tmp/clawdis-deps.XXXXXX) + cp "$ROOT_DIR/package.json" "$TMP_DEPLOY/" + cp "$ROOT_DIR/pnpm-lock.yaml" "$TMP_DEPLOY/" + [ -f "$ROOT_DIR/.npmrc" ] && cp "$ROOT_DIR/.npmrc" "$TMP_DEPLOY/" + PNPM_STORE_DIR="$TMP_DEPLOY/.pnpm-store" \ + PNPM_HOME="$HOME/Library/pnpm" \ + pnpm install \ + --prod \ + --force \ + --no-frozen-lockfile \ + --ignore-scripts=false \ + --config.enable-pre-post-scripts=true \ + --config.ignore-workspace-root-check=true \ + --config.shared-workspace-lockfile=false \ + --config.node-linker=hoisted \ + --lockfile-dir "$TMP_DEPLOY" \ + --dir "$TMP_DEPLOY" + PNPM_STORE_DIR="$TMP_DEPLOY/.pnpm-store" \ + PNPM_HOME="$HOME/Library/pnpm" \ + pnpm rebuild sharp --config.ignore-workspace-root-check=true --dir "$TMP_DEPLOY" + rsync -a "$TMP_DEPLOY/node_modules/" "$RELAY_DIR/node_modules/" + + # Keep only the arm64 macOS sharp vendor payloads to shrink the bundle + SHARP_VENDOR_DIR="$RELAY_DIR/node_modules/@img" + if [ -d "$SHARP_VENDOR_DIR" ]; then + find "$SHARP_VENDOR_DIR" -maxdepth 1 -type d -name "sharp-*" \ + ! -name "sharp-darwin-arm64" \ + ! -name "sharp-libvips-darwin-arm64" -exec rm -rf {} + + fi + + # Prune obvious dev/build tooling to keep size down + rm -rf \ + "$RELAY_DIR/node_modules/.bin"/vite \ + "$RELAY_DIR/node_modules/.bin"/rolldown \ + "$RELAY_DIR/node_modules/.bin"/biome \ + "$RELAY_DIR/node_modules/.bin"/vitest \ + "$RELAY_DIR/node_modules/.bin"/tsc \ + "$RELAY_DIR/node_modules/.bin"/tsx 2>/dev/null || true + rm -rf \ + "$RELAY_DIR/node_modules"/{vite,rolldown,vitest,ts-node,ts-node-dev,typescript,@types,docx-preview,jszip,lucide,ollama} 2>/dev/null || true + rm -rf "$TMP_DEPLOY" +else + echo "🧰 Skipping relay payload packaging (SKIP_RELAY_PACKAGE=1)" fi -echo "📦 Installing prod node_modules into bundle via temp project" -TMP_DEPLOY=$(mktemp -d /tmp/clawdis-deps.XXXXXX) -cp "$ROOT_DIR/package.json" "$TMP_DEPLOY/" -cp "$ROOT_DIR/pnpm-lock.yaml" "$TMP_DEPLOY/" -[ -f "$ROOT_DIR/.npmrc" ] && cp "$ROOT_DIR/.npmrc" "$TMP_DEPLOY/" -PNPM_STORE_DIR="$TMP_DEPLOY/.pnpm-store" \ -PNPM_HOME="$HOME/Library/pnpm" \ -pnpm install \ - --prod \ - --force \ - --no-frozen-lockfile \ - --ignore-scripts=false \ - --config.enable-pre-post-scripts=true \ - --config.ignore-workspace-root-check=true \ - --config.shared-workspace-lockfile=false \ - --config.node-linker=hoisted \ - --lockfile-dir "$TMP_DEPLOY" \ - --dir "$TMP_DEPLOY" -PNPM_STORE_DIR="$TMP_DEPLOY/.pnpm-store" \ -PNPM_HOME="$HOME/Library/pnpm" \ -pnpm rebuild sharp --config.ignore-workspace-root-check=true --dir "$TMP_DEPLOY" -rsync -a "$TMP_DEPLOY/node_modules/" "$RELAY_DIR/node_modules/" - -# Keep only the arm64 macOS sharp vendor payloads to shrink the bundle -SHARP_VENDOR_DIR="$RELAY_DIR/node_modules/@img" -if [ -d "$SHARP_VENDOR_DIR" ]; then - find "$SHARP_VENDOR_DIR" -maxdepth 1 -type d -name "sharp-*" \ - ! -name "sharp-darwin-arm64" \ - ! -name "sharp-libvips-darwin-arm64" -exec rm -rf {} + -fi - -# Prune obvious dev/build tooling to keep size down -rm -rf \ - "$RELAY_DIR/node_modules/.bin"/vite \ - "$RELAY_DIR/node_modules/.bin"/rolldown \ - "$RELAY_DIR/node_modules/.bin"/biome \ - "$RELAY_DIR/node_modules/.bin"/vitest \ - "$RELAY_DIR/node_modules/.bin"/tsc \ - "$RELAY_DIR/node_modules/.bin"/tsx 2>/dev/null || true -rm -rf \ - "$RELAY_DIR/node_modules"/{vite,rolldown,vitest,ts-node,ts-node-dev,typescript,@types,docx-preview,jszip,lucide,ollama} 2>/dev/null || true -rm -rf "$TMP_DEPLOY" - if [ -f "$CLI_BIN" ]; then echo "🔧 Copying CLI helper" cp "$CLI_BIN" "$APP_ROOT/Contents/MacOS/ClawdisCLI" diff --git a/scripts/restart-mac.sh b/scripts/restart-mac.sh index fb6d5e867..538be6448 100755 --- a/scripts/restart-mac.sh +++ b/scripts/restart-mac.sh @@ -4,7 +4,7 @@ set -euo pipefail ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" -APP_BUNDLE="${ROOT_DIR}/dist/Clawdis.app" +APP_BUNDLE="${CLAWDIS_APP_BUNDLE:-}" APP_PROCESS_PATTERN="Clawdis.app/Contents/MacOS/Clawdis" DEBUG_PROCESS_PATTERN="${ROOT_DIR}/apps/macos/.build/debug/Clawdis" LOCAL_PROCESS_PATTERN="${ROOT_DIR}/apps/macos/.build-local/debug/Clawdis" @@ -59,13 +59,36 @@ run_step "bundle webchat" bash -lc "cd '${ROOT_DIR}' && pnpm webchat:bundle" run_step "clean build cache" bash -lc "cd '${ROOT_DIR}/apps/macos' && rm -rf .build .build-swift .swiftpm 2>/dev/null || true" run_step "swift build" bash -lc "cd '${ROOT_DIR}/apps/macos' && swift build -q --product Clawdis" -# 3) Package + relaunch the app (script also stops any stragglers). -run_step "package app" "${ROOT_DIR}/scripts/package-mac-app.sh" +# 3) Package app (skip TS + relay staging; rely on global/custom install for relay JS). +run_step "package app" bash -lc "cd '${ROOT_DIR}' && SKIP_TSC=1 SKIP_RELAY_PACKAGE=1 '${ROOT_DIR}/scripts/package-mac-app.sh'" -# 4) Launch the packaged app in the foreground so the menu bar extra appears. +choose_app_bundle() { + if [[ -n "${APP_BUNDLE}" && -d "${APP_BUNDLE}" ]]; then + return 0 + fi + + if [[ -d "/Applications/Clawdis.app" ]]; then + APP_BUNDLE="/Applications/Clawdis.app" + return 0 + fi + + if [[ -d "${ROOT_DIR}/dist/Clawdis.app" ]]; then + APP_BUNDLE="${ROOT_DIR}/dist/Clawdis.app" + if [[ ! -d "${APP_BUNDLE}/Contents/Frameworks/Sparkle.framework" ]]; then + fail "dist/Clawdis.app missing Sparkle after packaging" + fi + return 0 + fi + + fail "App bundle not found. Set CLAWDIS_APP_BUNDLE to your installed Clawdis.app" +} + +choose_app_bundle + +# 4) Launch the installed app in the foreground so the menu bar extra appears. run_step "launch app" open "${APP_BUNDLE}" -# 5) Verify the packaged app is alive. +# 5) Verify the app is alive. sleep 1.5 if pgrep -f "${APP_PROCESS_PATTERN}" >/dev/null 2>&1; then log "OK: Clawdis is running."