mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
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:
parent
0f6fed4f07
commit
63f10b9f0d
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
8
test/pseudo-tty/test-tty-color-support-warning-2.js
Normal file
8
test/pseudo-tty/test-tty-color-support-warning-2.js
Normal file
@ -0,0 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
|
||||
process.env.NODE_DISABLE_COLORS = '1';
|
||||
process.env.FORCE_COLOR = '3';
|
||||
|
||||
console.log();
|
2
test/pseudo-tty/test-tty-color-support-warning-2.out
Normal file
2
test/pseudo-tty/test-tty-color-support-warning-2.out
Normal file
@ -0,0 +1,2 @@
|
||||
|
||||
(node:*) Warning: The 'NODE_DISABLE_COLORS' env is ignored due to the 'FORCE_COLOR' env being set.
|
9
test/pseudo-tty/test-tty-color-support-warning.js
Normal file
9
test/pseudo-tty/test-tty-color-support-warning.js
Normal file
@ -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();
|
2
test/pseudo-tty/test-tty-color-support-warning.out
Normal file
2
test/pseudo-tty/test-tty-color-support-warning.out
Normal file
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user