mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/48889 ## Motivation Modernising the react-native codebase to allow for ingestion by modern Flow tooling. ## This diff - Updates files in `Libraries/Core` to use `export` syntax - `export default` for qualified objects, many `export` statements for collections - Appends `.default` to requires of the changed files. - Changed `* as ExceptionsManager` to `ExceptionsManager` in import statements throughout product code. - Updates test files. - Updates the public API snapshot (intented breaking change) Changelog: [General][Breaking] - Files inside `Libraries/Core` use `export` syntax, which requires the addition of `.default` when imported with the CJS `require` syntax. [General][Breaking] - `Libraries/Core/ExceptionsManager` now exports a default `ExceptionsManager` object, and `SyntheticError` as a secondary export. Reviewed By: huntie Differential Revision: D68553694 fbshipit-source-id: 51c9a404b2762cb1cdb5f56cae3a683ccdfffc7f
81 lines
2.7 KiB
JavaScript
81 lines
2.7 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__) {
|
|
// Set up inspector
|
|
const JSInspector = require('../JSInspector/JSInspector');
|
|
JSInspector.registerAgent(require('../JSInspector/NetworkAgent'));
|
|
|
|
// Note we can't check if console is "native" because it would appear "native" in JSC and Hermes.
|
|
// We also can't check any properties that don't exist in the Chrome worker environment.
|
|
// So we check a navigator property that's set to a particular value ("Netscape") in all real browsers.
|
|
const isLikelyARealBrowser =
|
|
global.navigator != null &&
|
|
/* _
|
|
* | |
|
|
* _ __ ___| |_ ___ ___ __ _ _ __ ___
|
|
* | '_ \ / _ \ __/ __|/ __/ _` | '_ \ / _ \
|
|
* | | | | __/ |_\__ \ (_| (_| | |_) | __/
|
|
* |_| |_|\___|\__|___/\___\__,_| .__/ \___|
|
|
* | |
|
|
* |_|
|
|
*/
|
|
global.navigator.appName === 'Netscape'; // Any real browser
|
|
|
|
if (!Platform.isTesting) {
|
|
const HMRClient = require('../Utilities/HMRClient');
|
|
|
|
if (global.__FUSEBOX_HAS_FULL_CONSOLE_SUPPORT__) {
|
|
HMRClient.unstable_notifyFuseboxConsoleEnabled();
|
|
} else 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',
|
|
].forEach(level => {
|
|
const originalFunction = console[level];
|
|
console[level] = function (...args: $ReadOnlyArray<mixed>) {
|
|
HMRClient.log(level, args);
|
|
originalFunction.apply(console, args);
|
|
};
|
|
});
|
|
} else {
|
|
// We assume the environment has a real rich console (like Chrome), and don't hijack it to log to Metro.
|
|
// It's likely the developer is using rich console to debug anyway, and hijacking it would
|
|
// lose the filenames in console.log calls: https://github.com/facebook/react-native/issues/26788.
|
|
HMRClient.log('log', [
|
|
`JavaScript logs will appear in your ${
|
|
isLikelyARealBrowser ? 'browser' : 'environment'
|
|
} console`,
|
|
]);
|
|
}
|
|
}
|
|
|
|
require('./setUpReactRefresh');
|
|
|
|
global[`${global.__METRO_GLOBAL_PREFIX__ ?? ''}__loadBundleAsync`] =
|
|
require('./Devtools/loadBundleFromServer').default;
|
|
}
|