Skip to content

Commit 08045de

Browse files
committed
refactor: improve postinstall platform detection
Detect bundled prebuilds to avoid unnecessary downloads on Linux: - Linux: Prebuilds are bundled in npm package (prebuilds/linux-*) Script detects these and skips download entirely - macOS/Windows: No bundled prebuilds, downloads to build/Release/ Script downloads from GitHub releases as before Benefits: - Zero network calls on Linux VMs (instant postinstall) - Covers 15+ Node.js ABI versions for Linux out of box - Platform/arch detection matches node conventions (x86_64->x64, etc) - Clear messaging shows which path was taken This ensures remote Linux VMs running server mode aren't blocked by unnecessary downloads or network issues.
1 parent 3c69a54 commit 08045de

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

scripts/postinstall.sh

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,31 @@ if [ -d "node_modules/@homebridge/node-pty-prebuilt-multiarch" ]; then
3131
echo -e "${GREEN}Installing node-pty prebuilds...${NC}"
3232
cd node_modules/@homebridge/node-pty-prebuilt-multiarch
3333

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}"
34+
# Check if prebuilds are already available (bundled with package or previously downloaded)
35+
# The package looks for binaries in two locations:
36+
# 1. prebuilds/<platform>-<arch>/node.abi*.node (bundled for Linux in npm package)
37+
# 2. build/Release/pty.node (downloaded via prebuild-install for macOS/Windows)
38+
39+
PLATFORM=$(uname -s | tr '[:upper:]' '[:lower:]')
40+
ARCH=$(uname -m)
41+
42+
# Normalize arch names to match node conventions
43+
case "$ARCH" in
44+
x86_64) ARCH="x64" ;;
45+
aarch64) ARCH="arm64" ;;
46+
armv7l) ARCH="arm" ;;
47+
i686) ARCH="ia32" ;;
48+
esac
49+
50+
# Check if bundled prebuilds exist (Linux has these in the npm package)
51+
if ls prebuilds/${PLATFORM}-${ARCH}/*.node > /dev/null 2>&1; then
52+
echo -e "${GREEN}✓ node-pty prebuilds bundled with package (prebuilds/${PLATFORM}-${ARCH})${NC}"
53+
elif [ -f "build/Release/pty.node" ]; then
54+
# Downloaded prebuild already exists
55+
echo -e "${GREEN}✓ node-pty prebuild already downloaded (build/Release/pty.node)${NC}"
3856
else
39-
echo -e "${YELLOW}Downloading node-pty prebuilds...${NC}"
57+
# Need to download prebuilds (macOS/Windows don't ship with bundled binaries)
58+
echo -e "${YELLOW}Downloading node-pty prebuilds for ${PLATFORM}-${ARCH}...${NC}"
4059
# Run prebuild-install (may crash with bun, but still downloads the binary)
4160
$NODE_BIN ../../prebuild-install/bin.js --verbose > /tmp/node-pty-install.log 2>&1 || true
4261

0 commit comments

Comments
 (0)