Skip to content

feat(perf) - de-duplicate chalk dependency #6784

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

spanishpear
Copy link

@spanishpear spanishpear commented May 4, 2025

What's the problem this PR addresses?

👋 Hello! I was randomly looking at the @yarnpkg/cli bundle, and esbuild reported a few warnings (when building locally in the repo, and inspecting on https://esbuild.github.io/analyze/ ).

One of these warnings, was that there are some duplicated external libraries - such as chalk.

{1BA9255A-15DD-48DC-9A9E-D8183671F486}

Full bundle graph

The savings from this PR are tiny (a few kb), but worth doing :)

What does this PR do

This PR bumps chalk to consistently be v4.1.2 up from v 3.0.0.
The diff for 3.0.0 to 4.0.0 is here. The only relevant breaking change is dropping node 8 support, which should suffice for yarn (current engines of yarn is set to 18).

Note

I didn't opt for v5 - as it's esm only, and may require some config tweaking. V5 is a smaller bundle though, ~half the size!

/aside - It would be a larger bundle saving to remove the dependency entirely to something like https://www.npmjs.com/package/picocolors - but that's potentially a larger piece of work, as @yarnpkg/shell uses some bespoke colors .

I tried to bump ink, as they've made some improvements too - but it seems they expect tools to bundle with an esm format - wheras yarn is currently bundling as iife, so would require decent patching or upstream changes ( I couldn't get either to work just yet).

How did you fix it?

yarn upgrade-interactive to specify v4 of chalk :)
Note that yarn upgrade-interactive is difficult to use when using workspaces, until #3260 (or similar) are closed. Similarly reported in #2591 #3281.

Checklist

  • I have read the Contributing Guide.
  • I have set the packages that need to be released for my changes to be effective.
  • I will check that all automated PR checks pass before the PR gets reviewed.

@spanishpear
Copy link
Author

Ah, I left a type error in - will fix it when I'm back at my laptop!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant