|
| 1 | +#!/usr/bin/env sh |
| 2 | +# Conditional postinstall script for node-pty |
| 3 | +# |
| 4 | +# Compatible with all environments (no node/bun required). |
| 5 | +# |
| 6 | +# Desktop mode (Electron present): |
| 7 | +# - Rebuilds node-pty for Electron's ABI |
| 8 | +# |
| 9 | +# Server mode (no Electron): |
| 10 | +# - Uses Node.js/Bun prebuilt binaries (no rebuild needed) |
| 11 | + |
| 12 | +set -euo pipefail |
| 13 | + |
| 14 | +# Get script directory (works in both sh and bash) |
| 15 | +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
| 16 | +PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" |
| 17 | +ELECTRON_PATH="$PROJECT_ROOT/node_modules/electron" |
| 18 | + |
| 19 | +if [ -d "$ELECTRON_PATH" ]; then |
| 20 | + echo "🔧 Electron detected - rebuilding node-pty for Electron..." |
| 21 | + |
| 22 | + # Try npx first, fallback to bunx |
| 23 | + if command -v npx >/dev/null 2>&1; then |
| 24 | + npx @electron/rebuild -f -m node_modules/node-pty || { |
| 25 | + echo "⚠️ Failed to rebuild native modules" |
| 26 | + echo " Terminal functionality may not work in desktop mode." |
| 27 | + echo " Run 'make rebuild-native' manually to fix." |
| 28 | + exit 0 |
| 29 | + } |
| 30 | + elif command -v bunx >/dev/null 2>&1; then |
| 31 | + bunx @electron/rebuild -f -m node_modules/node-pty || { |
| 32 | + echo "⚠️ Failed to rebuild native modules" |
| 33 | + echo " Terminal functionality may not work in desktop mode." |
| 34 | + echo " Run 'make rebuild-native' manually to fix." |
| 35 | + exit 0 |
| 36 | + } |
| 37 | + else |
| 38 | + echo "⚠️ Neither npx nor bunx found - cannot rebuild native modules" |
| 39 | + echo " Terminal functionality may not work in desktop mode." |
| 40 | + echo " Run 'make rebuild-native' manually to fix." |
| 41 | + exit 0 |
| 42 | + fi |
| 43 | + |
| 44 | + echo "✅ Native modules rebuilt successfully" |
| 45 | +else |
| 46 | + echo "🌐 Server mode detected - using prebuilt binaries" |
| 47 | +fi |
0 commit comments