Skip to content

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