Skip to content

fix: update husky pre-commit to use bash and remove deprecated lines #752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sreecharan-desu
Copy link

Fix Husky Pre-Commit Hook

Overview

Fixes .husky/pre-commit syntax error, removes deprecated lines, and enforces lockfile validation for Husky v10.0.0.

Issues

  1. Bash array syntax error in POSIX shell.
  2. Deprecated Husky lines breaking in v10.0.0.
  3. Invalid lockfiles blocking commits.

Fixes

  1. Changed to #!/bin/bash.
  2. Removed legacy Husky lines.
  3. Added grep -E lockfile check:
    #!/bin/bash
    if git diff --cached --name-only | grep -E '^(package-lock\.json|pnpm-lock\.yaml|bun\.lockb)$'; then
      echo "Error: Only 'yarn.lock' allowed. Remove other lockfiles."
      exit 1
    fi

Testing

  • Valid commits pass.
  • Invalid lockfiles blocked.
  • yarn.lock commits work.
  • Script runs without errors.

Verification

  1. Commit test file: echo "test" > test.txt && git add test.txt && git commit.
  2. Try invalid lockfile: echo "{}" > package-lock.json && git add package-lock.json && git commit.
  3. Test yarn.lock; verify success.
  4. Run .husky/pre-commit manually.

Screenshot

Blocked commit for package-lock.json:
Screenshot

Notes

  • CLI/Prisma fix in separate PR.
  • Ensure .husky/ configured for core.hooksPath.

Thanks for reviewing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant