fix(git-hooks): resolve node binary for nvm environments
When git hooks run, the shell profile is not sourced so nvm-managed Node installations are not in PATH. This caused 'node: command not found' errors on every commit for users relying on nvm. Add a PATH-extension fallback in both pre-commit and run-node-tool.sh that walks ~/.nvm/versions/node/*/bin/node and prepends the first found binary to PATH, mirroring how nvm itself resolves the runtime.
This commit is contained in:
parent
feefa8568f
commit
4ced2e0ef0
@ -2,6 +2,17 @@
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Resolve node when not in PATH (e.g. nvm environments where shell profile
|
||||
# hasn't been sourced by the git hook). Picks the highest nvm version found.
|
||||
if ! command -v node >/dev/null 2>&1; then
|
||||
for _nvm_node in "$HOME/.nvm/versions/node"/*/bin/node; do
|
||||
if [[ -x "$_nvm_node" ]]; then
|
||||
export PATH="$(dirname "$_nvm_node"):$PATH"
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
ROOT_DIR="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
|
||||
RUN_NODE_TOOL="$ROOT_DIR/scripts/pre-commit/run-node-tool.sh"
|
||||
FILTER_FILES="$ROOT_DIR/scripts/pre-commit/filter-staged-files.mjs"
|
||||
|
||||
@ -3,6 +3,16 @@ set -euo pipefail
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||||
|
||||
# Resolve node when not in PATH (nvm environments).
|
||||
if ! command -v node >/dev/null 2>&1; then
|
||||
for _nvm_node in "$HOME/.nvm/versions/node"/*/bin/node; do
|
||||
if [[ -x "$_nvm_node" ]]; then
|
||||
export PATH="$(dirname "$_nvm_node"):$PATH"
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ $# -lt 1 ]]; then
|
||||
echo "usage: run-node-tool.sh <tool> [args...]" >&2
|
||||
exit 2
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user