Skip to content

Commit edc5d7d

Browse files
authored
Fix: CLI flags and FORCE_COLOR should precede other color support checks (#154)
1 parent d4f413e commit edc5d7d

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
6565

6666
const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
6767

68-
if (forceColor === 0) {
69-
return 0;
68+
if (forceColor !== undefined) {
69+
return forceColor;
7070
}
7171

7272
if (sniffFlags) {
@@ -91,7 +91,7 @@ function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
9191
return 0;
9292
}
9393

94-
const min = forceColor || 0;
94+
const min = 0;
9595

9696
if (env.TERM === 'dumb') {
9797
return min;

test.js

+16
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,22 @@ test('return true if `FORCE_COLOR` is in env, but honor 256 #2', t => {
4646
t.is(result.stdout.level, 2);
4747
});
4848

49+
test('CLI color flags precede other color support checks', t => {
50+
process.env.COLORTERM = 'truecolor';
51+
process.argv = ['--color=256'];
52+
const result = importFresh('./index.js');
53+
t.truthy(result.stdout);
54+
t.is(result.stdout.level, 2)
55+
});
56+
57+
test('`FORCE_COLOR` environment variable precedes other color support checks', t => {
58+
process.env.COLORTERM = 'truecolor';
59+
process.env.FORCE_COLOR = '2';
60+
const result = importFresh('./index.js');
61+
t.truthy(result.stdout);
62+
t.is(result.stdout.level, 2)
63+
});
64+
4965
test('return false if `FORCE_COLOR` is in env and is 0', t => {
5066
process.env.FORCE_COLOR = '0';
5167
const result = importFresh('./index.js');

0 commit comments

Comments
 (0)