Skip to content

Replace pre-commit with husky

Compare
Choose a tag to compare
@forabi forabi released this 16 Feb 20:28
· 14 commits to master since this release
347dd51
Replace pre-commit with husky (#7)

While working on hollowverse/hollowverse#295 I removed husky from dependencies because git was getting stuck every time I commited or pushed something (hollowverse/hollowverse#297).  I made sure that I removed all possibly leftover git hooks but the issue persisted. Looking at the `.git/hooks` directory, it seems that every time I added or removed an npm package, yarn was re-installing a `pre-commit` git hook. It turns out that the culprit was `pre-commit`. Running `yarn why pre-commit` showed this:

```
❯ yarn why pre-commit
yarn why v1.3.2[1/4] Why do we have the module "pre-commit"...?
[2/4] Initialising dependency graph...
[3/4] Finding dependency...
[4/4] Calculating file sizes...
info This module exists because "@hollowverse/validate-filenames" depends on it.
info Disk size without dependencies: "104kB"
info Disk size with unique dependencies: "280kB"
info Disk size with transitive dependencies: "976kB"
info Number of shared dependencies: 14
Done in 1.03s.
```

So `pre-commit` was being installed because this package depends on it and it was installing the pre-commit hook in the project root. The issue might be because `pre-commit` is declared as a production dependency here.

Anyway, I replaced `pre-commit` with `husky` to bring this in line with our other repos and made sure `husky` is a dev dependency. We also get to add a `pre-push` hook as well!