Cleanup InitializeJavascriptAppEngine
Reviewed By: davidaurelio Differential Revision: D3235141 fb-gh-sync-id: 86fc844c5e9d9ea57d504696bac30671c2079e7a fbshipit-source-id: 86fc844c5e9d9ea57d504696bac30671c2079e7a
This commit is contained in:
parent
2310494f32
commit
2760df761d
|
@ -11,13 +11,15 @@
|
||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var BatchedBridge = require('BatchedBridge');
|
const BatchedBridge = require('BatchedBridge');
|
||||||
var ReactNativeEventEmitter = require('ReactNativeEventEmitter');
|
|
||||||
|
|
||||||
BatchedBridge.registerCallableModule(
|
const RCTEventEmitter = {
|
||||||
'RCTEventEmitter',
|
register(eventEmitter: any) {
|
||||||
ReactNativeEventEmitter
|
BatchedBridge.registerCallableModule(
|
||||||
);
|
'RCTEventEmitter',
|
||||||
|
eventEmitter
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Completely locally implemented - no native hooks.
|
module.exports = RCTEventEmitter;
|
||||||
module.exports = ReactNativeEventEmitter;
|
|
||||||
|
|
|
@ -32,10 +32,27 @@ if (typeof window === 'undefined') {
|
||||||
global.window = global;
|
global.window = global;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setUpProfile() {
|
||||||
|
if (__DEV__) {
|
||||||
|
const Systrace = require('Systrace');
|
||||||
|
Systrace.swizzleReactPerf();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setUpProcess() {
|
||||||
|
GLOBAL.process = GLOBAL.process || {};
|
||||||
|
GLOBAL.process.env = GLOBAL.process.env || {};
|
||||||
|
if (!GLOBAL.process.env.NODE_ENV) {
|
||||||
|
GLOBAL.process.env.NODE_ENV = __DEV__ ? 'development' : 'production';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function setUpConsole() {
|
function setUpConsole() {
|
||||||
// ExceptionsManager transitively requires Promise so we install it after
|
// ExceptionsManager transitively requires Promise so we install it after
|
||||||
var ExceptionsManager = require('ExceptionsManager');
|
const ExceptionsManager = require('ExceptionsManager');
|
||||||
ExceptionsManager.installConsoleErrorReporter();
|
ExceptionsManager.installConsoleErrorReporter();
|
||||||
|
|
||||||
|
require('RCTLog');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,7 +71,7 @@ function setUpConsole() {
|
||||||
* https://github.com/facebook/react-native/issues/934
|
* https://github.com/facebook/react-native/issues/934
|
||||||
*/
|
*/
|
||||||
function polyfillGlobal(name, newValue, scope = global) {
|
function polyfillGlobal(name, newValue, scope = global) {
|
||||||
var descriptor = Object.getOwnPropertyDescriptor(scope, name) || {
|
const descriptor = Object.getOwnPropertyDescriptor(scope, name) || {
|
||||||
// jest for some bad reasons runs the polyfill code multiple times. In jest
|
// jest for some bad reasons runs the polyfill code multiple times. In jest
|
||||||
// environment, XmlHttpRequest doesn't exist so getOwnPropertyDescriptor
|
// environment, XmlHttpRequest doesn't exist so getOwnPropertyDescriptor
|
||||||
// returns undefined and defineProperty default for writable is false.
|
// returns undefined and defineProperty default for writable is false.
|
||||||
|
@ -63,7 +80,7 @@ function polyfillGlobal(name, newValue, scope = global) {
|
||||||
};
|
};
|
||||||
|
|
||||||
if (scope[name] !== undefined) {
|
if (scope[name] !== undefined) {
|
||||||
var backupName = `original${name[0].toUpperCase()}${name.substr(1)}`;
|
const backupName = `original${name[0].toUpperCase()}${name.substr(1)}`;
|
||||||
Object.defineProperty(scope, backupName, {...descriptor, value: scope[name]});
|
Object.defineProperty(scope, backupName, {...descriptor, value: scope[name]});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +132,7 @@ function setUpErrorHandler() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var ErrorUtils = require('ErrorUtils');
|
const ErrorUtils = require('ErrorUtils');
|
||||||
ErrorUtils.setGlobalHandler(handleError);
|
ErrorUtils.setGlobalHandler(handleError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,6 +183,8 @@ function setUpXHR() {
|
||||||
polyfillLazyGlobal('Headers', () => require('fetch').Headers);
|
polyfillLazyGlobal('Headers', () => require('fetch').Headers);
|
||||||
polyfillLazyGlobal('Request', () => require('fetch').Request);
|
polyfillLazyGlobal('Request', () => require('fetch').Request);
|
||||||
polyfillLazyGlobal('Response', () => require('fetch').Response);
|
polyfillLazyGlobal('Response', () => require('fetch').Response);
|
||||||
|
|
||||||
|
polyfillLazyGlobal('WebSocket', () => require('WebSocket'));
|
||||||
}
|
}
|
||||||
|
|
||||||
function setUpGeolocation() {
|
function setUpGeolocation() {
|
||||||
|
@ -174,6 +193,8 @@ function setUpGeolocation() {
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
configurable: true,
|
configurable: true,
|
||||||
});
|
});
|
||||||
|
Object.defineProperty(global.navigator, 'product', {value: 'ReactNative'});
|
||||||
|
|
||||||
polyfillLazyGlobal('geolocation', () => require('Geolocation'), global.navigator);
|
polyfillLazyGlobal('geolocation', () => require('Geolocation'), global.navigator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,39 +205,20 @@ function setUpMapAndSet() {
|
||||||
polyfillGlobal('Set', require('Set'));
|
polyfillGlobal('Set', require('Set'));
|
||||||
}
|
}
|
||||||
|
|
||||||
function setUpProduct() {
|
|
||||||
Object.defineProperty(global.navigator, 'product', {value: 'ReactNative'});
|
|
||||||
}
|
|
||||||
|
|
||||||
function setUpWebSockets() {
|
|
||||||
polyfillLazyGlobal('WebSocket', () => require('WebSocket'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function setUpProfile() {
|
|
||||||
if (__DEV__) {
|
|
||||||
var Systrace = require('Systrace');
|
|
||||||
Systrace.swizzleReactPerf();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function setUpProcess() {
|
|
||||||
global.process = global.process || {};
|
|
||||||
global.process.env = global.process.env || {};
|
|
||||||
if (!global.process.env.NODE_ENV) {
|
|
||||||
global.process.env.NODE_ENV = __DEV__ ? 'development' : 'production';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function setUpDevTools() {
|
function setUpDevTools() {
|
||||||
// not when debugging in chrome
|
if (__DEV__) {
|
||||||
if (__DEV__) { // TODO(9123099) Strip `__DEV__ &&`
|
// not when debugging in chrome
|
||||||
if (!window.document && require('Platform').OS === 'ios') {
|
if (!window.document && require('Platform').OS === 'ios') {
|
||||||
var setupDevtools = require('setupDevtools');
|
const setupDevtools = require('setupDevtools');
|
||||||
setupDevtools();
|
setupDevtools();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
require('RCTDebugComponentOwnership');
|
||||||
|
require('react-transform-hmr');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setUpProfile();
|
||||||
setUpProcess();
|
setUpProcess();
|
||||||
setUpConsole();
|
setUpConsole();
|
||||||
setUpTimers();
|
setUpTimers();
|
||||||
|
@ -226,21 +228,10 @@ setUpErrorHandler();
|
||||||
setUpXHR();
|
setUpXHR();
|
||||||
setUpGeolocation();
|
setUpGeolocation();
|
||||||
setUpMapAndSet();
|
setUpMapAndSet();
|
||||||
setUpProduct();
|
|
||||||
setUpWebSockets();
|
|
||||||
setUpProfile();
|
|
||||||
setUpDevTools();
|
setUpDevTools();
|
||||||
|
|
||||||
// Just to make sure the JS gets packaged up. Wait until the JS environment has
|
// Just to make sure the JS gets packaged up. Wait until the JS environment has
|
||||||
// been initialized before requiring them.
|
// been initialized before requiring them.
|
||||||
if (__DEV__) {
|
|
||||||
require('RCTDebugComponentOwnership');
|
|
||||||
}
|
|
||||||
require('RCTDeviceEventEmitter');
|
require('RCTDeviceEventEmitter');
|
||||||
require('RCTNativeAppEventEmitter');
|
require('RCTNativeAppEventEmitter');
|
||||||
require('PerformanceLogger');
|
require('PerformanceLogger');
|
||||||
|
|
||||||
if (__DEV__) {
|
|
||||||
// include this transform and it's dependencies on the bundle on dev mode
|
|
||||||
require('react-transform-hmr');
|
|
||||||
}
|
|
||||||
|
|
|
@ -124,7 +124,7 @@
|
||||||
"react-native": "local-cli/wrong-react-native.js"
|
"react-native": "local-cli/wrong-react-native.js"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"react": "15.0.2"
|
"react": "15.0.3-alpha.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"absolute-path": "^0.0.0",
|
"absolute-path": "^0.0.0",
|
||||||
|
@ -187,7 +187,7 @@
|
||||||
"flow-bin": "0.24.0",
|
"flow-bin": "0.24.0",
|
||||||
"jest-cli": "11.0.2",
|
"jest-cli": "11.0.2",
|
||||||
"portfinder": "0.4.0",
|
"portfinder": "0.4.0",
|
||||||
"react": "15.0.2",
|
"react": "15.0.3-alpha.1",
|
||||||
"shelljs": "0.6.0"
|
"shelljs": "0.6.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -248,16 +248,6 @@ class Bundler {
|
||||||
entryModuleOnly,
|
entryModuleOnly,
|
||||||
resolutionResponse,
|
resolutionResponse,
|
||||||
}) {
|
}) {
|
||||||
if (dev && runBeforeMainModule) { // no runBeforeMainModule for hmr bundles
|
|
||||||
// `require` calls in the require polyfill itself are not extracted and
|
|
||||||
// replaced with numeric module IDs, but the require polyfill
|
|
||||||
// needs Systrace.
|
|
||||||
// Therefore, we include the Systrace module before the main module, and
|
|
||||||
// it will set itself as property on the require function.
|
|
||||||
// TODO(davidaurelio) Scan polyfills for dependencies, too (t9759686)
|
|
||||||
runBeforeMainModule = runBeforeMainModule.concat(['Systrace']);
|
|
||||||
}
|
|
||||||
|
|
||||||
const onResolutionResponse = response => {
|
const onResolutionResponse = response => {
|
||||||
bundle.setMainModuleId(this._getModuleId(getMainModule(response)));
|
bundle.setMainModuleId(this._getModuleId(getMainModule(response)));
|
||||||
if (bundle.setNumPrependedModules) {
|
if (bundle.setNumPrependedModules) {
|
||||||
|
|
Loading…
Reference in New Issue