New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

commitizen init fails when commitizen is installed with -g #418

Open
jimthedev opened this Issue Jan 9, 2017 · 0 comments

Comments

Projects
None yet
1 participant
@jimthedev
Member

jimthedev commented Jan 9, 2017

Installing commitizen globally using the steps in the documentation as shown here

npm install -g commitizen
npm install -g cz-conventional-changelog
echo '{ "path": "cz-conventional-changelog" }' > ~/.czrc

Prevents you from being able to run commitizen init --save-dev cz-conventional-changelog in a brand new npm project.

Attempting to initialize using the npm package cz-conventional-changelog
Error: A previous adapter is already configured. Use --force to override

Actually running commitizen init --save-exact --save-dev cz-conventional-changelog --force results in:

Attempting to initialize using the npm package cz-conventional-changelog
npm WARN using --force I sure hope you know what you are doing.
npm WARN saveError ENOENT: no such file or directory, open '/Users/jim.cummins/package.json'
/Users/jim.cummins
└─┬ cz-conventional-changelog@1.2.0
  ├── conventional-commit-types@2.1.0
  ├── lodash.map@4.6.0
  ├── longest@1.0.1
  ├─┬ pad-right@0.2.2
  │ └── repeat-string@1.6.1
  ├── right-pad@1.0.1
  └── word-wrap@1.2.0

npm WARN enoent ENOENT: no such file or directory, open '/Users/jim.cummins/package.json'
npm WARN jim.cummins No description
npm WARN jim.cummins No repository field.
npm WARN jim.cummins No README data
npm WARN jim.cummins No license field.
{ Error: ENOENT: no such file or directory, open '/Users/jim.cummins/package.json'
    at Error (native)
    at Object.fs.openSync (fs.js:640:18)
    at Object.fs.readFileSync (fs.js:508:33)
    at addPathToAdapterConfig (/Users/jim.cummins/.nvm/versions/node/v6.9.1/lib/node_modules/commitizen/dist/commitizen/adapter.js:71:40)
    at init (/Users/jim.cummins/.nvm/versions/node/v6.9.1/lib/node_modules/commitizen/dist/commitizen/init.js:104:9)
    at Object.bootstrap (/Users/jim.cummins/.nvm/versions/node/v6.9.1/lib/node_modules/commitizen/dist/cli/commitizen.js:43:30)
    at Object.<anonymous> (/Users/jim.cummins/.nvm/versions/node/v6.9.1/lib/node_modules/commitizen/bin/commitizen.js:2:38)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/Users/jim.cummins/package.json' }

I think this is because when running init we need to assume that the user wants to only init in the current directory, as such we should not be using findup to get the highest npm path like we do when looking for an adapter. Instead we need to be stricter in the case of init. We should explicitly be looking in the current directory for a package.json or we should fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment