Skip to content
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

CLI: Migrate from chalk to picocolors #28262

Merged
merged 24 commits into from
Oct 1, 2024
Merged

Conversation

43081j
Copy link
Contributor

@43081j 43081j commented Jun 17, 2024

This migrates away from chalk to picocolors instead, primarily because the latter is much lighter.

Keep in mind, node-logger still uses chalk as we use hex(code) which doesn't have an alternative in picocolors. This means it will still be in the dependency tree for many packages (for now).

This seems preferable over upgrading chalk since the latest version of chalk will still be heavier, and is ESM-only (not sure if we're able to adopt ESM only deps in SB yet).

This is a pretty big PR thanks to the CLI in particular. If you'd prefer I split it up into individual PRs, or at least separate out the CLI change, let me know and i'll do some git-fu

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests (should already be covered)
  • integration tests
  • end-to-end tests

Manual testing

Run the CLI and observe that the colours are still working as expected.

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

This migrates away from chalk to picocolors instead, primarily because
the latter is _much_ lighter.

Keep in mind, `node-logger` still uses chalk as we use `hex(code)` which
doesn't have an alternative in picocolors. This means it will still be
in the dependency tree for many packages (for now).

This seems preferable over upgrading chalk since the latest version of
chalk will still be heavier, and is ESM-only (not sure if we're able to
adopt ESM only deps in SB yet).
@43081j
Copy link
Contributor Author

43081j commented Jun 17, 2024

I'm on the go right now and my current laptop feels like it'll melt when i try the test runs. So its possible i have pushed pre-emptively and tests are not happy, partially relying on CI.

Will make it a draft if CI fails and i'll get back to it later this week

Edit: looks like a type check failed. I'll roll that package back for now if I don't figure an alternative fix out

Copy link

nx-cloud bot commented Jun 17, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 3919b23. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

@shilman shilman added dependencies maintenance User-facing maintenance tasks ci:normal labels Jun 18, 2024
@shilman shilman changed the title feat: migrate from chalk to picocolors CLI: Migrate from chalk to picocolors Jun 18, 2024
@shilman
Copy link
Member

shilman commented Jun 18, 2024

@43081j Thanks so much for doing this! Re: the breaking change, can we just switch e.g. pink: chalk.hex('F1618C')' to pink: picocolors.pink`? Having a fat package AND a slim package sounds like it could be worse than having a single fat package.

@43081j
Copy link
Contributor Author

43081j commented Jun 18, 2024

@43081j Thanks so much for doing this! Re: the breaking change, can we just switch e.g. pink: chalk.hex('F1618C')' to pink: picocolors.pink`? Having a fat package AND a slim package sounds like it could be worse than having a single fat package.

I think so yeah. If we can switch each of the hex colours to fixed colours, that would be great

Meanwhile, the build failure is because picocolours doesn't have bright colours yet. I'm going to try go upstream and help get that into picocolours before we land this

@shilman shilman changed the title CLI: Migrate from chalk to picocolors CLI: Migrate from chalk to picocolors Jun 23, 2024
@43081j
Copy link
Contributor Author

43081j commented Jul 30, 2024

minor update: we're just waiting for picocolors to ship a new version with bright colours enabled

it has been merged but no release has been cut yet. ill try help them out over there and will update this once it gets released

@43081j
Copy link
Contributor Author

43081j commented Sep 3, 2024

picocolors has bright variants now so i've tried to update and catch up from next

will see how CI goes and re-review the diff when I can

Copy link
Contributor

@JReinhold JReinhold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me, I can help out with the merge conflicts.

@@ -317,7 +317,8 @@
"prep": "jiti ../../../scripts/prepare/bundle.ts"
},
"dependencies": {
"@storybook/core": "workspace:*"
"@storybook/core": "workspace:*",
"picocolors": "^1.1.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was added by mistake.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remember to remove this too.

@JReinhold
Copy link
Contributor

JReinhold commented Sep 17, 2024

Strictly speaking we can't actually replace these chalk colors with picocolors, because the APIs are not compatible, and the colors export is a "public API" in node-logger (not documented). So even if we did find matches for chalk.pink in picocolors, it wouldn't work exactly the same, because chalk allows you to do colors.pink.bold("...") while picocolors requires colors.pink(picocolors.bold("...")).

export const colors = {
pink: chalk.hex('F1618C'),
purple: chalk.hex('B57EE5'),
orange: chalk.hex('F3AD38'),
green: chalk.hex('A2E05E'),
blue: chalk.hex('6DABF5'),
red: chalk.hex('F16161'),
gray: chalk.gray,
};

However, A GitHub-wide search shows zero usage of this API outside of Storybook or forks of it. This doesn't mean that no-one is using it privately, we can't know that of course.

These are all old forks:
https://github.com/search?q=/%5E.*colors.*from%5Cs+%5B'%22'%5D@storybook%5C/node-logger%5B'%22'%5D.*$/+-org:storybookjs+-is:fork&type=code

We do use the exported colors plenty both in the monorepo and in a few sattelite packages: https://github.com/search?q=/%5E.*colors.*from%5Cs+%5B'%22'%5D@storybook%5C/node-logger%5B'%22'%5D.*$/+org:storybookjs&type=code&p=1

I'd vote for completely removing the export now and update the usage across the monorepo and satellite packages. A middleground would be to replace them with picocolors equivalent to keep the colors.pink("...") usage intact and only break colors.pink.bold("...") instances.

Thoughts @shilman ?

@43081j
Copy link
Contributor Author

43081j commented Sep 18, 2024

I would probably lean towards removing the export too. otherwise, whatever library we choose, we're tying our public API to it which isn't great

I think we should avoid re-exporting/exposing dependencies in our public API if we can

@shilman
Copy link
Member

shilman commented Sep 19, 2024

Agree with both of you @JReinhold @43081j -- sorry for the slow reply!

@JReinhold JReinhold assigned ndelangen and unassigned shilman Sep 30, 2024
Copy link
Contributor

@JReinhold JReinhold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code looks good to me, but a few stray dependencies have snuck their way into various package.jsons

code/addons/test/package.json Outdated Show resolved Hide resolved
code/lib/create-storybook/package.json Outdated Show resolved Hide resolved
@@ -138,11 +137,13 @@
"knip": "^5.30.1",
"lint-staged": "^15.2.7",
"memoizerific": "^1.11.3",
"minimatch": "^10.0.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see usage of this anywhere in the repo

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The knip config file references it... I ran lint on scripts and this came up.

@@ -317,7 +317,8 @@
"prep": "jiti ../../../scripts/prepare/bundle.ts"
},
"dependencies": {
"@storybook/core": "workspace:*"
"@storybook/core": "workspace:*",
"picocolors": "^1.1.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remember to remove this too.

@ndelangen ndelangen merged commit 70d8f4d into storybookjs:next Oct 1, 2024
52 checks passed
@github-actions github-actions bot mentioned this pull request Oct 1, 2024
7 tasks
@43081j 43081j deleted the chalkless branch October 1, 2024 17:42
@nspector
Copy link

FYI this introduced a regression in @storybook/addon-styling-webpack - storybookjs/addon-styling-webpack#24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:normal maintenance User-facing maintenance tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants