Big fan of commitizen here. In so much that I'm trying to use it for projects that are not part of the NPM/node/javascript ecosystem. Any git repository, that is.
I can't get that scenario to work. I've installed commitizen, conventional-changelog, cz-conventional-changelog globally with -g, but running git cz fails (and falls back to regular git) because the adapter is either not found, or not loaded. No surprise here I guess, since there is no package.json file, and there won't be one in that repo. Would it be possible to provide a global configuration file, say ~/.czconfig, that the CLI would use when all else fails?
Thanks
@sebastienbarre Sorry I was a bit slow to reply. Good question, though!
Our config loader actually allows for this. You can use either .cz.json or .czrc. Just throw your config in there and we'll pick up the config. :+1:
Hopefully that works!
Thanks. Interesting! Failing for me:
$ git cz -a
Error: Could not locate node_modules in your project's root directory. Did you forget to npm init or npm install?
path.js:481
throw new TypeError('Arguments to path.join must be strings');
^
TypeError: Arguments to path.join must be strings
at Object.posix.join (path.js:481:13)
at getNearestProjectRootDirectory (/Volumes/Users/barre/.npm-packages/lib/node_modules/commitizen/dist/commitizen/adapter.js:138:28)
at gitCz (/Volumes/Users/barre/.npm-packages/lib/node_modules/commitizen/dist/cli/strategies/git-cz.js:74:58)
at Object.bootstrap (/Volumes/Users/barre/.npm-packages/lib/node_modules/commitizen/dist/cli/git-cz.js:29:27)
Maybe I'm not using it properly, here is my ~/.czrc:
{
"config": {
"commitizen": {
"path": node_modules/cz-conventional-changelog"
}
}
}
I also tried
"path": "~/.npm-packages/lib/node_modules/cz-conventional-changelog"
Ah yes, can you try:
{
"path": "~/.npm-packages/lib/node_modules/cz-conventional-changelog"
}
I've also not actually tried using the ~ in the path but hopefully it would work. If not we could probably implement some kind of way to resolve ~ to a homedir.
I'm afraid neither the above, nor a resolved path did the trick...
{
"path": "/Volumes/Users/barre/.npm-packages/lib/node_modules/cz-conventional-changelog"
}
still getting
$ git cz -a
Error: Could not locate node_modules in your project's root directory. Did you forget to npm init or npm install?
path.js:481
throw new TypeError('Arguments to path.join must be strings');
^
TypeError: Arguments to path.join must be strings
at Object.posix.join (path.js:481:13)
at getNearestProjectRootDirectory (/Volumes/Users/barre/.npm-packages/lib/node_modules/commitizen/dist/commitizen/adapter.js:138:28)
Huh, ok I'll have to dig in more. Perhaps it is a bug. Thanks for working
on it w/me.
On Wed, Nov 25, 2015 at 6:32 PM Sébastien Barré [email protected]
wrote:
I'm afraid neither the above, nor a resolved path did the trick...
{
"path": "/Volumes/Users/barre/.npm-packages/lib/node_modules/cz-conventional-changelog"
}still getting
$ git cz -a
Error: Could not locate node_modules in your project's root directory. Did you forget to npm init or npm install?
path.js:481
throw new TypeError('Arguments to path.join must be strings');
^
TypeError: Arguments to path.join must be strings
at Object.posix.join (path.js:481:13)
at getNearestProjectRootDirectory (/Volumes/Users/barre/.npm-packages/lib/node_modules/commitizen/dist/commitizen/adapter.js:138:28)—
Reply to this email directly or view it on GitHub
https://github.com/commitizen/cz-cli/issues/83#issuecomment-159765628.
I have this resolved, just working on fixing some tests it broke as a result. Will be in the next release.
Sweet, thanks
Ok so this was _supposed_ to be simple but my tests alerted me to the fact that it isn't as simple as I'd hoped. This is due to two special places that the config loader is used in:
commitizen init command, which attempts to make sure that it doesn't overwrite any existing adapter configs that might be up the tree.So why are these two cases special? Well, simply put, the config loader needs two different traversal modes to handle them:
commitizen init we need to allow people to choose if they want unbounded traversal (the default) or if they want to add an upper boundary during init. Just wanted to give an update. :+1:
Thanks @jimthedev ; can you point me to the traversal code, out of curiosity?
I create symbolic link to solve this problem.
node_modules is in the /Users/yuyuxuan.
Suppose my git repository is /Volumes/Transcend/Study/English/New_concept/New_concept_dictation
I use ln -sf ~/node_modules . at the location /Volumes/Transcend/
I could get commitizen and cz-conventional-changelog work for non-node-git-repo with global installation.
Here are the steps that I have followed.
$ npm i -g commitizen cz-conventional-changelog$ echo '{ "path": "cz-conventional-changelog" }' > ~/.czrc; create .czrc$ cd non-node-git-repo$ touch foogit cz -aHope it will be helpful.
@sarbbottam the scenario you described didn't work when I created the issue, but it seems to have been fixed by @jimthedev since then. Which is great. Thanks to all.
@jimthedev let me know if you would prefer a PR to update the README with
$ npm i -g commitizen cz-conventional-changelog$ echo '{ "path": "cz-conventional-changelog" }' > ~/.czrc; create.czrc$ cd non-node-git-repo$ touch foogit cz -a
@sarbbottam That would be great if you could put in a README PR! 👍
@sebastienbarre Yes this was a nice PR from someone that replace how I was using require and instead using .resolve which is much more consistent behavior with how other node modules typically let you provide input. Cheers to the contributors. :)
Most helpful comment
I could get
commitizenandcz-conventional-changelogwork fornon-node-git-repowith global installation.Here are the steps that I have followed.
$ npm i -g commitizen cz-conventional-changelog$ echo '{ "path": "cz-conventional-changelog" }' > ~/.czrc; create.czrc$ cd non-node-git-repo$ touch foogit cz -aHope it will be helpful.