jestjs / jest

Delightful JavaScript Testing.
https://jestjs.io
MIT License
44.03k stars 6.43k forks source link

[Feature]: Replace `chalk` dependency with a lighter alternative #15189

Open trivikr opened 1 month ago

trivikr commented 1 month ago

🚀 Feature Proposal

Replace chalk dependency with a lighter alternative

Motivation

Recently, the Ecosystem Performance was formed to cleanup, speedup, levelup the JavaScript Ecosystem. Socket Security team wrote a blog post about it https://socket.dev/blog/javascript-community-launches-e18e-initiative-to-improve-ecosystem-performance

On the e18e cleanup channel on Discord, multiple solutions are being discussed. One of them is to replace chalk with picocolors.

I see that jest uses chalk https://github.com/jestjs/jest/blob/cce44d767e5e1d5c62eaaf5f93fb73748c25266b/package.json#L31

And it's upgrade to chalk@5.x is blocked since it's ESM only https://github.com/jestjs/jest/pull/14253#issuecomment-1604065296

Example

No response

Pitch

Replace chalk with a lighter alternative like picocolors.

SimenB commented 1 month ago

Happy to take a PR switching to picocolors (which babel etc. uses) or something else if there are better alternatives 👍

ishon19 commented 1 month ago

Hey @SimenB, I would like to work on this issue!

Also, I went through a bunch of relevant npm packages (kleur, colorette, etc.) and I also feel like picocolors would be the best option here, as it beats others in terms of the package size.

SimenB commented 1 month ago

Sweet thanks! Looking forward to it 👍

sindresorhus commented 3 weeks ago

I recommend reading this: https://github.com/chalk/chalk#why-not-switch-to-a-smaller-coloring-package

ishon19 commented 3 weeks ago

I recommend reading this: https://github.com/chalk/chalk#why-not-switch-to-a-smaller-coloring-package

Thanks for sharing the link @sindresorhus and I agree to a great extent, smaller packages somewhere fall short on providing the range of colors, something which I experienced in the linked draft PR, not to mention the package specific quirks that need to be accommodated on top of that.

SimenB commented 3 weeks ago

Fair enough, but for jest specifically that probably doesn't apply as much:

trivikr commented 1 day ago

I would like to work on this issue!

@ishon19 Are you still working on this?

My PR on changesets was just merged and released https://github.com/changesets/changesets/pull/1417, and I don't mind taking this up.

ishon19 commented 21 hours ago

@ishon19 Are you still working on this?

My PR on changesets was just merged and released changesets/changesets#1417, and I don't mind taking this up.

Hey @trivikr, that's awesome! Sure, you can take this up if you'd like to. I was stuck on the type extraction; the yarn build was failing as API Extractor couldn't extract picocolors type, I created an issue with picocolors too (linked in the draft PR) but haven't received any official response yet.

trivikr commented 13 hours ago

linked in the draft PR

My bad. I see that you've already posted PR on Jul 18th which I didn't know about https://github.com/jestjs/jest/pull/15197

Thank you for posting the PR, and following up with the maintainer.

ishon19 commented 13 hours ago

My bad. I see that you've already posted PR on Jul 18th which I didn't know about #15197

Thank you for posting the PR, and following up with the maintainer.

No problem! Hoping to get a response from the maintainer soon so that we're good to go.