Open castarco opened 4 years ago
I found the solution, I had to change the config
entry in the package.json
file (notice how I explicitly specify the cx
directory):
{
"config": {
"commitizen": {
"path": "cx/node_modules/cz-conventional-changelog"
}
}
}
Well, it seems I was too optimistic, there are still some "minor" problems:
(node:429371) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, open '/home/user/Code/namespace/prj-name/cx/.git/COMMIT_EDITMSG'
at openSync (fs.js:461:3)
at commit (/home/user/Code/namespace/prj-name/cx/node_modules/commitizen/dist/git/commit.js:844:62)
at dispatchGitCommit (/home/user/Code/namespace/prj-name/cx/node_modules/commitizen/dist/commitizen/commit.js:549:19)
at /home/user/Code/namespace/prj-name/cx/node_modules/commitizen/dist/commitizen/commit.js:630:11
at /home/user/Code/namespace/prj-name/cx/node_modules/cz-conventional-changelog/engine.js:217:9
The problem can be a little bit confusing, because the wizard works nicely... until the git editor is opened, and then you realize that the message is empty.
For now I'm applying a workaround, although it seems pretty nasty to me (basically I create a temporary symbolic link to the .git
directory, and I also revert the change I made to the config.commitizen.path
field):
{
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"husky": {
"hooks": {
"prepare-commit-msg": "ln -fs ../.git ./.git && exec < /dev/tty && npm run git-cz -- --hook || true && unlink ./.git",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
}
}
even nevermind, I was missing an n in "path": "./node_modules/cz-conventional-changelog"
doesn't work for me, cz
still fails to resolve it even though it's installed in devDependencies
argh.conventional
💩 😅
In my setup, the git repository is placed in
/home/user/Code/namespace/prj-name/
, but all the CI/CD code is placed in/home/user/Code/namespace/prj-name/cx
(in part, because it is not a JS project, and I want to "simplify" the directories/files structure at the root of the project).Before that, I had everything in the project root, and it was running fine, but I'm in the middle of a refactoring process for the build system, hence the change.
Husky seems to adapt pretty well to this setup (I even checked the generated shell scripts inside
.git/hooks
, and it takes care of changing directory before running the hooks).But...
commitizen
fails to do the same, and it insists on trying to load the modules from the "root" of the project, even if I set the$NODE_PATH
environment variable to point the/home/user/Code/namespace/prj-name/cx
directory (where$PWD
points too, due to how Husky works).Here you can see the error message, sadly it does not show the involved line numbers, and I couldn't follow the "jump" from
dist/commitizen.js
todist/commitizen/adapter.js
:Here a simplified version of my
package.json
file (also in thecx
directory):Is there any configuration option (or environment variable) I can use to tell commitizen how to behave?
Thanks for your attention.