Announcing meteor-husky, the husky git hooks package for Meteor

meteor-husky

I’ve been using the husky package for awhile now for defining precommit and prepush git hooks in a project’s package.json to do things like block commits if code linting fails, and block git pushes if unit tests fail. It’s really great for local development.

Unfortunately it relies on the system’s available npm and node and doesn’t provide a way to let it use Meteor npm and Meteor node instead. So I’ve created a slightly modified version of the package that will use Meteor’s internal versions of the two instead, so you can use the package without having to install node external of Meteor.

2 Likes

I ran this package, and then uninstalled it and ran the official husky package. The official package seems to work fine for myself and the person who helped me in this thread Pre-commit hooks not working?

The regular husky package will work if you have node and npm installed on your system outside of Meteor. meteor-husky is husky, but it forces your husky scripts to use the version of node and npm bundled with your project’s Meteor version. Try setting up a Meteor project on a system that doesn’t have node installed, then use husky. It won’t work because husky can’t find your system’s node binary in the PATH.

This can be problematic if some of your scripts are using a node API or EcmaScript feature that isn’t present in your system’s node version causing unpredictable behavior, or if someone on your team has only installed Meteor and not node.

See this line in the husky code, which gets added to your .git/hooks folder for each hook. It simpy runs

npm run -s <hook script in package.json>

Now see this line in meteor-husky, which forces your git hooks to use

meteor npm run -s <hook script in package.json>

which is the npm version bundled with your proejct’s Meteor version. That isn’t the only difference between the packages, but that’s the main one.

Thanks @efrancis . That makes sense to me and I’ll re-add your meteor version

is there a way I could make that more clear in the README to others? I suppose I could add my previous comment if it’s helpful

Here’s how I would put it (mainly rephrasing your first paragraph and giving it all my effort).

Meteor developers should use the meteor-husky package because you cannot depend on other meteor developers having npm/node installed at the system level (I didn’t my first couple weeks on the job). The meteor-husky package has a slight modification familiar to meteor developers changing husky’s usage of npm run to meteor npm run .

1 Like

got it, thanks! I’ll make a couple changes to the README and republish sometime soon