From b2986744faa41db549696cfbe1a4587e75b9ebd4 Mon Sep 17 00:00:00 2001 From: Saravana Achu Mac Date: Sat, 14 Feb 2026 12:55:41 -0800 Subject: [PATCH] chore(husky): run hooks from repo root and avoid npx --- .husky/pre-commit | 11 ++++++++++- .husky/pre-push | 9 +++++++++ scripts/setup-husky.sh | 20 +++++++++++++++++++- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index 83204b25..2a282f26 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,5 +1,14 @@ #!/usr/bin/env sh +# Ensure hooks run from repo root (we intentionally do not source Husky internals). +ROOT="$(git rev-parse --show-toplevel 2>/dev/null)" +if [ -n "$ROOT" ]; then + cd "$ROOT" || exit 1 +fi + +# Prefer local binaries (prettier/lint-staged/etc.) +export PATH="$PWD/node_modules/.bin:$PATH" + # Check if Husky is disabled via environment variable if [ "$HUSKY_ENABLED" = "false" ]; then echo "⚠️ Husky disabled via HUSKY_ENABLED=false" @@ -13,4 +22,4 @@ bash scripts/secret-scan-staged.sh echo "🐶 Running pre-commit hooks for common platform..." # Run lint-staged on staged files -npx lint-staged +pnpm exec lint-staged diff --git a/.husky/pre-push b/.husky/pre-push index b73d55a3..a93388cd 100755 --- a/.husky/pre-push +++ b/.husky/pre-push @@ -1,5 +1,14 @@ #!/usr/bin/env sh +# Ensure hooks run from repo root (we intentionally do not source Husky internals). +ROOT="$(git rev-parse --show-toplevel 2>/dev/null)" +if [ -n "$ROOT" ]; then + cd "$ROOT" || exit 1 +fi + +# Prefer local binaries (if needed in future). +export PATH="$PWD/node_modules/.bin:$PATH" + # Check if Husky is disabled via environment variable if [ "$HUSKY_ENABLED" = "false" ]; then echo "⚠️ Husky disabled via HUSKY_ENABLED=false" diff --git a/scripts/setup-husky.sh b/scripts/setup-husky.sh index 4ef0ba6c..e1420954 100755 --- a/scripts/setup-husky.sh +++ b/scripts/setup-husky.sh @@ -14,6 +14,15 @@ mkdir -p .husky cat > .husky/pre-commit << 'EOF' #!/usr/bin/env sh +# Ensure hooks run from repo root (we intentionally do not source Husky internals). +ROOT="$(git rev-parse --show-toplevel 2>/dev/null)" +if [ -n "$ROOT" ]; then + cd "$ROOT" || exit 1 +fi + +# Prefer local binaries (prettier/lint-staged/etc.) +export PATH="$PWD/node_modules/.bin:$PATH" + # Check if Husky is disabled via environment variable if [ "$HUSKY_ENABLED" = "false" ]; then echo "⚠️ Husky disabled via HUSKY_ENABLED=false" @@ -27,13 +36,22 @@ bash scripts/secret-scan-staged.sh echo "🐶 Running pre-commit hooks for common platform..." # Run lint-staged on staged files -npx lint-staged +pnpm exec lint-staged EOF # Create pre-push hook with HUSKY_ENABLED flag cat > .husky/pre-push << 'EOF' #!/usr/bin/env sh +# Ensure hooks run from repo root (we intentionally do not source Husky internals). +ROOT="$(git rev-parse --show-toplevel 2>/dev/null)" +if [ -n "$ROOT" ]; then + cd "$ROOT" || exit 1 +fi + +# Prefer local binaries (if needed in future). +export PATH="$PWD/node_modules/.bin:$PATH" + # Check if Husky is disabled via environment variable if [ "$HUSKY_ENABLED" = "false" ]; then echo "⚠️ Husky disabled via HUSKY_ENABLED=false"