Fix FORCE_COLOR override when COLORTERM is set

When COLORTERM=truecolor is set, FORCE_COLOR=1 and FORCE_COLOR=2 were both returning level 3 instead of respecting the specified level. This happened because terminal detection (checking for COLORTERM) was running after FORCE_COLOR was parsed, overriding the explicit user preference.

The fix adds an early return when FORCE_COLOR is explicitly set, preventing any terminal detection logic from overriding the user's choice. This ensures FORCE_COLOR takes priority over automatic terminal capability detection.

Fixes #624
This commit is contained in:
Varun Chawla 2026-02-13 00:50:03 -08:00
parent aa06bb5ac3
commit dab86650a7

View file

@ -81,6 +81,12 @@ function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
}
}
// If FORCE_COLOR is explicitly set, return it immediately
// to prevent terminal detection from overriding it
if (forceColor !== undefined) {
return forceColor;
}
// Check for Azure DevOps pipelines.
// Has to be above the `!streamIsTTY` check.
if ('TF_BUILD' in env && 'AGENT_NAME' in env) {