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.12k stars 41 forks source link

[Bug report] Duplicate node modules getting bundled #107

Closed jrson83 closed 1 year ago

jrson83 commented 1 year ago

✅ Checklist

📄 System Info

System:
  OS: Windows 10 10.0.22621
  CPU: (12) x64 AMD Ryzen 5 3600 6-Core Processor
  Memory: 17.64 GB / 31.93 GB
Binaries:
  Node: 18.14.0 - ~\AppData\Local\Volta\tools\image\node\18.14.0\node.EXE
  Yarn: 1.22.18 - ~\AppData\Local\Volta\tools\image\yarn\1.22.18\bin\yarn.CMD
  npm: 9.3.1 - ~\AppData\Local\Volta\tools\image\node\18.14.0\npm.CMD
npmPackages:
  cz-git: workspace:* => 1.6.0
  czg: workspace:* => 1.6.0

🔎 Description

Concise Description

There are duplicate node modules in the monorepo, which get bundled twice on build.

Expected behavior

Each module should be bundled once.

Steps to reproduce

  1. Clone and install the monorepo.
git clone https://github.com/Zhengqbbb/cz-git.git
cd cz-git
pnpm install

Tsup can generate a metafile for bundle analysis by adding --metafile as flag.

  1. Open packages/cli/package.json and add --metafile to the build script.
"build": "pnpm clean && tsup --metafile"
  1. Run pnpm build.
  2. Goto Bundle Buddy, choose esbuild, click the button Upload assets ESBUILD.JSON and upload the metafile from packages/cli/lib/metafile-cjs.json.
  3. Scroll down and click GO TO ANALYSIS.
  4. You should see the duplicate modules in health check section.

Screenshots or Screen Recording

2023-03-17_13h17_31

Possible solution

Use pnpm overrides in package.json to get rid of the duplicate modules:

"pnpm": {
  "overrides": {
    "chalk": "^5.2.0",
    "color-convert": "^2.0.1",
    "supports-color": "^9.3.1"
  },
}

I have tested this and the bundle-size is about 1kb less after and the duplicate modules are gone:

2023-03-17_13h30_42

I was hoping this helps, but after build all tests fail, cause chalk and supports-color dropped cjs support.

I will test again with the last versions with cjs support. If I find another solution I will let you know.

UPDATE:

I tested again and with the following versions, the tests run successful (added to root package.json):

"pnpm": {
  "overrides": {
    "chalk": "4.1.2",
    "color-convert": "2.01",
    "supports-color": "8.1.1"
  },
}

🔗 Reproduction link / repo:

No response

jrson83 commented 1 year ago

I will create the PR, but before releasing we should test in detail if it doesn't break anything.

Zhengqbbb commented 1 year ago

That's for sure I will close If the 1KB brings uncertainty

Zhengqbbb commented 1 year ago

I have released the next version ⭐ 1.6.2-beta.1⭐ Welcome to use it and let me know if there are any ISSUE ~

jrson83 commented 1 year ago

Awesome, thank you!