Skip to content

Comments

Vendor chalk and supports-color#659

Open
jfmengels wants to merge 34 commits intortfeldman:masterfrom
jfmengels:chalk-pr
Open

Vendor chalk and supports-color#659
jfmengels wants to merge 34 commits intortfeldman:masterfrom
jfmengels:chalk-pr

Conversation

@jfmengels
Copy link
Contributor

Vendors the chalk dependency, getting rid of a few indirect dependencies too.
chalk does quite a lot of complicated work to enable complex usages (chalk.blue.underline(...), template literals, ...), whereas we only use it to do chalk.red() and chalk.blue() (and that's it).

We also chalk it to figure out whether the output supports colors, but that is handled by the sub-dependency supports-color.

I've vendored both dependencies, and simplified them. chalk is now extremely simple, and supports-color is simplified a bit (I've done it in steps for it to be understandable, or even replicable later). Simplifying these dependencies mean startup should be faster 🤞

I'm still on the fence for vendoring supports-color (but leaning towards doing it) as we will now receive new updates for it. That said, the latest version is already incompatible with this CLI, as it's ESM only. Therefore we won't get any updates until we switch to ESM (thereby dropping Node.js v12 compatibility).

Copy link
Collaborator

@lydell lydell left a comment

Choose a reason for hiding this comment

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

Great! Pretty funny that we depended on a whole library plus sub dependencies just to make some text blue and red 😅

@lydell
Copy link
Collaborator

lydell commented Feb 20, 2026

I think we should go one step further with supports-color and simplify it even more.

This is what we have documented:

https://github.com/rtfeldman/node-test-runner#--no-color

Disable colored console output.

Colors are also disabled when you pipe the output of elm-test to another program. You can use --color to force the colors back.

Alternatively, you can set the environment variable FORCE_COLOR to 0 to disable colors, or to any other value to force them.

We only allow --color and --no-color. --no-colors, --color=always etc are errors (I tested it just now).

So I think we only need to take into account:

  • process.stdout.isTTY
  • FORCE_COLOR=0 and FORCE_COLOR set to not-zero (empty string seems to mean that the env var is ignored?)
  • --color/--no-color. See
    // `chalk.supportsColor` looks at `process.argv` for these flags.
    // We still need to define them so they appear in `--help` and aren’t
    // treated as unknown flags.
    .option(
    '--no-color',
    'Disable colored console output (setting FORCE_COLOR=0 also works)'
    )
    .option(
    '--color',
    'Force colored console output (setting FORCE_COLOR to anything but 0 also works)'
    )

I think we can assume that all terminals these days, including cmd.exe and CI services, support basic blue and red.

@jfmengels
Copy link
Contributor Author

jfmengels commented Feb 21, 2026

Yes that sounds good 👍

I've simplified it a bit more with your suggestions. We can simplify more but that would probably mean being slightly incorrect in some corner case/environment, and I don't feel confident calling the shot. Feel free to edit this further!

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