Skip to content

tty: treat empty NO_COLOR same as absent NO_COLOR #58074

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

aduh95
Copy link
Contributor

@aduh95 aduh95 commented Apr 29, 2025

As specified in https://no-color.org/, setting the env variable to an empty string should result in that env variable to be ignored:

Command-line software which adds ANSI color to its output by default should check for a NO_COLOR environment variable that, when present and not an empty string (regardless of its value), prevents the addition of ANSI color.

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. tty Issues and PRs related to the tty subsystem. labels Apr 29, 2025
Copy link

codecov bot commented Apr 29, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.21%. Comparing base (a36981a) to head (59fbe0d).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #58074      +/-   ##
==========================================
- Coverage   90.21%   90.21%   -0.01%     
==========================================
  Files         630      630              
  Lines      186391   186391              
  Branches    36608    36608              
==========================================
- Hits       168161   168150      -11     
- Misses      11052    11061       +9     
- Partials     7178     7180       +2     
Files with missing lines Coverage Δ
lib/internal/tty.js 99.15% <100.00%> (ø)

... and 25 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
@@ -82,9 +82,9 @@ function warnOnDeactivatedColors(env) {
if (warned)
return;
let name = '';
if (env.NODE_DISABLE_COLORS !== undefined)
Copy link
Member

Choose a reason for hiding this comment

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

These entries could (IMO should) all be simplified by just checking for truthiness. An env may only be undefined or a string due to the internal setter, no matter that e.g., null is assigned. It would result in 'null'.

Copy link
Member

@BridgeAR BridgeAR Apr 30, 2025

Choose a reason for hiding this comment

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

Thinking about it again: a user may pass through arbitrary values as environment variables. If a zero would for example be passed through, it would now be handled as not defined, while it would be picked up as process.env (being transformed to a string before).

So maybe we should just handle it as the stringified version? As in: env.FOO?.toString()? I am somewhat indecisive about how to handle this case ideally.

@BridgeAR BridgeAR added the semver-major PRs that contain breaking changes and should be released in the next major version. label Apr 29, 2025
@aduh95
Copy link
Contributor Author

aduh95 commented Apr 29, 2025

@BridgeAR is it semver-major or just a fix? Wdyt about not landing it on LTS release lines to minimize the risk of ecosystem breakage, but still land it on Current release line?

@BridgeAR
Copy link
Member

@aduh95 I think it's fine to land it on 24 or do you mean any release before?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-ci PRs that need a full CI run. semver-major PRs that contain breaking changes and should be released in the next major version. tty Issues and PRs related to the tty subsystem.
5 participants