<p align="center">
Kicking off the year with an exciting update!
</p>
<p align="center">
<img src="https://github.com/typicode/husky/assets/5502029/457ab087-e935-4196-b99f-601ecf37f263" height="400px" alt="" />
</p>
_Note: install using `huskylatest` to get the bug fixes that were released after._
Introducing `husky init`
v8
shell
npm pkg set scripts.prepare="husky install"
npm run prepare
npx husky add .husky/pre-commit "npm test"
v9
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.
shell
npx husky init
Adding a New Hook
v8
shell
npx husky add .husky/pre-commit "npm test"
git add --chmod=+x .husky/pre-commit On Windows
v9
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:
shell
echo "npm test" > .husky/pre-commit
Further Size Reduction
`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 😄__
More to Come
Additional features are in the pipeline for `v9`. Stay tuned :raised_hands:
Other Changes
- **Enhanced security** with CI and npm `--provenance` for safer publishing.
- Added **`$XDG_CONFIG_HOME`** support. Move `~/.huskyrc` to `~/.config/husky/init.sh` for centralized configuration.
- **Fixed permission issue for Windows-created hooks**; they no longer need to be executable.
- Removed `husky install`. Use `husky` or `husky some/dir` for the same functionality (deprecation notice to be added).
- Modified behavior when `.git` is missing; it now triggers a warning instead of failure.
- Replaced `HUSKY_DEBUG=1` with `HUSKY=2` for debugging.
- Updated the Husky API for module usage.
- Transitioned to `ESM` for module usage.
- Dropped support for Node 14 and 16.
- Revamped docs.
How to Migrate
`v9` is backward compatible with `v8`, allowing you to freely upgrade and migrate your hooks later.
Here are the steps to migrate:
`package.json`
diff
{
"scripts": {
- "prepare": "husky install"
+ "prepare": "husky"
}
}
`.husky/pre-commit`
diff
- !/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:
diff
- const husky = require('husky')
- // ...
+ import husky from 'husky'
+ console.log(husky())
untagged-92a048317303ed861830
:dog: