tty: do not end in an infinite warning recursion

It was possible that this warning ends up in an infinite recursion.
The reason is that printing the warning triggered a color check and
that triggered another warning. Limiting it to a single warning
prevents this.

PR-URL: https://github.com/nodejs/node/pull/31429
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
Ruben Bridgewater authored and Shelley Vohr committed 2020-02-17 12:21:39 -08:00
1 parent 58f17c0e6b
commit be55f3ec4f
6 files changed
+33 -11

No files matched your search

+12 -4
View File
@@ -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;
}
}
@@ -0,0 +1,8 @@
'use strict';
require('../common');
process.env.NODE_DISABLE_COLORS = '1';
process.env.FORCE_COLOR = '3';
console.log();
@@ -0,0 +1,2 @@
(node:*) Warning: The 'NODE_DISABLE_COLORS' env is ignored due to the 'FORCE_COLOR' env being set.
@@ -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();
@@ -0,0 +1,2 @@
(node:*) Warning: The 'NODE_DISABLE_COLORS' and 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set.
@@ -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.