commitizen / cz-cli

The commitizen command line utility. #BlackLivesMatter
http://commitizen.github.io/cz-cli/
MIT License
16.9k stars 552 forks source link

Allow specifying adaptor module, not path #79

Closed bahmutov closed 8 years ago

bahmutov commented 9 years ago

Why do we load a path to an adaptor and not an actual module? I like to distribute the commitizen with my pre-git module as pre-git dependency by default. But commitizen cannot find the adaptor path

"czConfig": {
    "path": "node_modules/cz-conventional-changelog"
}

This breaks between npm 2 and 3 - npm3 seems to flatten paths, while npm2 leaves the paths nested. I believe it would be better to just require the adaptor by name, rather than use node_modules path, or at least check if the path resolves or not.

jimthedev commented 9 years ago

@bahmutov Thanks for the great idea. I've considered this as well but haven't had time to implement yet. I do intend to eventually.

Historically, the reason behind using the path is two fold:

  1. It is simply an artifact of commitizen being written before Npm 3 existed when it was simply easier to resolve a path.
  2. It helpful for adapter authors who are developing their adapters at a separate path on disk and want to be able to easily point to that without having to use npm link or something else.

I agree that it needs some work to provide a module key instead of a path key. We could likely handle resolving the paths internally in commitizen. Currently we handle the differences between npm 2 and npm 3 in a very hacky way by trying to load one, then the other (incorrect: see here) that ideally we'd eventually remove once npm2 falls out of favor.

Edit: My link here on finding npm modules was incorrect. That is how we used to do it. We now use the find-node-modules plugin so I'd imagine we could implement this relatively easily.

bahmutov commented 9 years ago

cool, for now I implemented running the adapter from my own module without going through commitizen bin script, here is the change https://github.com/bahmutov/pre-git/commit/1f35af70e6d428520bd79ed9fea98740a4f76592 I wanted to use commitizen as a module, but the src/index.js is a dummy file, right? https://github.com/commitizen/cz-cli/blob/master/src/index.js

jimthedev commented 9 years ago

You are correct. :) It is just a dummy file since up until now it has really only been used as a cli. Time to expose the api a bit better in a library I suppose.

One quick edit, too. My post above on finding npm modules was incorrect. That is how we used to do it. We now use the find-node-modules plugin so I'd imagine we could implement this relatively easily.

jimthedev commented 9 years ago

Also, @bahmutov, please upgrade to the latest version of commitizen's cli and use the following package.json syntax since czConfig will be deprecated in 3.0.0.

config: {
  commitizen: {
    path: './node-modules/cz-conventional-changelog'
  }
}

http://commitizen.github.io/cz-cli/