Skip to content

Commit 3c69a54

Browse files
committed
feat: automate node-pty prebuild installation
Add postinstall script that automatically downloads node-pty prebuilt binaries after bun install. This eliminates the manual step developers previously had to run. Why this is needed: - Bun blocks npm postinstall scripts by default for security - node-pty requires native .node binaries compiled for specific ABIs - Without prebuilds, terminals don't work in packaged Electron app How it works: - scripts/postinstall.sh runs after bun install (via Makefile) - Detects node or bun in PATH (with fallback to common locations) - Runs prebuild-install to download binaries from GitHub releases - Checks for build/Release/pty.node to verify success - Gracefully degrades if download fails (build continues) Benefits: - No manual steps for developers after git pull + bun install - Works with bun, node, or npm as package manager - Caches downloads in ~/.npm/_prebuilds for faster reinstalls - Clear error messages if manual intervention needed
1 parent 803a256 commit 3c69a54

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ all: build
9090
node_modules/.installed: package.json bun.lock
9191
@echo "Dependencies out of date or missing, running bun install..."
9292
@bun install
93+
@echo "Running postinstall scripts..."
94+
@./scripts/postinstall.sh
9395
@touch node_modules/.installed
9496

9597
# Legacy target for backwards compatibility

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"access": "public"
1717
},
1818
"scripts": {
19+
"postinstall": "./scripts/postinstall.sh",
1920
"dev": "make dev",
2021
"prebuild:main": "./scripts/generate-version.sh",
2122
"build": "make build",

scripts/postinstall.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env bash
2+
# Postinstall script to handle native module prebuilds
3+
# Bun blocks postinstall scripts by default, so we need to manually trigger them
4+
set -euo pipefail
5+
6+
# Find node-compatible runtime (prefer node, fallback to bun)
7+
if command -v node &> /dev/null; then
8+
NODE_BIN="node"
9+
elif command -v bun &> /dev/null; then
10+
NODE_BIN="bun"
11+
elif [ -f "/usr/local/bin/bun" ]; then
12+
NODE_BIN="/usr/local/bin/bun"
13+
elif [ -f "$HOME/.bun/bin/bun" ]; then
14+
NODE_BIN="$HOME/.bun/bin/bun"
15+
else
16+
echo "Error: Neither node nor bun found in PATH"
17+
exit 1
18+
fi
19+
20+
# Color output for better visibility
21+
RED='\033[0;31m'
22+
GREEN='\033[0;32m'
23+
YELLOW='\033[1;33m'
24+
NC='\033[0m' # No Color
25+
26+
echo "Running postinstall tasks..."
27+
28+
# Install node-pty prebuilds
29+
# The package has an install script that downloads prebuilt binaries from GitHub
30+
if [ -d "node_modules/@homebridge/node-pty-prebuilt-multiarch" ]; then
31+
echo -e "${GREEN}Installing node-pty prebuilds...${NC}"
32+
cd node_modules/@homebridge/node-pty-prebuilt-multiarch
33+
34+
# Run the install script using prebuild-install (downloads prebuilts from GitHub)
35+
# Check if already installed first
36+
if [ -f "build/Release/pty.node" ]; then
37+
echo -e "${GREEN}✓ node-pty prebuild already exists (build/Release/pty.node)${NC}"
38+
else
39+
echo -e "${YELLOW}Downloading node-pty prebuilds...${NC}"
40+
# Run prebuild-install (may crash with bun, but still downloads the binary)
41+
$NODE_BIN ../../prebuild-install/bin.js --verbose > /tmp/node-pty-install.log 2>&1 || true
42+
43+
# Check if the binary was actually installed
44+
if [ -f "build/Release/pty.node" ]; then
45+
echo -e "${GREEN}✓ node-pty prebuilds downloaded successfully${NC}"
46+
else
47+
echo -e "${YELLOW}⚠ Failed to install node-pty prebuilds${NC}"
48+
echo -e "${YELLOW}Terminals may not work in packaged Electron app${NC}"
49+
echo -e "${YELLOW}To fix manually, run:${NC}"
50+
echo -e "${YELLOW} cd node_modules/@homebridge/node-pty-prebuilt-multiarch${NC}"
51+
echo -e "${YELLOW} node ../../prebuild-install/bin.js --verbose${NC}"
52+
# Don't exit 1 - let the build continue, terminals will just be degraded
53+
fi
54+
fi
55+
56+
cd ../..
57+
else
58+
echo -e "${YELLOW}Warning: @homebridge/node-pty-prebuilt-multiarch not found in node_modules${NC}"
59+
echo -e "${YELLOW}Run 'bun install' first${NC}"
60+
exit 1
61+
fi
62+
63+
echo -e "${GREEN}Postinstall completed successfully${NC}"

0 commit comments

Comments
 (0)