Skip to content

Commit bf3c5da

Browse files
committed
better postinstall script
1 parent 6f5cfde commit bf3c5da

File tree

3 files changed

+50
-38
lines changed

3 files changed

+50
-38
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"storybook": "make storybook",
4343
"storybook:build": "make storybook-build",
4444
"test:storybook": "make test-storybook",
45-
"postinstall": "node scripts/postinstall.js"
45+
"postinstall": "sh scripts/postinstall.sh"
4646
},
4747
"dependencies": {
4848
"@ai-sdk/anthropic": "^2.0.44",
@@ -222,6 +222,7 @@
222222
"icon": "build/icon.png",
223223
"artifactName": "${productName}-${version}-${arch}.${ext}"
224224
},
225-
"npmRebuild": false
225+
"npmRebuild": true,
226+
"buildDependenciesFromSource": false
226227
}
227228
}

scripts/postinstall.js

Lines changed: 0 additions & 36 deletions
This file was deleted.

scripts/postinstall.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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

Comments
 (0)