Skip to content

Commit 2c69552

Browse files
authored
feat(perf) - de-duplicate chalk dependency (#6784)
## 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}](https://github.com/user-attachments/assets/e1b8bf8a-db5e-4a92-b7f4-eb6b747b6c49) <details><summary>Full bundle graph</summary> <img src="https://github.com/user-attachments/assets/99133d9b-5bbf-4390-84ab-b608ef301501" /> </details> 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 ](https://github.com/chalk/chalk/releases/tag/v4.0.0) up from v `3.0.0`. The diff for 3.0.0 to 4.0.0 is [here](chalk/chalk@v3.0.0...v4.0.0). 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 ](https://github.com/chalk/chalk/releases/tag/v5.0.0)- 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 ](https://github.com/yarnpkg/berry/blob/master/packages/yarnpkg-shell/sources/index.ts#L815-L815). 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 - [x] I have read the [Contributing Guide](https://yarnpkg.com/advanced/contributing). - [x] I have set the packages that need to be released for my changes to be effective. - [x] I will check that all automated PR checks pass before the PR gets reviewed.
1 parent bee82ef commit 2c69552

File tree

10 files changed

+52
-37
lines changed

10 files changed

+52
-37
lines changed

β€Ž.pnp.cjs

Lines changed: 6 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.

β€Ž.yarn/versions/6a20bebf.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
releases:
2+
"@yarnpkg/builder": patch
3+
"@yarnpkg/cli": patch
4+
"@yarnpkg/core": patch
5+
"@yarnpkg/doctor": patch
6+
"@yarnpkg/extensions": patch
7+
"@yarnpkg/nm": patch
8+
"@yarnpkg/plugin-compat": patch
9+
"@yarnpkg/plugin-constraints": patch
10+
"@yarnpkg/plugin-dlx": patch
11+
"@yarnpkg/plugin-essentials": patch
12+
"@yarnpkg/plugin-exec": patch
13+
"@yarnpkg/plugin-file": patch
14+
"@yarnpkg/plugin-git": patch
15+
"@yarnpkg/plugin-github": patch
16+
"@yarnpkg/plugin-http": patch
17+
"@yarnpkg/plugin-init": patch
18+
"@yarnpkg/plugin-interactive-tools": patch
19+
"@yarnpkg/plugin-jsr": patch
20+
"@yarnpkg/plugin-link": patch
21+
"@yarnpkg/plugin-nm": patch
22+
"@yarnpkg/plugin-npm": patch
23+
"@yarnpkg/plugin-npm-cli": patch
24+
"@yarnpkg/plugin-pack": patch
25+
"@yarnpkg/plugin-patch": patch
26+
"@yarnpkg/plugin-pnp": patch
27+
"@yarnpkg/plugin-pnpm": patch
28+
"@yarnpkg/plugin-stage": patch
29+
"@yarnpkg/plugin-typescript": patch
30+
"@yarnpkg/plugin-version": patch
31+
"@yarnpkg/plugin-workspace-tools": patch
32+
"@yarnpkg/pnpify": patch
33+
"@yarnpkg/sdks": patch
34+
"@yarnpkg/shell": patch

β€Žpackage.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
"dependencies": {
7878
"@iarna/toml": "^2.2.5",
7979
"@yarnpkg/types": "workspace:^",
80-
"chalk": "^3.0.0",
80+
"chalk": "^4.1.2",
8181
"micromatch": "^4.0.2",
8282
"semver": "^7.1.2"
8383
},

β€Žpackages/yarnpkg-builder/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"@yarnpkg/cli": "workspace:^",
1313
"@yarnpkg/core": "workspace:^",
1414
"@yarnpkg/fslib": "workspace:^",
15-
"chalk": "^3.0.0",
15+
"chalk": "^4.1.2",
1616
"clipanion": "^4.0.0-rc.2",
1717
"esbuild": "npm:esbuild-wasm@^0.23.0",
1818
"semver": "^7.1.2",

β€Žpackages/yarnpkg-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"@yarnpkg/parsers": "workspace:^",
2020
"@yarnpkg/shell": "workspace:^",
2121
"camelcase": "^5.3.1",
22-
"chalk": "^3.0.0",
22+
"chalk": "^4.1.2",
2323
"ci-info": "^4.0.0",
2424
"clipanion": "^4.0.0-rc.2",
2525
"cross-spawn": "^7.0.3",

β€Žpackages/yarnpkg-core/sources/formatUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {npath} from '@yarnpkg/fslib';
2-
import chalk from 'chalk';
2+
import chalk, {type Level} from 'chalk';
33
import CI from 'ci-info';
44
import {ColorFormat, formatMarkdownish} from 'clipanion';
55
import micromatch from 'micromatch';
@@ -63,7 +63,7 @@ export enum Style {
6363
BOLD = 1 << 1,
6464
}
6565

66-
const chalkOptions = CI.GITHUB_ACTIONS
66+
const chalkOptions: {level: Level} = CI.GITHUB_ACTIONS
6767
? {level: 2}
6868
: chalk.supportsColor
6969
? {level: chalk.supportsColor.level}

β€Žpackages/yarnpkg-sdks/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"@yarnpkg/core": "workspace:^",
1515
"@yarnpkg/fslib": "workspace:^",
1616
"@yarnpkg/parsers": "workspace:^",
17-
"chalk": "^3.0.0",
17+
"chalk": "^4.1.2",
1818
"clipanion": "^4.0.0-rc.2",
1919
"comment-json": "^2.2.0",
2020
"lodash": "^4.17.15",

β€Žpackages/yarnpkg-shell/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"dependencies": {
1313
"@yarnpkg/fslib": "workspace:^",
1414
"@yarnpkg/parsers": "workspace:^",
15-
"chalk": "^3.0.0",
15+
"chalk": "^4.1.2",
1616
"clipanion": "^4.0.0-rc.2",
1717
"cross-spawn": "^7.0.3",
1818
"fast-glob": "^3.2.2",

β€Žyarn.lock

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5780,7 +5780,7 @@ __metadata:
57805780
"@yarnpkg/core": "workspace:^"
57815781
"@yarnpkg/fslib": "workspace:^"
57825782
"@yarnpkg/monorepo": "workspace:^"
5783-
chalk: "npm:^3.0.0"
5783+
chalk: "npm:^4.1.2"
57845784
clipanion: "npm:^4.0.0-rc.2"
57855785
esbuild: "npm:esbuild-wasm@^0.23.0"
57865786
semver: "npm:^7.1.2"
@@ -5866,7 +5866,7 @@ __metadata:
58665866
"@yarnpkg/plugin-pnp": "workspace:^"
58675867
"@yarnpkg/shell": "workspace:^"
58685868
camelcase: "npm:^5.3.1"
5869-
chalk: "npm:^3.0.0"
5869+
chalk: "npm:^4.1.2"
58705870
ci-info: "npm:^4.0.0"
58715871
clipanion: "npm:^4.0.0-rc.2"
58725872
comment-json: "npm:^2.2.0"
@@ -6092,7 +6092,7 @@ __metadata:
60926092
"@yarnpkg/libzip": "workspace:^"
60936093
"@yarnpkg/sdks": "workspace:^"
60946094
"@yarnpkg/types": "workspace:^"
6095-
chalk: "npm:^3.0.0"
6095+
chalk: "npm:^4.1.2"
60966096
clipanion: "npm:^4.0.0-rc.2"
60976097
esbuild: "npm:esbuild-wasm@^0.23.0"
60986098
eslint: "npm:^9.20.1"
@@ -6630,7 +6630,7 @@ __metadata:
66306630
"@yarnpkg/monorepo": "workspace:^"
66316631
"@yarnpkg/parsers": "workspace:^"
66326632
"@yarnpkg/pnp": "workspace:^"
6633-
chalk: "npm:^3.0.0"
6633+
chalk: "npm:^4.1.2"
66346634
clipanion: "npm:^4.0.0-rc.2"
66356635
comment-json: "npm:^2.2.0"
66366636
lodash: "npm:^4.17.15"
@@ -6649,7 +6649,7 @@ __metadata:
66496649
"@yarnpkg/fslib": "workspace:^"
66506650
"@yarnpkg/monorepo": "workspace:^"
66516651
"@yarnpkg/parsers": "workspace:^"
6652-
chalk: "npm:^3.0.0"
6652+
chalk: "npm:^4.1.2"
66536653
clipanion: "npm:^4.0.0-rc.2"
66546654
cross-spawn: "npm:^7.0.3"
66556655
fast-glob: "npm:^3.2.2"
@@ -7948,16 +7948,6 @@ __metadata:
79487948
languageName: node
79497949
linkType: hard
79507950

7951-
"chalk@npm:^3.0.0":
7952-
version: 3.0.0
7953-
resolution: "chalk@npm:3.0.0"
7954-
dependencies:
7955-
ansi-styles: "npm:^4.1.0"
7956-
supports-color: "npm:^7.1.0"
7957-
checksum: 10/37f90b31fd655fb49c2bd8e2a68aebefddd64522655d001ef417e6f955def0ed9110a867ffc878a533f2dafea5f2032433a37c8a7614969baa7f8a1cd424ddfc
7958-
languageName: node
7959-
linkType: hard
7960-
79617951
"chalk@npm:^4.0.0, chalk@npm:^4.1.0, chalk@npm:^4.1.2":
79627952
version: 4.1.2
79637953
resolution: "chalk@npm:4.1.2"

0 commit comments

Comments
Β (0)