Open ackvf opened 2 years ago
@ackvf Great suggestion! I took this for a spin on my end, however, and the prepare
script pushes a new line with tsdx lint
to the ./husky/pre-push
hook every time the package is installed.
I'm using Yarn, and the Husky guide is a little different for Yarn. I also removed husky: {}
from package.json
but I made these script changes instead:
"postinstall": "husky install",
"prepack": "pinst --disable",
"postpack": "pinst --enable",
"husky:init": "npx husky add .husky/pre-commit 'tsdx lint'"
I just run husky:init
once to bootstrap the command I want, instead of attaching it to prepare
.
I'm using "tsdx": "^0.14.1" & yarn v1.22.19. What I do only following this:
npx husky-init && yarn
and the command will:
&& husky install
at prepare section and install husky with a new version that I think it will be adjusted according to the peer dependencies.
{
"scripts": {
...
"prepare": "tsdx build && husky install", // <--- previous "prepare": "tsdx build"
...
},
"devDependencies": {
...
"husky": "^8.0.0",
...
}
.husky/pre-commit
at my root directory
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
npm test
Since I using yarn, then I change npm test into:
. "$(dirname -- "$0")/_/husky.sh"
yarn lint && yarn test
Next, remove **husky** section below at **package.json**
"husky": { "hooks": { "pre-commit": "tsdx lint" } },
and that's it. When I do a commit the husky will run as expected
Current Behavior
Husky >4 does not automatically create hooks with new tsdx installs.
Expected behavior
When I create my first commit, it should run pre-commit hooks.
Suggested solution(s)
Husky lists steps to register a hook on their site, maybe it could be automated using a script. https://github.com/typicode/husky#usage
What works for me
note
husky: {}
frompackage.json
altogether.init:husky
scriptprepare
scriptAdditional context
There have been some changes in Husky since version 4 and it does not register the hooks automatically any more. Husky 7 is used with tsdx and thus it is also affected.