yarnpkg / berry

📦🐈 Active development trunk for Yarn ⚒
https://yarnpkg.com
BSD 2-Clause "Simplified" License
7.39k stars 1.11k forks source link

[Feature] Proper support of enableColors config option #4353

Open stylemistake opened 2 years ago

stylemistake commented 2 years ago

Describe the user story

I often run Yarn as part of a build pipeline, often in parallel, both in CI and locally on a dev machine, where Yarn doesn't have access to TTY. It is very desirable to have support for colors when you can ensure that terminal supports it regardless of TTY checks.

Documentation for .yarnrc.yml has the following:

enableColors: true

If true (by default detects terminal capabilities), Yarn will format its pretty-print its output by using colors to differentiate important parts of its messages.

Well, the problem is that when TTY is not present, this option is completely ignored (not really, but kind of yes), which is kinda against documentation.

You can reproduce it with something like this:

YARN_ENABLE_COLORS=true yarn install | cat

image image


The only exception to this is the yarn config module, which prints out colors successfully (but not for the > YN0000 part).

image image image


Describe the solution you'd like

That's the hard part, because I initially thought this was a bug, but the more I look into the code, it appears more like a missing feature. The only code that respects the enableColors config option is the formatUtils module, and formatUtils seems to be barely used anywhere (correct me if I'm wrong).

Would be nice if all formatting code was aware of this option.

Describe the drawbacks of your solution

Might require a lot of actual work instead of fixing a small issue.

Describe alternatives you've considered

Perhaps it could be overridden globally on chalk module level, and all code that depends on chalk would automatically output in colors in respect to that setting.

arcanis commented 2 years ago

formatUtils is used everywhere, for example the message name here: https://github.com/yarnpkg/berry/blob/master/packages/yarnpkg-core/sources/StreamReport.ts#L91

legobeat commented 2 months ago

On the flip side, today we still see the option ignored but to the opposite effect:

Colored output is enabled in GitHub Actions (making testing of process output an unnecessary hassle) and setting YARN_ENABLE_COLORS=false env var does not take any effect.

Can not reproduce it locally. It seems like chalk colors are force-enabled if yarn detects running in GitHub Actions. Surprising.

https://github.com/yarnpkg/berry/blob/13d5b3041794c33171808fdce635461ff4ab5c4e/packages/yarnpkg-core/sources/formatUtils.ts#L66-L70