Skip to content

czg-cli failed to load global configuration $HOME/.czrc or $HOME/.cz.json #132

Answered by 13OnTheCode
13OnTheCode asked this question in Q&A
Discussion options

You must be logged in to vote

是的, 我在本地调试了 cosmiconfig, 确实是 cosmiconfig 的问题:

cosmiconfig/cosmiconfig#278
tal-rofe/cz-vinyl#71

但是目前我还没有深入阅读源码寻找问题所在,初步测试发现应该是因为 MacOS 是统一的目录结构, 有一个统一的主目录(Home Directory)作为用户的个人文件空间,而在 Windows 上却是使用了分区的概念, 属于分层的目录结构, 通过逻辑磁盘(如C、D、E等)来组织文件和目录。每个逻辑磁盘都有自己的根目录。稍微看了一下源码 cosmiconfig 似乎没有对 Windows 系统做额外的处理,不清楚是不是开发人员有意为之还是疏忽了。

测试过程:

我在 D:\Developer\13OnTheCode\test\index.js 内执行了 cosmiconfig(...).search(...)
那么 cosmiconfig 最后递归到的 "主目录" 是 D 盘,而不是 C 盘
所以当 .czrc 配置文件创建在 D 盘的根目录下是可以找到的


最后我提交了一个 PR #133 ,最终改动是 const result = await resultFn(searchPath) ?? await cosmiconfigFn.search(os.homedir())

cosmiconfigFn.search(os.homedir()) 因为指定了 C 盘主目录路径,所以我认为不会有性能上的问题,在 cosmiconfig 修复这个问题之前,我认为这是目前最优解。稍后我会去阅读 co…

Replies: 4 comments 9 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@Zhengqbbb
Comment options

@13OnTheCode
Comment options

@Zhengqbbb
Comment options

Answer selected by 13OnTheCode
Comment options

You must be logged in to vote
6 replies
@WakerCN
Comment options

@Zhengqbbb
Comment options

@WakerCN
Comment options

@Zhengqbbb
Comment options

@Zhengqbbb
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants