From 4ced2e0ef0b9e770175d69f1d1f7a51ee439bd9a Mon Sep 17 00:00:00 2001 From: jiarung Date: Fri, 13 Mar 2026 08:59:53 +0000 Subject: [PATCH] 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. --- git-hooks/pre-commit | 11 +++++++++++ scripts/pre-commit/run-node-tool.sh | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/git-hooks/pre-commit b/git-hooks/pre-commit index 948f2087ada..9650fe936eb 100755 --- a/git-hooks/pre-commit +++ b/git-hooks/pre-commit @@ -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" diff --git a/scripts/pre-commit/run-node-tool.sh b/scripts/pre-commit/run-node-tool.sh index 34163075517..69a26f45e0e 100755 --- a/scripts/pre-commit/run-node-tool.sh +++ b/scripts/pre-commit/run-node-tool.sh @@ -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 [args...]" >&2 exit 2