Skip to content

Commit

Permalink
Revert "console: colorize console error and warn"
Browse files Browse the repository at this point in the history
This reverts commit a833c9e.

PR-URL: #54677
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
  • Loading branch information
Aviv Keller authored and targos committed Oct 4, 2024
1 parent 60a35ed commit 1dcc5ee
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 27 deletions.
25 changes: 5 additions & 20 deletions lib/internal/console/constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const {
ArrayIsArray,
ArrayPrototypeForEach,
ArrayPrototypePush,
ArrayPrototypeSome,
ArrayPrototypeUnshift,
Boolean,
ErrorCaptureStackTrace,
Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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) || '';

Expand All @@ -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);
Expand Down Expand Up @@ -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, {
Expand Down Expand Up @@ -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))
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],',
Expand All @@ -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 ? [
Expand Down
4 changes: 2 additions & 2 deletions test/pseudo-tty/test-tty-color-support-warning-2.out
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 2 additions & 2 deletions test/pseudo-tty/test-tty-color-support-warning.out
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 2 additions & 2 deletions test/pseudo-tty/test-tty-color-support.out
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 1dcc5ee

Please sign in to comment.