mirror of
https://github.com/status-im/react-native.git
synced 2025-01-10 01:25:39 +00:00
934cd82941
Summary: The way React DevTools integration was set up in RN was not entirely supported by the React team, and we had to disable it in c3b25c9059f57ee8df5505628ff6221f11cf9234 so that we can move forward with enabling Fiber support in React Native. Here, I am moving the DevTools client setup from RN repo to [React DevTools repo](https://github.com/facebook/react-devtools/blob/master/packages/react-devtools-core/README.md#requirereact-devtools-coreconnecttodevtoolsoptions) so that we can keep it in sync with the rest of React DevTools. This is also a part of a larger effort to consolidate DevTools code (https://github.com/facebook/react-devtools/issues/489). It allows us to remove the double injection of the hook, an lets us replace the `eval` hack with a regular dependency. The implementation [lives here now](https://github.com/facebook/react-devtools/blob/master/packages/react-devtools-core/src/backend.js). This change re-enables Nuclide Inspector with React Native Stack reconciler and prepares it for compatibi Closes https://github.com/facebook/react-native/pull/12316 Reviewed By: zertosh Differential Revision: D4545322 Pulled By: gaearon fbshipit-source-id: ab949916c1a92c6b41cd41e7e1edf9697a71de2e
109 lines
4.3 KiB
JavaScript
109 lines
4.3 KiB
JavaScript
/**
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*/
|
|
'use strict';
|
|
|
|
const InspectorProxy = require('./util/inspectorProxy.js');
|
|
const ReactPackager = require('../../packager/react-packager');
|
|
const TerminalReporter = require('../../packager/src/lib/TerminalReporter');
|
|
|
|
const attachHMRServer = require('./util/attachHMRServer');
|
|
const connect = require('connect');
|
|
const copyToClipBoardMiddleware = require('./middleware/copyToClipBoardMiddleware');
|
|
const cpuProfilerMiddleware = require('./middleware/cpuProfilerMiddleware');
|
|
const defaultAssetExts = require('../../packager/defaults').assetExts;
|
|
const defaultPlatforms = require('../../packager/defaults').platforms;
|
|
const defaultProvidesModuleNodeModules = require('../../packager/defaults').providesModuleNodeModules;
|
|
const getDevToolsMiddleware = require('./middleware/getDevToolsMiddleware');
|
|
const heapCaptureMiddleware = require('./middleware/heapCaptureMiddleware.js');
|
|
const http = require('http');
|
|
const indexPageMiddleware = require('./middleware/indexPage');
|
|
const loadRawBodyMiddleware = require('./middleware/loadRawBodyMiddleware');
|
|
const messageSocket = require('./util/messageSocket.js');
|
|
const openStackFrameInEditorMiddleware = require('./middleware/openStackFrameInEditorMiddleware');
|
|
const path = require('path');
|
|
const statusPageMiddleware = require('./middleware/statusPageMiddleware.js');
|
|
const systraceProfileMiddleware = require('./middleware/systraceProfileMiddleware.js');
|
|
const unless = require('./middleware/unless');
|
|
const webSocketProxy = require('./util/webSocketProxy.js');
|
|
|
|
function runServer(args, config, readyCallback) {
|
|
var wsProxy = null;
|
|
var ms = null;
|
|
const packagerServer = getPackagerServer(args, config);
|
|
const inspectorProxy = new InspectorProxy();
|
|
const app = connect()
|
|
.use(loadRawBodyMiddleware)
|
|
.use(connect.compress())
|
|
.use(getDevToolsMiddleware(args, () => wsProxy && wsProxy.isChromeConnected()))
|
|
.use(getDevToolsMiddleware(args, () => ms && ms.isChromeConnected()))
|
|
.use(openStackFrameInEditorMiddleware(args))
|
|
.use(copyToClipBoardMiddleware)
|
|
.use(statusPageMiddleware)
|
|
.use(systraceProfileMiddleware)
|
|
.use(heapCaptureMiddleware)
|
|
.use(cpuProfilerMiddleware)
|
|
.use(indexPageMiddleware)
|
|
.use(unless('/inspector', inspectorProxy.processRequest.bind(inspectorProxy)))
|
|
.use(packagerServer.processRequest.bind(packagerServer));
|
|
|
|
args.projectRoots.forEach(root => app.use(connect.static(root)));
|
|
|
|
app.use(connect.logger())
|
|
.use(connect.errorHandler());
|
|
|
|
const serverInstance = http.createServer(app).listen(
|
|
args.port,
|
|
args.host,
|
|
function() {
|
|
attachHMRServer({
|
|
httpServer: serverInstance,
|
|
path: '/hot',
|
|
packagerServer,
|
|
});
|
|
|
|
wsProxy = webSocketProxy.attachToServer(serverInstance, '/debugger-proxy');
|
|
ms = messageSocket.attachToServer(serverInstance, '/message');
|
|
inspectorProxy.attachToServer(serverInstance, '/inspector');
|
|
readyCallback();
|
|
}
|
|
);
|
|
// Disable any kind of automatic timeout behavior for incoming
|
|
// requests in case it takes the packager more than the default
|
|
// timeout of 120 seconds to respond to a request.
|
|
serverInstance.timeout = 0;
|
|
}
|
|
|
|
function getPackagerServer(args, config) {
|
|
const transformModulePath =
|
|
args.transformer ? path.resolve(args.transformer) :
|
|
typeof config.getTransformModulePath === 'function' ? config.getTransformModulePath() :
|
|
undefined;
|
|
|
|
const providesModuleNodeModules =
|
|
args.providesModuleNodeModules || defaultProvidesModuleNodeModules;
|
|
|
|
return ReactPackager.createServer({
|
|
assetExts: defaultAssetExts.concat(args.assetExts),
|
|
blacklistRE: config.getBlacklistRE(),
|
|
cacheVersion: '3',
|
|
extraNodeModules: config.extraNodeModules,
|
|
getTransformOptions: config.getTransformOptions,
|
|
platforms: defaultPlatforms.concat(args.platforms),
|
|
projectRoots: args.projectRoots,
|
|
providesModuleNodeModules: providesModuleNodeModules,
|
|
reporter: new TerminalReporter(),
|
|
resetCache: args.resetCache,
|
|
transformModulePath: transformModulePath,
|
|
verbose: args.verbose,
|
|
watch: !args.nonPersistent,
|
|
});
|
|
}
|
|
|
|
module.exports = runServer;
|