In this post, I'll show you how to upgrade from Husky - Git hooks v4.x to v5.x.
The motivation to write about that is because I made this upgrade on some of my projects and I think this short post can be helpful to you.
At the moment I'm writing this post the current version of Husky is
v5.1.1, I'll keep this version of the package to avoid configuration problems when we are reading this post.
Notice that Husky v5.x.x is free just for open source projects, read more here.
- Zero dependencies
- Lightweight (~0.02MB vs ~1MB for husky 4)
- Fast (~0.01s vs ~0.5s for husky 4)
- Supports macOS, Linux and Windows
npm install --save-dev firstname.lastname@example.org
yarn add -D email@example.com
Now, you already had installed Husky v5.1.1 you can execute the following command:
npx husky install
yarn husky install
Note: It will create the
.husky directory at the current directory you are when running this.
You will use the basis command every time you want to add a new hook to Husky, like:
npx husky add .husky/<HOOK NAME> "<SCRIPTS TO RUN>"
In this case, I'll add two hooks to Husky, such as:
npx husky add .husky/pre-commit "npx lint-staged"
npx husky add .husky/commit-msg 'npx --no-install commitlint --edit "$1"'
yarn husky add .husky/commit-msg 'npx --no-install commitlint --edit "$1"'
If you want to go deeper, I recommend you read the Husky docs.