precommit runs twice when using husky
See original GitHub issueHere’s my relevant package.json
:
"devDependencies": {
"commitizen": "^2.9.6",
"cz-conventional-changelog": "^2.0.0",
"husky": "^0.13.2",
"lint-staged": "^3.4.0",
"prettier": "^1.2.2"
},
"scripts": {
"precommit": "lint-staged --verbose",
"commit": "git-cz",
},
"lint-staged": {
"*.js": [
"prettier --single-quote --semi=false --write",
"git add"
]
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
lint-staged
is correctly called once before the commitizen
command line form appears, and then incorrectly husky - npm run -s precommit
is run after. Typically without commitizen
only lint-staged
is called. Somehow commitizen
is triggering husky
to be called. No where do I have this script: npm run -s precommit
. It seems commitizen
somehow triggers it after you complete the form.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Commitizen and husky seem to be triggering the pre-commit ...
I am trying to configure commitizen with husky and when I commit using a custom script from package.json commit gets triggered twice.
Read more >Developers - should husky be running precommit hooks twice
should husky be running precommit hooks twice: once before commitizen wizards and again after?
Read more >pre-commit
To run individual hooks use pre-commit run <hook_id> . The first time pre-commit runs on a file it will automatically download, install, and...
Read more >Getting started with Husky and Lint-staged for pre-commit hooks
Think of Prettier converting double quotes to single quotes for example. Lint-staged is also pre-configured to run the linting scripts on the staged...
Read more >Husky + Lint-Staged on a React TypeScript Project
"pre-commit": "npm run test -- --watchAll=false" } }. Note: As you see, Husky Configuration file can use any script on “package.json” by ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
That is a bug in husky that happens due to a “feature” of npm-scripts that auto run scripts with the name prexxx where xxx is the name of another script. So, because you’re using
commit
andprecommit
it is running them twice.Until husky fixes this you can simply change your commitizen task to
cmt
or something else (cz
,co
, etc).We could probably update our docs to reflect that when using commitizen and husky you should pick another name than
npm run commit
. Want to put in a PR?nice find!
Here’s the PR as requested: https://github.com/commitizen/cz-cli/pull/433