build(macos): bundle bun gateway

This commit is contained in:
Peter Steinberger
2025-12-19 19:20:46 +01:00
parent bb7f4abd4b
commit 98bbc73925
2 changed files with 39 additions and 46 deletions

View File

@@ -125,6 +125,9 @@ if [ -d "$APP_BUNDLE/Contents/Resources/Relay" ]; then
find "$APP_BUNDLE/Contents/Resources/Relay" -type f \( -name "*.node" -o -name "*.dylib" \) -print0 | while IFS= read -r -d '' f; do find "$APP_BUNDLE/Contents/Resources/Relay" -type f \( -name "*.node" -o -name "*.dylib" \) -print0 | while IFS= read -r -d '' f; do
echo "Signing gateway payload: $f"; sign_item "$f" "$ENT_TMP_BASE" echo "Signing gateway payload: $f"; sign_item "$f" "$ENT_TMP_BASE"
done done
if [ -f "$APP_BUNDLE/Contents/Resources/Relay/clawdis-gateway" ]; then
echo "Signing embedded gateway"; sign_item "$APP_BUNDLE/Contents/Resources/Relay/clawdis-gateway" "$ENT_TMP_BASE"
fi
fi fi
# Sign Sparkle deeply if present # Sign Sparkle deeply if present

View File

@@ -128,56 +128,46 @@ cp "$ROOT_DIR/apps/macos/Sources/Clawdis/Resources/Clawdis.icns" "$APP_ROOT/Cont
RELAY_DIR="$APP_ROOT/Contents/Resources/Relay" RELAY_DIR="$APP_ROOT/Contents/Resources/Relay"
if [[ "${SKIP_GATEWAY_PACKAGE:-0}" != "1" ]]; then if [[ "${SKIP_GATEWAY_PACKAGE:-0}" != "1" ]]; then
echo "🧰 Staging gateway payload (dist + node_modules; expects system Node ≥22)" if ! command -v bun >/dev/null 2>&1; then
rsync -a --delete --exclude "Clawdis.app" "$ROOT_DIR/dist/" "$RELAY_DIR/dist/" echo "ERROR: bun missing. Install bun to package the embedded gateway." >&2
cp "$ROOT_DIR/package.json" "$RELAY_DIR/" exit 1
cp "$ROOT_DIR/pnpm-lock.yaml" "$RELAY_DIR/"
if [ -f "$ROOT_DIR/.npmrc" ]; then
cp "$ROOT_DIR/.npmrc" "$RELAY_DIR/"
fi fi
echo "📦 Installing prod node_modules into bundle via temp project" echo "🧰 Building bundled gateway (bun --compile)"
TMP_DEPLOY=$(mktemp -d /tmp/clawdis-deps.XXXXXX) mkdir -p "$RELAY_DIR"
cp "$ROOT_DIR/package.json" "$TMP_DEPLOY/" BUN_OUT="$RELAY_DIR/clawdis-gateway"
cp "$ROOT_DIR/pnpm-lock.yaml" "$TMP_DEPLOY/" bun build "$ROOT_DIR/dist/macos/gateway-daemon.js" \
[ -f "$ROOT_DIR/.npmrc" ] && cp "$ROOT_DIR/.npmrc" "$TMP_DEPLOY/" --compile \
PNPM_STORE_DIR="$TMP_DEPLOY/.pnpm-store" \ --outfile "$BUN_OUT" \
PNPM_HOME="$HOME/Library/pnpm" \ -e playwright-core \
pnpm install \ -e electron \
--prod \ -e "chromium-bidi*" \
--force \ --define "__CLAWDIS_VERSION__=\\\"$PKG_VERSION\\\""
--no-frozen-lockfile \ chmod +x "$BUN_OUT"
--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 echo "📄 Writing embedded runtime package.json (Pi compatibility)"
SHARP_VENDOR_DIR="$RELAY_DIR/node_modules/@img" cat > "$RELAY_DIR/package.json" <<JSON
if [ -d "$SHARP_VENDOR_DIR" ]; then {
find "$SHARP_VENDOR_DIR" -maxdepth 1 -type d -name "sharp-*" \ "name": "clawdis-embedded",
! -name "sharp-darwin-arm64" \ "version": "$PKG_VERSION",
! -name "sharp-libvips-darwin-arm64" -exec rm -rf {} + "piConfig": {
"name": "pi",
"configDir": ".pi"
}
}
JSON
echo "🎨 Copying Pi theme payload (optional)"
PI_ENTRY_URL="$(cd "$ROOT_DIR" && node --input-type=module -e "console.log(import.meta.resolve('@mariozechner/pi-coding-agent'))")"
PI_ENTRY="$(cd "$ROOT_DIR" && node --input-type=module -e "console.log(new URL(process.argv[1]).pathname)" "$PI_ENTRY_URL")"
PI_DIR="$(cd "$(dirname "$PI_ENTRY")/.." && pwd)"
THEME_SRC="$PI_DIR/dist/modes/interactive/theme"
if [ -d "$THEME_SRC" ]; then
rm -rf "$RELAY_DIR/theme"
cp -R "$THEME_SRC" "$RELAY_DIR/theme"
else
echo "WARN: Pi theme dir missing at $THEME_SRC (continuing)" >&2
fi 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 else
echo "🧰 Skipping gateway payload packaging (SKIP_GATEWAY_PACKAGE=1)" echo "🧰 Skipping gateway payload packaging (SKIP_GATEWAY_PACKAGE=1)"
fi fi