Files
react-native/packages/react-native/Libraries/Core/setUpDeveloperTools.js
T
Panos Vekris 50ca7e5730 manual annotations in preparation of natural inference rollout in react-native, tools, etc.
Summary:
The Flow team is improving the way Flow infers type for primitive literals. This diff prepares the codebase for the new behavior by adding type annotations, or annotations of the form `'abc' as const`.

Changelog: [internal]

Reviewed By: marcoww6

Differential Revision: D75188179

fbshipit-source-id: be50990f23f79cf2d8dae7576af5190218adcafe
2025-05-21 20:06:46 -07:00

53 lines
1.3 KiB
JavaScript

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
*/
import Platform from '../Utilities/Platform';
declare var console: {[string]: $FlowFixMe};
/**
* Sets up developer tools for React Native.
* You can use this module directly, or just require InitializeCore.
*/
if (__DEV__) {
if (!Platform.isTesting) {
const HMRClient = require('../Utilities/HMRClient').default;
// TODO(T214991636): Remove legacy Metro log forwarding
if (console._isPolyfilled) {
// We assume full control over the console and send JavaScript logs to Metro.
(
[
'trace',
'info',
'warn',
'error',
'log',
'group',
'groupCollapsed',
'groupEnd',
'debug',
] as const
).forEach(level => {
const originalFunction = console[level];
console[level] = function (...args: $ReadOnlyArray<mixed>) {
HMRClient.log(level, args);
originalFunction.apply(console, args);
};
});
}
}
require('./setUpReactRefresh');
global[`${global.__METRO_GLOBAL_PREFIX__ ?? ''}__loadBundleAsync`] =
require('./Devtools/loadBundleFromServer').default;
}