Skip to content

Commit 8411d18

Browse files
committed
Disable consoleWithStackDev Transform except in RN/WWW
In jest tests we're already not running the forks for RN/WWW so we don't need them at all there.
1 parent 92b1e9d commit 8411d18

File tree

9 files changed

+34
-85
lines changed

9 files changed

+34
-85
lines changed

packages/react-client/src/ReactClientConsoleConfigBrowser.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
* @flow
88
*/
99

10-
import {warn, error} from 'shared/consoleWithStackDev';
11-
1210
const badgeFormat = '%c%s%c ';
1311
// Same badge styling as DevTools.
1412
const badgeStyle =
@@ -65,12 +63,6 @@ export function printToConsole(
6563
);
6664
}
6765

68-
if (methodName === 'error' && __DEV__) {
69-
error.apply(console, newArgs);
70-
} else if (methodName === 'warn' && __DEV__) {
71-
warn.apply(console, newArgs);
72-
} else {
73-
// $FlowFixMe[invalid-computed-prop]
74-
console[methodName].apply(console, newArgs); // eslint-disable-line react-internal/no-production-logging
75-
}
66+
// $FlowFixMe[invalid-computed-prop]
67+
console[methodName].apply(console, newArgs); // eslint-disable-line react-internal/no-production-logging
7668
}

packages/react-client/src/ReactClientConsoleConfigPlain.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
* @flow
88
*/
99

10-
import {warn, error} from 'shared/consoleWithStackDev';
11-
1210
const badgeFormat = '[%s] ';
1311
const pad = ' ';
1412

@@ -46,12 +44,6 @@ export function printToConsole(
4644
newArgs.splice(offset, 0, badgeFormat, pad + badgeName + pad);
4745
}
4846

49-
if (methodName === 'error' && __DEV__) {
50-
error.apply(console, newArgs);
51-
} else if (methodName === 'warn' && __DEV__) {
52-
warn.apply(console, newArgs);
53-
} else {
54-
// $FlowFixMe[invalid-computed-prop]
55-
console[methodName].apply(console, newArgs); // eslint-disable-line react-internal/no-production-logging
56-
}
47+
// $FlowFixMe[invalid-computed-prop]
48+
console[methodName].apply(console, newArgs); // eslint-disable-line react-internal/no-production-logging
5749
}

packages/react-client/src/ReactClientConsoleConfigServer.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
* @flow
88
*/
99

10-
import {warn, error} from 'shared/consoleWithStackDev';
11-
1210
// This flips color using ANSI, then sets a color styling, then resets.
1311
const badgeFormat = '\x1b[0m\x1b[7m%c%s\x1b[0m%c ';
1412
// Same badge styling as DevTools.
@@ -66,12 +64,6 @@ export function printToConsole(
6664
);
6765
}
6866

69-
if (methodName === 'error' && __DEV__) {
70-
error.apply(console, newArgs);
71-
} else if (methodName === 'warn' && __DEV__) {
72-
warn.apply(console, newArgs);
73-
} else {
74-
// $FlowFixMe[invalid-computed-prop]
75-
console[methodName].apply(console, newArgs); // eslint-disable-line react-internal/no-production-logging
76-
}
67+
// $FlowFixMe[invalid-computed-prop]
68+
console[methodName].apply(console, newArgs); // eslint-disable-line react-internal/no-production-logging
7769
}

packages/react-client/src/ReactFlightClient.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2090,7 +2090,7 @@ function resolveConsoleEntry(
20902090
task.run(callStack);
20912091
return;
20922092
}
2093-
// TODO: Set the current owner so that consoleWithStackDev adds the component
2093+
// TODO: Set the current owner so that captureOwnerStack() adds the component
20942094
// stack during the replay - if needed.
20952095
}
20962096
const rootTask = response._debugRootTask;

packages/react-reconciler/src/ReactFiberErrorLogger.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export function defaultOnCaughtError(
124124
error,
125125
componentNameMessage,
126126
recreateMessage,
127-
// We let our consoleWithStackDev wrapper add the component stack to the end.
127+
// We let DevTools or console.createTask add the component stack to the end.
128128
],
129129
error.environmentName,
130130
);
@@ -134,7 +134,7 @@ export function defaultOnCaughtError(
134134
error,
135135
componentNameMessage,
136136
recreateMessage,
137-
// We let our consoleWithStackDev wrapper add the component stack to the end.
137+
// We let our DevTools or console.createTask add the component stack to the end.
138138
);
139139
}
140140
} finally {

packages/shared/consoleWithStackDev.js

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,14 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
export function setSuppressWarning(newSuppressWarning) {
9-
// TODO: Noop. Delete.
10-
}
11-
12-
// In DEV, calls to console.warn and console.error get replaced
13-
// by calls to these methods by a Babel plugin.
8+
// We expect that our Rollup, Jest, and Flow configurations
9+
// always shim this module with the corresponding environment
10+
// (either rn or www).
1411
//
15-
// In PROD (or in packages without access to React internals),
16-
// they are left as they are instead.
17-
18-
export function warn(format, ...args) {
19-
if (__DEV__) {
20-
printWarning('warn', format, args);
21-
}
22-
}
23-
24-
export function error(format, ...args) {
25-
if (__DEV__) {
26-
printWarning('error', format, args);
27-
}
28-
}
12+
// We should never resolve to this file, but it exists to make
13+
// sure that if we *do* accidentally break the configuration,
14+
// the failure isn't silent.
2915

30-
function printWarning(level, format, args) {
31-
// When changing this logic, you might want to also
32-
// update consoleWithStackDev.www.js as well.
33-
if (__DEV__) {
34-
args.unshift(format);
35-
// We intentionally don't use spread (or .apply) directly because it
36-
// breaks IE9: https://github.com/facebook/react/issues/13610
37-
// eslint-disable-next-line react-internal/no-production-logging
38-
Function.prototype.apply.call(console[level], console, args);
39-
}
16+
export function setSuppressWarning() {
17+
// TODO: Delete this and error when even importing this module.
4018
}

scripts/jest/preprocessor.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ const pathToBabel = path.join(
1616
'../..',
1717
'package.json'
1818
);
19-
const pathToBabelPluginReplaceConsoleCalls = require.resolve(
20-
'../babel/transform-replace-console-calls'
21-
);
2219
const pathToTransformInfiniteLoops = require.resolve(
2320
'../babel/transform-prevent-infinite-loops'
2421
);
@@ -73,14 +70,7 @@ module.exports = {
7370
const isInDevToolsPackages = !!filePath.match(
7471
/\/packages\/react-devtools.*\//
7572
);
76-
const testOnlyPlugins = [];
77-
const sourceOnlyPlugins = [];
78-
if (process.env.NODE_ENV === 'development' && !isInDevToolsPackages) {
79-
sourceOnlyPlugins.push(pathToBabelPluginReplaceConsoleCalls);
80-
}
81-
const plugins = (isTestFile ? testOnlyPlugins : sourceOnlyPlugins).concat(
82-
babelOptions.plugins
83-
);
73+
const plugins = [].concat(babelOptions.plugins);
8474
if (isTestFile && isInDevToolsPackages) {
8575
plugins.push(pathToTransformReactVersionPragma);
8676
}

scripts/print-warnings/print-warnings.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ function transform(file, enc, cb) {
6868
gs([
6969
'packages/**/*.js',
7070
'!packages/*/npm/**/*.js',
71-
'!packages/shared/consoleWithStackDev.js',
7271
'!packages/react-devtools*/**/*.js',
7372
'!**/__tests__/**/*.js',
7473
'!**/__mocks__/**/*.js',

scripts/rollup/build.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,22 @@ function getBabelConfig(
149149
sourcemap: false,
150150
};
151151
if (isDevelopment) {
152-
options.plugins.push(
153-
...babelToES5Plugins,
154-
// Turn console.error/warn() into a custom wrapper
155-
[
156-
require('../babel/transform-replace-console-calls'),
157-
{
158-
shouldError: !canAccessReactObject,
159-
},
160-
]
161-
);
152+
options.plugins.push(...babelToES5Plugins);
153+
if (
154+
bundleType === FB_WWW_DEV ||
155+
bundleType === RN_OSS_DEV ||
156+
bundleType === RN_FB_DEV
157+
) {
158+
options.plugins.push(
159+
// Turn console.error/warn() into a custom wrapper
160+
[
161+
require('../babel/transform-replace-console-calls'),
162+
{
163+
shouldError: !canAccessReactObject,
164+
},
165+
]
166+
);
167+
}
162168
}
163169
if (updateBabelOptions) {
164170
options = updateBabelOptions(options);

0 commit comments

Comments
 (0)