Revert "console: colorize console error and warn"

This reverts commit a833c9e0be.

PR-URL: https://github.com/nodejs/node/pull/54677
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
This commit is contained in:
Aviv Keller 2024-09-28 09:50:39 -04:00 committed by GitHub
parent e8127db032
commit 2d77ba5d30
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 12 additions and 27 deletions

View File

@ -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) {

View File

@ -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 ? [

View File

@ -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)

View File

@ -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)

View File

@ -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)