commitizen / commitizen/cz-cli

commitizen init fails when commitizen is installed with -g

未关闭
#418 3 条评论 7 个 reaction 已指派 0 人 在 GitHub 查看
bug cli hacktoberfest help / pr wanted
主要语言
JavaScript
星标
17.5k
派生
566
平均合并
8 小时 16 分钟
30 天内合并 PR
1

描述

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. (/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.

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。