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 picocolors #2717

Closed

Conversation

kravetsone
Copy link
Contributor

@kravetsone kravetsone commented Jul 31, 2024

Replace chalk with picocolors for better perfomance and reduce bundle size.

Benchmarks from picocolors repo

Benchmarks

The space in node_modules including sub-dependencies:

$ node ./benchmarks/size.js
Data from packagephobia.com
  chalk       101 kB
  cli-color  1249 kB
  ansi-colors  25 kB
  kleur        21 kB
  colorette    17 kB
  nanocolors   16 kB
+ picocolors    7 kB

Library loading time:

$ node ./benchmarks/loading.js
  chalk          6.167 ms
  cli-color     31.431 ms
  ansi-colors    1.585 ms
  kleur          2.008 ms
  kleur/colors   0.773 ms
  colorette      2.476 ms
  nanocolors     0.833 ms
+ picocolors     0.466 ms

Benchmark for simple use case:

$ node ./benchmarks/simple.js
  chalk         24,066,342 ops/sec
  cli-color        938,700 ops/sec
  ansi-colors    4,532,542 ops/sec
  kleur         20,343,122 ops/sec
  kleur/colors  35,415,770 ops/sec
  colorette     34,244,834 ops/sec
  nanocolors    33,443,265 ops/sec
+ picocolors    33,271,645 ops/sec

Benchmark for complex use cases:

$ node ./benchmarks/complex.js
  chalk            969,915 ops/sec
  cli-color        131,639 ops/sec
  ansi-colors      342,250 ops/sec
  kleur            611,880 ops/sec
  kleur/colors   1,129,526 ops/sec
  colorette      1,747,277 ops/sec
  nanocolors     1,251,312 ops/sec
+ picocolors     2,024,086 ops/sec

But it blocked by alexeyraspopov/picocolors#55

tsc --noEmit
src/cli/commands/migrate.ts:283:14 - error TS2339: Property 'blueBright' does not exist on type 'Colors & { createColors: (enabled?: boolean | undefined) => Colors; }'.

283         pico.blueBright(
                 ~~~~~~~~~~

src/cli/commands/migrate.ts:287:14 - error TS2339: Property 'blueBright' does not exist on type 'Colors & { createColors: (enabled?: boolean | undefined) => Colors; }'.

287         pico.blueBright(
                 ~~~~~~~~~~

src/cli/validations/outputs.ts:6:36 - error TS2551: Property 'bgGray' does not exist on type 'Colors & { createColors: (enabled?: boolean | undefined) => Colors; }'. Did you mean 'gray'?

6  warning: (str: string) => `${pico.bgGray(pico.white(' Warning '))} ${str}`,
                                     ~~~~~~

  ../node_modules/.pnpm/[email protected]/node_modules/picocolors/types.ts:21:2
    21  gray: Formatter
        ~~~~
    'gray' is declared here.

src/cli/validations/outputs.ts:9:39 - error TS2551: Property 'bgGray' does not exist on type 'Colors & { createColors: (enabled?: boolean | undefined) => Colors; }'. Did you mean 'gray'?

9  suggestion: (str: string) => `${pico.bgGray(pico.white(' Suggestion '))} ${str}`,
                                        ~~~~~~

  ../node_modules/.pnpm/[email protected]/node_modules/picocolors/types.ts:21:2
    21  gray: Formatter
        ~~~~
    'gray' is declared here.

src/serializer/pgSerializer.ts:351:15 - error TS2339: Property 'blueBright' does not exist on type 'Colors & { createColors: (enabled?: boolean | undefined) => Colors; }'.

351          pico.blueBright(
                  ~~~~~~~~~~

src/serializer/pgSerializer.ts:355:15 - error TS2339: Property 'blueBright' does not exist on type 'Colors & { createColors: (enabled?: boolean | undefined) => Colors; }'.

355          pico.blueBright(
                  ~~~~~~~~~~

src/serializer/pgSerializer.ts:359:15 - error TS2339: Property 'blueBright' does not exist on type 'Colors & { createColors: (enabled?: boolean | undefined) => Colors; }'.

359          pico.blueBright(
                  ~~~~~~~~~~

Some colors are not available (and the package version with them has not been published) we can replace them or wait for 1.1.0

SImillar pull requests/issues

I love you Drizzle!

Replace `chalk` with `picocolors` for better perfomance and reduce bundle size
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.

2 participants