fix: resolve symlinks in install.sh for npm/bun bin usage

When installed via `npm install ecc-universal`, the `ecc-install` bin
entry creates a symlink from the package manager's bin directory to
install.sh. The old `$(dirname "$0")` resolved to the bin directory
instead of the actual package directory, causing `cp` to fail with
"cannot stat '.../rules/common/.'".

Now follows the symlink chain with readlink before resolving SCRIPT_DIR.

Fixes #199
This commit is contained in:
Affaan Mustafa
2026-02-12 16:12:21 -08:00
parent 492c99ac24
commit d9d0d3c444

View File

@@ -22,7 +22,15 @@
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
# Resolve symlinks — needed when invoked as `ecc-install` via npm/bun bin symlink
SCRIPT_PATH="$0"
while [ -L "$SCRIPT_PATH" ]; do
link_dir="$(cd "$(dirname "$SCRIPT_PATH")" && pwd)"
SCRIPT_PATH="$(readlink "$SCRIPT_PATH")"
# Resolve relative symlinks
[[ "$SCRIPT_PATH" != /* ]] && SCRIPT_PATH="$link_dir/$SCRIPT_PATH"
done
SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_PATH")" && pwd)"
RULES_DIR="$SCRIPT_DIR/rules"
# --- Parse --target flag ---