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

Replace Chalk with Kleur #2113

Merged
merged 1 commit into from
Nov 21, 2021
Merged

Replace Chalk with Kleur #2113

merged 1 commit into from
Nov 21, 2021

Conversation

dgrammatiko
Copy link
Contributor

@dgrammatiko dgrammatiko commented Nov 20, 2021

A simple switch of a cli dependency

Why?

  • Kleur is smaller (theoretically better(?) for the serverless)

Screenshot 2021-11-20 at 22 41 46

  • Kleur is more performant

Screenshot 2021-11-20 at 23 23 12

  • it has no further dependencies

  • Micro optimisation? Maybe, maybe not...

Signed-off-by: dgrammatiko <d.grammatiko@gmail.com>
@zachleat zachleat merged commit 1309db4 into 11ty:master Nov 21, 2021
@zachleat zachleat added this to the Eleventy 1.0.0 milestone Nov 21, 2021
@zachleat
Copy link
Member

Seems great to me, thanks!

@TigersWay
Copy link
Contributor

There's quite some choice to replace chalk. But is that the best one really? I found quite different numbers around... Do you want small or fast?

@dgrammatiko
Copy link
Contributor Author

dgrammatiko commented Nov 21, 2021

@TigersWay small size and no dependencies were my goals here but I guess the rabbit hole is deeper. So, some further research on styling the cli revealed these options:

  • Chalk has 2 dependencies, it's the most popular pkg
    Screenshot 2021-11-21 at 13 29 03

  • kleur has 0 dependencies, it's also popular and has better performance
    Screenshot 2021-11-21 at 13 30 45

  • But colorette has also 0 dependencies, it's smaller and more performant (according their benchmarks)
    Screenshot 2021-11-21 at 13 31 59

  • But then picocolors has also 0 dependencies, it's even smaller more performant and used by PostCSS and Autoprefixer
    Screenshot 2021-11-21 at 13 34 41

Screenshot 2021-11-21 at 13 48 32

@zachleat since all these are interchangeable packages let me know if you want me to create a new PR switching to picocolors (or any other package that you think it's a better fit)

@dgrammatiko dgrammatiko deleted the replace-chalk-kleur branch November 21, 2021 12:39
@TigersWay
Copy link
Contributor

@dgrammatiko You have them all 😄 Thanks!

colorette and the recent picolors are clearly both small and much faster than chalk, which is A LOT more used.....
Another choice to make 😇

@pdehaan
Copy link
Contributor

pdehaan commented Nov 21, 2021

This is giving me babel/babel#13783 (and eslint/eslint#15102) flashbacks.

I think the best point in the Babel thread was Sindre's comment: babel/babel#13783 (comment)

Also, Chalk is such a common dependency that it's usually already somewhere in the dependency tree on most projects anyway. So Chalk is often 0 kB.

Also interesting is that if you do a brand new Eleventy 0.12.1 install, the node_modules directory is ~76MB (on macOS at least), so not sure we we're saving by reducing the package size by 5KB.

Looking at the dependency tree, it looks like @11ty/eleventy 0.12.x includes chalk 3 times, but all very different versions.

npm ls chalk

tmp@1.0.0 /private/tmp/11ty-size
└─┬ @11ty/eleventy@0.12.1
  ├─┬ browser-sync@2.27.7
  │ └─┬ eazy-logger@3.1.0
  │   └─┬ tfunk@4.0.0
  │     └── chalk@1.1.3
  ├── chalk@4.1.2
  └─┬ time-require@0.1.2
    └── chalk@0.4.0

And @11ty/eleventy 1.0.0-beta.8 includes chalk 4 times, each with a different major version number.

npm ls chalk

11ty-size@1.0.0 /private/tmp/11ty-size
└─┬ @11ty/eleventy@1.0.0-beta.8
  ├─┬ browser-sync@2.27.7
  │ └─┬ eazy-logger@3.1.0
  │   └─┬ tfunk@4.0.0
  │     └── chalk@1.1.3
  ├── chalk@4.1.2
  ├─┬ ejs@3.1.6
  │ └─┬ jake@10.8.2
  │   └── chalk@2.4.2
  └─┬ time-require@0.1.2
    └── chalk@0.4.0

@dgrammatiko
Copy link
Contributor Author

This is giving me babel/babel#13783 (and eslint/eslint#15102) flashbacks.

What have I done? 😒 I was genuinely unaware of these PRs...

And @11ty/eleventy 1.0.0-beta.8 includes chalk 4 times, each with a different major version number.

Yes, but that's due to other dependencies, as you already showcasing by the dep tree graph. Also if chalk was a direct dependency (as it was before this PR) there would be 5 copies of the library.

@zachleat
Copy link
Member

Are we still okay that this PR was merged? I don’t think we need to belabor this too much, kleur seems like an improvement over chalk, is reasonably popular, and is maintained by a Cloudflare dev so it seems pretty safe to me.

@pdehaan
Copy link
Contributor

pdehaan commented Nov 22, 2021

No objections here. Looking at the dep trees above, it looks like chalk@4 wasn't already in the tree anyways. 👍

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.

4 participants