Migrate husky 4 to 5


TL;DR: run in your command-line:

 npx husky-4-to-5

Problem

Husky’s maintainer created a migration tool husky-4-to-5 but it didn’t suit my needs.

It requires you to be on npm 7+ and there’s a lot of manual work of updating scripts and removing leftover files.

To migrate for an npm project:

npm exec -- github:typicode/husky-4-to-5 --package-manager npm

Solution

As a result, I created my own CLI tool husky-4-to-5 that’s published to npm.

Migrating is as simple as:

npx husky-4-to-5

The one step I didn’t automate is prepending npx in front of the binaries in the husky hooks.

For example:

jest → npx jest
     → yarn jest

jest && eslint → npx jest && npx eslint
               → yarn jest && yarn eslint

commitlint -E HUSKY_GIT_PARAMS → npx commitlint --edit $1
                               → yarn commitlint --edit $1

Resources



Please support this site and join our Discord!