chore(husky): run hooks from repo root and avoid npx
This commit is contained in:
parent
468a6c6072
commit
b2986744fa
@ -1,5 +1,14 @@
|
|||||||
#!/usr/bin/env sh
|
#!/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
|
# Check if Husky is disabled via environment variable
|
||||||
if [ "$HUSKY_ENABLED" = "false" ]; then
|
if [ "$HUSKY_ENABLED" = "false" ]; then
|
||||||
echo "⚠️ Husky disabled via HUSKY_ENABLED=false"
|
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..."
|
echo "🐶 Running pre-commit hooks for common platform..."
|
||||||
|
|
||||||
# Run lint-staged on staged files
|
# Run lint-staged on staged files
|
||||||
npx lint-staged
|
pnpm exec lint-staged
|
||||||
|
|||||||
@ -1,5 +1,14 @@
|
|||||||
#!/usr/bin/env sh
|
#!/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
|
# Check if Husky is disabled via environment variable
|
||||||
if [ "$HUSKY_ENABLED" = "false" ]; then
|
if [ "$HUSKY_ENABLED" = "false" ]; then
|
||||||
echo "⚠️ Husky disabled via HUSKY_ENABLED=false"
|
echo "⚠️ Husky disabled via HUSKY_ENABLED=false"
|
||||||
|
|||||||
@ -14,6 +14,15 @@ mkdir -p .husky
|
|||||||
cat > .husky/pre-commit << 'EOF'
|
cat > .husky/pre-commit << 'EOF'
|
||||||
#!/usr/bin/env sh
|
#!/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
|
# Check if Husky is disabled via environment variable
|
||||||
if [ "$HUSKY_ENABLED" = "false" ]; then
|
if [ "$HUSKY_ENABLED" = "false" ]; then
|
||||||
echo "⚠️ Husky disabled via HUSKY_ENABLED=false"
|
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..."
|
echo "🐶 Running pre-commit hooks for common platform..."
|
||||||
|
|
||||||
# Run lint-staged on staged files
|
# Run lint-staged on staged files
|
||||||
npx lint-staged
|
pnpm exec lint-staged
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Create pre-push hook with HUSKY_ENABLED flag
|
# Create pre-push hook with HUSKY_ENABLED flag
|
||||||
cat > .husky/pre-push << 'EOF'
|
cat > .husky/pre-push << 'EOF'
|
||||||
#!/usr/bin/env sh
|
#!/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
|
# Check if Husky is disabled via environment variable
|
||||||
if [ "$HUSKY_ENABLED" = "false" ]; then
|
if [ "$HUSKY_ENABLED" = "false" ]; then
|
||||||
echo "⚠️ Husky disabled via HUSKY_ENABLED=false"
|
echo "⚠️ Husky disabled via HUSKY_ENABLED=false"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user