diff --git a/lib/internal/tty.js b/lib/internal/tty.js index 98975fa68a436f..44d51737008eb0 100644 --- a/lib/internal/tty.js +++ b/lib/internal/tty.js @@ -73,18 +73,26 @@ const TERM_ENVS_REG_EXP = [ /^vt100/ ]; +let warned = false; function warnOnDeactivatedColors(env) { - let name; + if (warned) + return; + let name = ''; if (env.NODE_DISABLE_COLORS !== undefined) name = 'NODE_DISABLE_COLORS'; - if (env.NO_COLOR !== undefined) - name = 'NO_COLOR'; + if (env.NO_COLOR !== undefined) { + if (name !== '') { + name += "' and '"; + } + name += 'NO_COLOR'; + } - if (name !== undefined) { + if (name !== '') { process.emitWarning( `The '${name}' env is ignored due to the 'FORCE_COLOR' env being set.`, 'Warning' ); + warned = true; } } diff --git a/test/pseudo-tty/test-tty-color-support-warning-2.js b/test/pseudo-tty/test-tty-color-support-warning-2.js new file mode 100644 index 00000000000000..34ba49c0dfd1b5 --- /dev/null +++ b/test/pseudo-tty/test-tty-color-support-warning-2.js @@ -0,0 +1,8 @@ +'use strict'; + +require('../common'); + +process.env.NODE_DISABLE_COLORS = '1'; +process.env.FORCE_COLOR = '3'; + +console.log(); diff --git a/test/pseudo-tty/test-tty-color-support-warning-2.out b/test/pseudo-tty/test-tty-color-support-warning-2.out new file mode 100644 index 00000000000000..cd57b3f9f69672 --- /dev/null +++ b/test/pseudo-tty/test-tty-color-support-warning-2.out @@ -0,0 +1,2 @@ + +(node:*) Warning: The 'NODE_DISABLE_COLORS' env is ignored due to the 'FORCE_COLOR' env being set. diff --git a/test/pseudo-tty/test-tty-color-support-warning.js b/test/pseudo-tty/test-tty-color-support-warning.js new file mode 100644 index 00000000000000..ae164958d2d6b9 --- /dev/null +++ b/test/pseudo-tty/test-tty-color-support-warning.js @@ -0,0 +1,9 @@ +'use strict'; + +require('../common'); + +process.env.NO_COLOR = '1'; +process.env.NODE_DISABLE_COLORS = '1'; +process.env.FORCE_COLOR = '3'; + +console.log(); diff --git a/test/pseudo-tty/test-tty-color-support-warning.out b/test/pseudo-tty/test-tty-color-support-warning.out new file mode 100644 index 00000000000000..9360ae1328b2cd --- /dev/null +++ b/test/pseudo-tty/test-tty-color-support-warning.out @@ -0,0 +1,2 @@ + +(node:*) Warning: The 'NODE_DISABLE_COLORS' and 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set. diff --git a/test/pseudo-tty/test-tty-color-support.out b/test/pseudo-tty/test-tty-color-support.out index f73fbdcd9651f6..e6904d10b8a7b8 100644 --- a/test/pseudo-tty/test-tty-color-support.out +++ b/test/pseudo-tty/test-tty-color-support.out @@ -1,8 +1 @@ (node:*) Warning: The 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set. -(node:*) Warning: The 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set. -(node:*) Warning: The 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set. -(node:*) Warning: The 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set. -(node:*) Warning: The 'NODE_DISABLE_COLORS' env is ignored due to the 'FORCE_COLOR' env being set. -(node:*) Warning: The 'NODE_DISABLE_COLORS' env is ignored due to the 'FORCE_COLOR' env being set. -(node:*) Warning: The 'NODE_DISABLE_COLORS' env is ignored due to the 'FORCE_COLOR' env being set. -(node:*) Warning: The 'NODE_DISABLE_COLORS' env is ignored due to the 'FORCE_COLOR' env being set.