Skip to content

Commit 30ff929

Browse files
committed
fix: resolve symlinks in launcher script for npm global install
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 <simongdavies@users.noreply.github.com>
1 parent 8cdb5c7 commit 30ff929

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

scripts/build-binary.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,13 @@ console.log("📝 Creating launcher...");
318318
// We use a shell wrapper that invokes node with explicit CommonJS treatment
319319
const launcher = `#!/bin/sh
320320
# HyperAgent Launcher - resolves native addons from lib/ directory
321-
exec node --no-warnings "\${0%/*}/../lib/hyperagent-launcher.cjs" "$@"
321+
# When invoked via PATH, $0 may be a bare name (no slash). Resolve it first.
322+
SELF="$0"
323+
case "$SELF" in */*) ;; *) SELF="$(command -v -- "$SELF")" ;; esac
324+
# Resolve symlinks so this works when npm links the bin globally
325+
SELF="$(readlink -f "$SELF" 2>/dev/null || realpath "$SELF" 2>/dev/null || echo "$SELF")"
326+
SCRIPT_DIR="$(cd "$(dirname "$SELF")" && pwd)"
327+
exec node --no-warnings "\${SCRIPT_DIR}/../lib/hyperagent-launcher.cjs" "$@"
322328
`;
323329

324330
// The actual launcher logic in CommonJS

0 commit comments

Comments
 (0)