Migrate husky 4 to 9


TL;DR: migrate husky from 4 to 9:

npx husky-4-to-5

This post goes over how to migrate husky from 4 to 9 using the npm package husky-4-to-5.

Problem

Husky’s maintainer created a migration tool husky-4-to-8 but it didn’t suit my needs because there’s a lot of manual work of updating scripts and removing leftover files:

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 on npm.

Migrating is as simple as:

npx husky-4-to-5

What wasn’t automated was prepending npx in front of the binaries of 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


Please support this site and join our Discord!