Skip to content

Commit dc27b87

Browse files
committed
Bun doesn't currently doesn't support consistent coloring
In the terminal it prints the CSS and in the inspector it prints the ANSI. So we just use a plain bracket instead.
1 parent 49cd789 commit dc27b87

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
const badgeFormat = '[%s] ';
11+
const pad = ' ';
12+
13+
export function printToConsole(
14+
methodName: string,
15+
args: Array<any>,
16+
badgeName: string,
17+
): void {
18+
let offset = 0;
19+
switch (methodName) {
20+
case 'dir':
21+
case 'dirxml':
22+
case 'groupEnd':
23+
case 'table': {
24+
// These methods cannot be colorized because they don't take a formatting string.
25+
// eslint-disable-next-line react-internal/no-production-logging
26+
console[methodName].apply(console, args);
27+
return;
28+
}
29+
case 'assert': {
30+
// assert takes formatting options as the second argument.
31+
offset = 1;
32+
}
33+
}
34+
35+
const newArgs = args.slice(0);
36+
if (typeof newArgs[offset] === 'string') {
37+
newArgs.splice(
38+
offset,
39+
1,
40+
badgeFormat + newArgs[offset],
41+
pad + badgeName + pad,
42+
);
43+
} else {
44+
newArgs.splice(offset, 0, badgeFormat, pad + badgeName + pad);
45+
}
46+
47+
// eslint-disable-next-line react-internal/no-production-logging
48+
console[methodName].apply(console, newArgs);
49+
return;
50+
}

packages/react-client/src/forks/ReactFlightClientConfig.dom-bun.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
export * from 'react-client/src/ReactFlightClientStreamConfigWeb';
11-
export * from 'react-client/src/ReactFlightClientConsoleConfigServer';
11+
export * from 'react-client/src/ReactFlightClientConsoleConfigPlain';
1212
export * from 'react-dom-bindings/src/shared/ReactFlightClientConfigDOM';
1313

1414
export type Response = any;

packages/react-client/src/forks/ReactFlightClientConfig.dom-fb-experimental.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
export * from 'react-client/src/ReactFlightClientStreamConfigWeb';
11-
export * from 'react-client/src/ReactFlightClientConsoleConfigServer';
11+
export * from 'react-client/src/ReactFlightClientConsoleConfigPlain';
1212
export * from 'react-dom-bindings/src/shared/ReactFlightClientConfigDOM';
1313
export * from 'react-server-dom-fb/src/ReactFlightClientConfigFBBundler';
1414

0 commit comments

Comments
 (0)