Closed rubenswieringa closed 1 month ago
You can do it like this if you have a recent version of node:
node --env-file=.env ./node_modules/.bin/husky
Or
node --run prepare --env-file=.env
AFAIK there's no Node API that could be used from husky.
You can do it like this if you have a recent version of node:
node --env-file=.env ./node_modules/.bin/husky
This would be what you’d put in the package.json "prepare"
script?
Would that only work if the project dependencies haven’t already been installed?
This would be what you’d put in the package.json "prepare" script? Would that only work if the project dependencies haven’t already been installed?
Yes to both. But that's also the case when "prepare": "husky"
. When prepare
runs, dependencies have already been installed.
If you need to handle cases where husky is not installed (for example, in prod), check:
https://typicode.github.io/husky/how-to.html#ci-server-and-docker
Well the reason I asked is because it didn’t immediately make sense that the HUSKY
environment-variable was only evaluated during install.
One of the developers on my team doesn’t like the pre-commit linting/formatting we have configured in our project (using husky) and it seemed safe to assume that adding HUSKY=0
with npm-dependencies already installed at an earlier point would work.
Do you reckon that
node pre-commit.js
to my pre-commit hook…would be significantly slower?
I assumed you wanted to prevent install, but husky also support HUSKY=0 during commit (even if installed)
https://typicode.github.io/husky/how-to.html#skipping-git-hooks
The dev can disable husky permanently (or you can make it opt-in for your team)
Steps to reproduction:
HUSKY=0
in your project’s .env fileExpected results:
Actual results:
I’m running Husky v9.0.11 on the commandline (iTerm) if that matters. Setting
HUSKY=0
inline on the commandline when I commit does disable Husky, but I was assuming that having it in my .env file would do the same too.