From 2d77ba5d30b591a9e4aa7726468452642f19151c Mon Sep 17 00:00:00 2001 From: Aviv Keller Date: Sat, 28 Sep 2024 09:50:39 -0400 Subject: [PATCH] Revert "console: colorize console error and warn" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit a833c9e0bed85214884d6650fe344d5896c9e67a. PR-URL: https://github.com/nodejs/node/pull/54677 Reviewed-By: Joyee Cheung Reviewed-By: Michaƫl Zasso --- lib/internal/console/constructor.js | 25 ++++--------------- test/parallel/test-repl.js | 2 +- .../test-tty-color-support-warning-2.out | 4 +-- .../test-tty-color-support-warning.out | 4 +-- test/pseudo-tty/test-tty-color-support.out | 4 +-- 5 files changed, 12 insertions(+), 27 deletions(-) diff --git a/lib/internal/console/constructor.js b/lib/internal/console/constructor.js index c892b91919d..d3535fa5b6a 100644 --- a/lib/internal/console/constructor.js +++ b/lib/internal/console/constructor.js @@ -8,7 +8,6 @@ const { ArrayIsArray, ArrayPrototypeForEach, ArrayPrototypePush, - ArrayPrototypeSome, ArrayPrototypeUnshift, Boolean, ErrorCaptureStackTrace, @@ -60,7 +59,6 @@ const { const { CHAR_UPPERCASE_C: kTraceCount, } = require('internal/constants'); -const { styleText } = require('util'); const kCounts = Symbol('counts'); const { time, timeLog, timeEnd, kNone } = require('internal/util/debuglog'); @@ -264,7 +262,7 @@ ObjectDefineProperties(Console.prototype, { [kWriteToConsole]: { __proto__: null, ...consolePropAttributes, - value: function(streamSymbol, string, color = '') { + value: function(streamSymbol, string) { const ignoreErrors = this._ignoreErrors; const groupIndent = internalIndentationMap.get(this) || ''; @@ -279,11 +277,6 @@ ObjectDefineProperties(Console.prototype, { } string = groupIndent + string; } - - if (color) { - string = styleText(color, string); - } - string += '\n'; if (ignoreErrors === false) return stream.write(string); @@ -382,15 +375,12 @@ const consoleMethods = { log(...args) { this[kWriteToConsole](kUseStdout, this[kFormatForStdout](args)); }, + + warn(...args) { - const color = (shouldColorize(args) && 'yellow') || ''; - this[kWriteToConsole](kUseStderr, this[kFormatForStderr](args), color); + this[kWriteToConsole](kUseStderr, this[kFormatForStderr](args)); }, - error(...args) { - const color = (shouldColorize(args) && 'red') || ''; - this[kWriteToConsole](kUseStderr, this[kFormatForStderr](args), color); - }, dir(object, options) { this[kWriteToConsole](kUseStdout, inspect(object, { @@ -621,12 +611,6 @@ const iterKey = '(iteration index)'; const isArray = (v) => ArrayIsArray(v) || isTypedArray(v) || isBuffer(v); -// TODO: remove string type check once the styleText supports objects -// Return true if all args are type string -const shouldColorize = (args) => { - return lazyUtilColors().hasColors && !ArrayPrototypeSome(args, (arg) => typeof arg !== 'string'); -}; - function noop() {} for (const method of ReflectOwnKeys(consoleMethods)) @@ -635,6 +619,7 @@ for (const method of ReflectOwnKeys(consoleMethods)) Console.prototype.debug = Console.prototype.log; Console.prototype.info = Console.prototype.log; Console.prototype.dirxml = Console.prototype.log; +Console.prototype.error = Console.prototype.warn; Console.prototype.groupCollapsed = Console.prototype.group; function initializeGlobalConsole(globalConsole) { diff --git a/test/parallel/test-repl.js b/test/parallel/test-repl.js index 3b885936496..610c7813e04 100644 --- a/test/parallel/test-repl.js +++ b/test/parallel/test-repl.js @@ -793,7 +793,6 @@ const errorTests = [ 'Object [console] {', ' log: [Function: log],', ' warn: [Function: warn],', - ' error: [Function: error],', ' dir: [Function: dir],', ' time: [Function: time],', ' timeEnd: [Function: timeEnd],', @@ -809,6 +808,7 @@ const errorTests = [ / {2}debug: \[Function: (debug|log)],/, / {2}info: \[Function: (info|log)],/, / {2}dirxml: \[Function: (dirxml|log)],/, + / {2}error: \[Function: (error|warn)],/, / {2}groupCollapsed: \[Function: (groupCollapsed|group)],/, / {2}Console: \[Function: Console],?/, ...process.features.inspector ? [ diff --git a/test/pseudo-tty/test-tty-color-support-warning-2.out b/test/pseudo-tty/test-tty-color-support-warning-2.out index 61a1baa0b54..37b470a5f10 100644 --- a/test/pseudo-tty/test-tty-color-support-warning-2.out +++ b/test/pseudo-tty/test-tty-color-support-warning-2.out @@ -1,3 +1,3 @@ -*(node:*) Warning: The 'NODE_DISABLE_COLORS' env is ignored due to the 'FORCE_COLOR' env being set. -(Use `* --trace-warnings ...` to show where the warning was created)* +(node:*) Warning: The 'NODE_DISABLE_COLORS' env is ignored due to the 'FORCE_COLOR' env being set. +(Use `* --trace-warnings ...` to show where the warning was created) diff --git a/test/pseudo-tty/test-tty-color-support-warning.out b/test/pseudo-tty/test-tty-color-support-warning.out index 35ed65c96d2..b25d2e42cf7 100644 --- a/test/pseudo-tty/test-tty-color-support-warning.out +++ b/test/pseudo-tty/test-tty-color-support-warning.out @@ -1,3 +1,3 @@ -*(node:*) Warning: The 'NODE_DISABLE_COLORS' and 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set. -(Use `* --trace-warnings ...` to show where the warning was created)* +(node:*) Warning: The 'NODE_DISABLE_COLORS' and 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set. +(Use `* --trace-warnings ...` to show where the warning was created) diff --git a/test/pseudo-tty/test-tty-color-support.out b/test/pseudo-tty/test-tty-color-support.out index 55b3986f73b..df5831c555b 100644 --- a/test/pseudo-tty/test-tty-color-support.out +++ b/test/pseudo-tty/test-tty-color-support.out @@ -1,2 +1,2 @@ -*(node:*) Warning: The 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set. -(Use `* --trace-warnings ...` to show where the warning was created)* +(node:*) Warning: The 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set. +(Use `* --trace-warnings ...` to show where the warning was created)