Git hooks made easy 🐶 woof!
Kicking off the year with an exciting update!
Note: install using husky@latest
to get the bug fixes that were released after.
husky init
npm pkg set scripts.prepare="husky install"
npm run prepare
npx husky add .husky/pre-commit "npm test"
Adding husky to a project is now easier than ever. It's just a single line that does the same as above. No need to read the docs to get started anymore.
npx husky init
npx husky add .husky/pre-commit "npm test"
git add --chmod=+x .husky/pre-commit # On Windows
Adding a hook is as simple as creating a file. This can be accomplished using your favorite editor, a script or a basic echo
command. For example, on Linux/macOS:
echo "npm test" > .husky/pre-commit
v8
was already the most compact Git hooks manager at approximately 6kB
.
v9
takes this a step further, reducing the size to just 3kB
, likely making it the smallest devDependency in your toolkit.
To give you an idea of how small it is, the biggest file in the project is the MIT license 😄
Additional features are in the pipeline for v9
. Stay tuned :raised_hands:
--provenance
for safer publishing.$XDG_CONFIG_HOME
support. Move ~/.huskyrc
to ~/.config/husky/init.sh
for centralized configuration.husky install
. Use husky
or husky some/dir
for the same functionality (deprecation notice to be added)..git
is missing; it now triggers a warning instead of failure.HUSKY_DEBUG=1
with HUSKY=2
for debugging.ESM
for module usage.v9
is backward compatible with v8
, allowing you to freely upgrade and migrate your hooks later.
Here are the steps to migrate:
package.json
{
"scripts": {
- "prepare": "husky install"
+ "prepare": "husky"
}
}
.husky/pre-commit
- #!/usr/bin/env sh
- . "$(dirname -- "$0")/_/husky.sh"
npm test
Note: sh
will be used to run hooks, even if a shebang is set.
If you were using husky
as a module:
- const husky = require('husky')
- // ...
+ import husky from 'husky'
+ console.log(husky())
:dog:
husky -
prefix to logged global error messages by @joshbalfour in https://github.com/typicode/husky/pull/1092
PATH
when command not found to improve debuggability$HUSKY=0
/usr/bin/env sh
instead of direct path of sh
by @skhaz in https://github.com/typicode/husky/pull/1051
./husky.sh
by @hyperupcall in https://github.com/typicode/husky/pull/1104
basename
/dirname
to treat $0
as an argument by @mataha in https://github.com/typicode/husky/pull/1132
git.io
links by @renbaoshuo in https://github.com/typicode/husky/pull/1136
npx --no-install
option with npx --no
by @sibiraj-s in https://github.com/typicode/husky/pull/1070
pnpm
installation by @MohamadKh75 in https://github.com/typicode/husky/pull/1139
No changes. Husky v7.0.3 was reverted, this version is the same as v7.0.2.
Fix pre-commit hook in WebStorm (#1023)
.husky/
directory structure. .husky/.gitignore
is now unnecessary and can be removed.husky-init
CLIhusky-4-to-7
CLIPlease help me develop and release OSS projects :heart: on GitHub Sponsors or Open Collective. Thank you for your support!