File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -422,16 +422,26 @@ set -e
422422
423423# Resolve the installation directory
424424# Handle both direct execution and symlinked scenarios
425- if [ -L "$0" ]; then
426- # Follow symlink
427- SCRIPT_PATH="$(readlink -f "$0" 2>/dev/null || readlink "$0" 2>/dev/null || echo "$0")"
428- else
429- SCRIPT_PATH="$0"
430- fi
425+ # Uses portable shell built-ins instead of GNU-specific readlink -f and realpath
426+ # Ignores inherited CDPATH, then resolves the script directory and its parent path
427+ SCRIPT_DIR="$(
428+ CDPATH=
429+ self=$0
430+
431+ # follow the symlink chain one hop at a time so relative targets resolve correctly
432+ while [ -L "$self" ]; do
433+ cd -- "${self%/*}" >/dev/null || :
434+ self=$(readlink "${self##*/}")
435+ done
436+
437+ case "$self" in
438+ (*/*) ;;
439+ (*) self=./$self ;;
440+ esac
431441
432- # Get absolute path to script directory
433- SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_PATH")" && pwd )"
434- INSTALL_DIR="$(dirname "$SCRIPT_DIR")"
442+ cd -P -- "${self%/*}" >/dev/null && pwd
443+ )"
444+ INSTALL_DIR="$(dirname -- "$SCRIPT_DIR")"
435445
436446# Paths to bundled components
437447NODE_BIN="$INSTALL_DIR/node/current/bin/node"
Original file line number Diff line number Diff line change @@ -592,6 +592,8 @@ test_wrapper_missing_cli
592592printf ' \n'
593593test_wrapper_via_symlink
594594printf ' \n'
595+ test_wrapper_via_relative_symlink
596+ printf ' \n'
595597test_path_with_spaces
596598printf ' \n'
597599test_version_equals_form
You can’t perform that action at this time.
0 commit comments