Husky 5

A rewrite that goes back to something simpler, more flexible and closer to Git. Zero dependencies, explicit install, hooks as plain files.

ยท 1 min ยท husky, git, oss

I'm happy to announce the release of husky 5 ๐ŸŽ‰ ๐Ÿบ woof!

During the past years, husky has grown in complexity. With this version, I wanted to go back to something simpler, more flexible and closer to the metal.

You can use husky 5 in your Open Source projects today.

Thanks for your support and feedback. I hope you'll enjoy this release <3

https://github.com/typicode/husky

Faster and smaller

Husky 5 is closer to Git and has far fewer abstractions. It makes it not only simpler to understand but also very fast and small with zero dependencies.

Time spent to run a simple echo "hello world" pre-commit hook:

husky 4: ~0.50s
husky 5: ~0.01s

Installation size with dependencies:

husky 4: ~1.00MB with 47 packages
husky 5: ~0.02MB with  0 packages

Optional install

With husky 4, hooks were automatically installed. With husky 5, you have the choice and it's explicit.

You can keep the previous behaviour (recommended) by adding a postinstall script:

json
// package.json
{
  "private": true,
  "scripts": {
    "postinstall": "husky install"
  }
}

If you prefer to manually install husky, omit the above postinstall script and just run in your terminal:

sh
# Manual install
$ npx husky install
$ yarn husky install

Config

Previously, hooks were defined in package.json or .huskyrc. Now they're defined directly in their corresponding hook file. Overhead is reduced and scripting is easier.

sh
# .husky/pre-commit
# ...
yarn lint-staged

They can also be put in any subdirectory. For example in .config:

sh
# .config/husky/pre-commit
$ husky install .config/husky
$ husky add .config/husky/pre-commit "npm test"

How to migrate

A new doc site has been created with a dedicated section to migrating hooks from husky 4 to 5:

https://typicode.github.io/husky

If you have many projects using husky 4, you can use husky-4-to-5 CLI to do it automatically:

https://github.com/typicode/husky-4-to-5

There are some caveats so just copying your previous config may not work.