Zhengqbbb / cz-git

cz-git | czg 🛠️ DX first and more engineered, lightweight, customizable, standard output format Commitizen adapter and CLI
https://cz-git.qbb.sh
MIT License
1.1k stars 40 forks source link

[Feature Request] Support commitlint.config.mjs extension #177

Closed zigang93 closed 2 months ago

zigang93 commented 3 months ago

💭 Describe the feature

support esm module file. using import statement

💡 Proposed Solution

No response

Zhengqbbb commented 3 months ago

I apologize, but at the beginning of the project, I started experimenting with compatibility in this ESM ISSUE which proved infeasible due to upstream dependencies:

  1. The CLI must be started using the Common JS method because the Terminal UI library inquirer@8.2.4 used by commitizen requires CJS, and commitizen is currently very inactive, so I don't think it will be updated.
  2. If I use the CJS method to start and obtain ESM configuration, an error will occur.

https://github.com/commitizen/cz-cli/blob/28d96ef98d702dc48c7a19d44dce710ab80911ba/package.json#L84 https://github.com/SBoudrias/Inquirer.js/tree/inquirer%408.2.4


However, there is still a way to achieve this, which is to use @esbuild-kit/cjs-loader to convert the CJS compatibility layer and provide it to the cz-git configuration. https://github.com/element-plus/element-plus/blob/dev/commitlint.config.js playground: https://github.com/Zhengqbbb/czgit-playground/tree/commitizen-esm

Zhengqbbb commented 3 months ago

BTW I'm curious why it's necessary to use commitlint.config.mjs. Emmm as far as I know, commitlint.config.cjs can also achieve the validation effect.

zigang93 commented 2 months ago

btw, I able to make it work with .js only.. and make my monorepo root packages.json with "type": module"..

I had tried to change .cjs but it don't work..

I want to use .mjs because I don't want to use "type": module" in my packages.json.. it will force my source code to use esm only.. mjs is standalone config file.. I saw @commitlint/cli got support mjs..

lastly, from my understanding.. cjs is use for commonjs ? it shouldn't support modern import statement

Zhengqbbb commented 2 months ago

make my monorepo root packages.json with "type": module". I had tried to change .cjs but it don't work..

Oh that is something wrong. It should work. If you try to read js in your type:modules project, it will use the ESM paradigm to read it. However, if your file is cjs, it will forcibly use the CJS method to read the configuration.


Have a reproduction repo 👀 ?

zigang93 commented 2 months ago

make my monorepo root packages.json with "type": module". I had tried to change .cjs but it don't work..

Oh that is something wrong. It should work. If you try to read js in your type:modules project, it will use the ESM paradigm to read it. However, if your file is cjs, it will forcibly use the CJS method to read the configuration.

Have a reproduction repo 👀 ?

I try reproduce for u :) will update to u within 2 days