Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3ba2e7b

Browse filesBrowse files
avivkellermarco-ippolito
authored andcommitted
Revert "console: colorize console error and warn"
This reverts commit a833c9e. PR-URL: #54677 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
1 parent 8981309 commit 3ba2e7b
Copy full SHA for 3ba2e7b

File tree

Expand file treeCollapse file tree

5 files changed

+12
-27
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

5 files changed

+12
-27
lines changed
Open diff view settings
Collapse file

‎lib/internal/console/constructor.js‎

Copy file name to clipboardExpand all lines: lib/internal/console/constructor.js
+5-20Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const {
88
ArrayIsArray,
99
ArrayPrototypeForEach,
1010
ArrayPrototypePush,
11-
ArrayPrototypeSome,
1211
ArrayPrototypeUnshift,
1312
Boolean,
1413
ErrorCaptureStackTrace,
@@ -68,7 +67,6 @@ const {
6867
CHAR_LOWERCASE_N: kTraceInstant,
6968
CHAR_UPPERCASE_C: kTraceCount,
7069
} = require('internal/constants');
71-
const { styleText } = require('util');
7270
const kCounts = Symbol('counts');
7371

7472
const kTraceConsoleCategory = 'node,node.console';
@@ -274,7 +272,7 @@ ObjectDefineProperties(Console.prototype, {
274272
[kWriteToConsole]: {
275273
__proto__: null,
276274
...consolePropAttributes,
277-
value: function(streamSymbol, string, color = '') {
275+
value: function(streamSymbol, string) {
278276
const ignoreErrors = this._ignoreErrors;
279277
const groupIndent = this[kGroupIndent];
280278

@@ -289,11 +287,6 @@ ObjectDefineProperties(Console.prototype, {
289287
}
290288
string = groupIndent + string;
291289
}
292-
293-
if (color) {
294-
string = styleText(color, string);
295-
}
296-
297290
string += '\n';
298291

299292
if (ignoreErrors === false) return stream.write(string);
@@ -384,15 +377,12 @@ const consoleMethods = {
384377
log(...args) {
385378
this[kWriteToConsole](kUseStdout, this[kFormatForStdout](args));
386379
},
380+
381+
387382
warn(...args) {
388-
const color = (shouldColorize(args) && 'yellow') || '';
389-
this[kWriteToConsole](kUseStderr, this[kFormatForStderr](args), color);
383+
this[kWriteToConsole](kUseStderr, this[kFormatForStderr](args));
390384
},
391385

392-
error(...args) {
393-
const color = (shouldColorize(args) && 'red') || '';
394-
this[kWriteToConsole](kUseStderr, this[kFormatForStderr](args), color);
395-
},
396386

397387
dir(object, options) {
398388
this[kWriteToConsole](kUseStdout, inspect(object, {
@@ -685,12 +675,6 @@ const iterKey = '(iteration index)';
685675

686676
const isArray = (v) => ArrayIsArray(v) || isTypedArray(v) || isBuffer(v);
687677

688-
// TODO: remove string type check once the styleText supports objects
689-
// Return true if all args are type string
690-
const shouldColorize = (args) => {
691-
return lazyUtilColors().hasColors && !ArrayPrototypeSome(args, (arg) => typeof arg !== 'string');
692-
};
693-
694678
function noop() {}
695679

696680
for (const method of ReflectOwnKeys(consoleMethods))
@@ -699,6 +683,7 @@ for (const method of ReflectOwnKeys(consoleMethods))
699683
Console.prototype.debug = Console.prototype.log;
700684
Console.prototype.info = Console.prototype.log;
701685
Console.prototype.dirxml = Console.prototype.log;
686+
Console.prototype.error = Console.prototype.warn;
702687
Console.prototype.groupCollapsed = Console.prototype.group;
703688

704689
function initializeGlobalConsole(globalConsole) {
Collapse file

‎test/parallel/test-repl.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-repl.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,6 @@ const errorTests = [
785785
'Object [console] {',
786786
' log: [Function: log],',
787787
' warn: [Function: warn],',
788-
' error: [Function: error],',
789788
' dir: [Function: dir],',
790789
' time: [Function: time],',
791790
' timeEnd: [Function: timeEnd],',
@@ -801,6 +800,7 @@ const errorTests = [
801800
/ {2}debug: \[Function: (debug|log)],/,
802801
/ {2}info: \[Function: (info|log)],/,
803802
/ {2}dirxml: \[Function: (dirxml|log)],/,
803+
/ {2}error: \[Function: (error|warn)],/,
804804
/ {2}groupCollapsed: \[Function: (groupCollapsed|group)],/,
805805
/ {2}Console: \[Function: Console],?/,
806806
...process.features.inspector ? [
Collapse file
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

2-
*(node:*) Warning: The 'NODE_DISABLE_COLORS' env is ignored due to the 'FORCE_COLOR' env being set.
3-
(Use `* --trace-warnings ...` to show where the warning was created)*
2+
(node:*) Warning: The 'NODE_DISABLE_COLORS' env is ignored due to the 'FORCE_COLOR' env being set.
3+
(Use `* --trace-warnings ...` to show where the warning was created)
Collapse file
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

2-
*(node:*) Warning: The 'NODE_DISABLE_COLORS' and 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set.
3-
(Use `* --trace-warnings ...` to show where the warning was created)*
2+
(node:*) Warning: The 'NODE_DISABLE_COLORS' and 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set.
3+
(Use `* --trace-warnings ...` to show where the warning was created)
Collapse file
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
*(node:*) Warning: The 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set.
2-
(Use `* --trace-warnings ...` to show where the warning was created)*
1+
(node:*) Warning: The 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set.
2+
(Use `* --trace-warnings ...` to show where the warning was created)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.