diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2020-01-20 23:37:14 +0300 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2020-02-09 15:39:56 +0300 |
commit | 63f10b9f0da0539b499a076f2951526ecae8260a (patch) | |
tree | 8a21fd505067f3554a023e691eb9ca86baa89424 /lib/internal/tty.js | |
parent | 0f6fed4f070391563c40a6c88d25deb734785274 (diff) |
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>
Diffstat (limited to 'lib/internal/tty.js')
-rw-r--r-- | lib/internal/tty.js | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/internal/tty.js b/lib/internal/tty.js index 98975fa68a4..44d51737008 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; } } |