From 30ff9294277f904002650eada957fac16ab1c730 Mon Sep 17 00:00:00 2001 From: Simon Davies Date: Mon, 23 Mar 2026 21:55:39 +0000 Subject: [PATCH] fix: resolve symlinks in launcher script for npm global install MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The shell launcher used ${0%/*} to find its lib/ directory, but when npm installs globally it creates a symlink in the bin dir. ${0%/*} resolves to the npm bin dir, not the package dir, causing: Cannot find module '.../lib/hyperagent-launcher.cjs' Use readlink -f / realpath to resolve symlinks before computing the relative path to the lib directory. Tested: symlink from /tmp/ → prints version correctly; old approach confirmed to fail with MODULE_NOT_FOUND. Signed-off-by: Simon Davies --- scripts/build-binary.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scripts/build-binary.js b/scripts/build-binary.js index d9cc71b..f59c897 100644 --- a/scripts/build-binary.js +++ b/scripts/build-binary.js @@ -318,7 +318,13 @@ console.log("📝 Creating launcher..."); // We use a shell wrapper that invokes node with explicit CommonJS treatment const launcher = `#!/bin/sh # HyperAgent Launcher - resolves native addons from lib/ directory -exec node --no-warnings "\${0%/*}/../lib/hyperagent-launcher.cjs" "$@" +# When invoked via PATH, $0 may be a bare name (no slash). Resolve it first. +SELF="$0" +case "$SELF" in */*) ;; *) SELF="$(command -v -- "$SELF")" ;; esac +# Resolve symlinks so this works when npm links the bin globally +SELF="$(readlink -f "$SELF" 2>/dev/null || realpath "$SELF" 2>/dev/null || echo "$SELF")" +SCRIPT_DIR="$(cd "$(dirname "$SELF")" && pwd)" +exec node --no-warnings "\${SCRIPT_DIR}/../lib/hyperagent-launcher.cjs" "$@" `; // The actual launcher logic in CommonJS