Skip to content

Commit

Permalink
fix(loader): support commitlint v19 esm plugin extends config (#161)
Browse files Browse the repository at this point in the history
* fix(plugin-loader): to support commitlint v19 `esm` plugin extends config

commitlint update to pure ESM.
Include common plugin like `@commitlint/config-conventional`
It cause cz-git loader config error

link #160
  • Loading branch information
Zhengqbbb authored Mar 3, 2024
1 parent b091c64 commit e410465
Show file tree
Hide file tree
Showing 8 changed files with 253 additions and 382 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"unocss.root": "docs",
"prettier.enable": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},
"picgo.picBed.github.path": "cz/",
"editor.formatOnSave": false,
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,21 @@ Support OpenAI, and more engineered, lightweight, customizable, standard output
- 🔨 [Better for monorepo engineering](https://cz-git.qbb.sh/recipes/#scopes) and **commitlint** project to give relevant verification information to the command line.
- ✅ Support commit with **emoji** | Better linking with [issuePrefix](https://cz-git.qbb.sh/recipes/default-issues.html) **for issue**

[⇒ Why cz-git](https://cz-git.qbb.sh/guide/why.html)
[⇒ Why cz-git](https://cz-git.qbb.sh/cli/why.html)

```bash
$ npm i -D cz-git
+ cz-git (1.9 MB)
added 1 package in 0.582s
```

[⇒ Why czg](https://cz-git.qbb.sh/guide/why.html)
```bash
$ npm i -g czg
+ czg (1.5 MB)
added 1 package in 0.531s
```

## Projects using cz-git

<table>
Expand Down
33 changes: 19 additions & 14 deletions docs/faq/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,18 @@ sitemap:

# FAQ

## Windows users use
## Error: require() of ES Module ... not supported

- Windows users are advised not to use powershell, cmd for command line use
- because they are not based on the POSIX SHELL specification, i.e. not a standard terminal environment
- It is recommended not to use git-bash, because the terminal is not an interactive terminal, and the selection up and down will be effected
- **It is recommended to use Windows Terminal combined with WSL, you should also do the same in daily development and use**
1. If you are an ESM project (i.e., `"type": "module"` in package.json),
- You can try changing the [configuration name](/config/) from `.js` to `.cjs`.
2. If you are using commitlint version (> 18),
- For example, configuring `extends: ['@commitlint/config-conventional']`,
- Please upgrade cz-git or czg to the latest version.

## Cannot find command after global install
## Can I customize the message format ?

- Enter the command `npm prefix -g` to check whether the path of npm global download is in the root directory
- The high probability is because the global download path prefix of npm has been changed with nvm
- You can open .zshrc or .bashrc to comment out the loading nvm, and then reopen the terminal to check

## Terminal cannot display Emoji symbols

- The terminal cannot Emoji symbols, the high probability is because your terminal has poor support for emoji/unicode characters, but it does not affect the submission
Because the final output is submitted by Emoji Code, you can consider changing the terminal and [font](https://github.com/ryanoasis/nerd-fonts)
1. The configuration contains most of the message format fine-tuning requirements, such as changing the emoji position with [emojiAlign](/config/show#emojialign).
2. [formatMessageCB](/config/engineer#formatmessagecb): It is the final format callback function. You can configure it to achieve the message format you need.

## Configure load not as expected

Expand All @@ -37,6 +32,16 @@ CZ_DEBUG=1 cz
CZ_DEBUG=1 czg
```

## Cannot find the command after global install

- Enter the command `npm prefix -g` to check whether the bin folder path of npm's global download is added to the system environment variable `$PATH`.
- Most likely because using nvm changed the npm global download path prefix, but the system environment variable was not recorded.

## Terminal cannot display Emoji symbols

- The terminal cannot Emoji symbols, the high probability is because your terminal has poor support for emoji/unicode characters, but it does not affect the submission
Because the final output is submitted by Emoji Code, you can consider changing the terminal and [font](https://github.com/ryanoasis/nerd-fonts)

## What is different between `cz-git` and `czg`

> See more [Why czg](/cli/why.html)
Expand Down
33 changes: 19 additions & 14 deletions docs/zh/faq/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,21 @@ sitemap:
---
# 常见问题

## Windows 用户使用
## Error: require() of ES Module ... not supported

- Windows用户建议不要使用 powershell, cmd 进行命令行的使用
- 因为他们不是基于 POSIX SHELL 规范,即不是标准终端环境
- 建议也不要使用 git-bash,因为该终端并不是交互型终端,上下选择以及交互体验上会受到很大的使用体验
- **建议使用 Windows Terminal 结合 WSL ,你在日常的开发和使用中也应该如此**
1. 如果你是 ESM 项目 (即 package.json 中有 `"type": "module"`)
- 可以尝试更改 [配置名](/zh/config/) `.js` => `.cjs`
2. 如果你使用了 commitlint 版本(> 18)
- 例如配置 `extends: ['@commitlint/config-conventional']`
- 请升级 cz-git 或 czg 到最新版本

## 全局安装后无法找到命令

- 输入命令 `npm prefix -g` 查看当中npm全局下载的路径是否为根目录下
- 大概率是因为使用 nvm 更改了 npm 的全局下载路径前缀
- 可以打开.zshrc 或者 .bashrc 将加载 nvm 部分先注释掉,重新开启终端检查

## 终端无法显示Emoji符号
## 可以自定义消息格式吗

- 终端无法Emoji符号,大概率是因为你的终端对于 emoji/unicode 字符支持较差,但是不影响提交
因为最终输出提交的是 Emoji Code,可以考虑更换终端与[字体](https://github.com/ryanoasis/nerd-fonts)
1. 配置总含有大部分消息格式的微调需求,例如 [emojiAlign](/zh/config/show#emojialign) 更换 emoji 位置
2. [formatMessageCB](/zh/config/engineer#formatmessagecb): 是最终格式回调函数,你可以配置它来达到你需求的消息格式

## 配置加载不符合预期

可以运行命令查看配置加载的路径

```sh
Expand All @@ -35,6 +31,15 @@ CZ_DEBUG=1 cz
CZ_DEBUG=1 czg
```

## 全局安装后无法找到命令

- 输入命令 `npm prefix -g` 查看当中 npm 全局下载的 bin 文件夹路径是否添加到系统环境变量 `$PATH`
- 大概率是因为使用 nvm 更改了 npm 的全局下载路径前缀,但系统环境变量没有记录

## 终端无法显示 Emoji 符号

- 终端无法显示 Emoji 符号,大概率是因为你的终端对于 emoji/unicode 字符支持较差,但是不影响提交,因为最终输出提交的是 Emoji Code,可以考虑更换终端以及终端设置使用的[字体](https://github.com/ryanoasis/nerd-fonts)

## `cz-git``czg` 有什么不同

> 可以查看更多信息 [czg 的动机](/zh/cli/why.html)
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
},
"devDependencies": {
"@antfu/eslint-config": "0.38.6",
"@commitlint/cli": "^17.4.4",
"@commitlint/config-conventional": "^17.4.4",
"@commitlint/cli": "^19.0.3",
"@commitlint/config-conventional": "^19.0.3",
"@cz-git/inquirer": "workspace:*",
"@types/fs-extra": "^11.0.2",
"@types/inquirer": "8.2.3",
Expand Down Expand Up @@ -80,7 +80,8 @@
"chalk": "4.1.2",
"color-convert": "2.0.1",
"resolve-from": "5.0.0",
"supports-color": "8.1.1"
"supports-color": "8.1.1",
"@commitlint/config-validator": "npm:@qbbsh/config-validator@19.0.3"
},
"peerDependencyRules": {
"ignoreMissing": [
Expand Down
4 changes: 2 additions & 2 deletions packages/@cz-git/plugin-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
"clean": "rimraf lib"
},
"devDependencies": {
"@commitlint/resolve-extends": "^17.4.4",
"@commitlint/types": "^17.4.4",
"@commitlint/resolve-extends": "^19.0.3",
"@commitlint/types": "^19.0.3",
"@types/tmp": "^0.2.3",
"cosmiconfig": "8.2.0",
"pkg-dir": "5.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@cz-git/plugin-loader/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export async function clLoader(cwd?: string): Promise<CommitlintOptions> {

// resolve extends
const base = (data && data.filepath) ? path.dirname(data.filepath) : process.cwd()
const extended = resolveExtends(data.config, {
const extended = await resolveExtends(data.config, {
prefix: 'commitlint-config',
cwd: base,
})
Expand Down
Loading

0 comments on commit e410465

Please sign in to comment.