mirror of
https://github.com/status-im/react-native.git
synced 2025-01-10 01:25:39 +00:00
8c9c7e6286
Summary: public This diff introduces an internal transforms pipeline that integrates with the external one. This has been a feature we've been looking to implement for a long time to use babel instead of `replace` with regexps on many parts of the packager. Also, to split the bundle we'll need to run one transform. Internally for Facebook we can run the system-import transform altogether withe the other ones. For OSS we offer `transformer.js` which people can use out of the box if they're writing ES6 code. For those people, `transformer.js` will also run the internal transforms`. However they might want to tune the transforms, or even write the code on another language that compiles to Javascript and use a complete different transformer. On those cases we'll need to run the external transforms first and pipe the output through the internal transforms. Note that the order it's important as the internal transforms assume the code is written in JS, though the original code could be on other scripting languages (CoffeeScript, TypeScript, etc). Reviewed By: davidaurelio Differential Revision: D2725109 fb-gh-sync-id: d764e209c78743419c4cb97068495c771372ab90
85 lines
3.1 KiB
JavaScript
85 lines
3.1 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 connect = require('connect');
|
|
const cpuProfilerMiddleware = require('./middleware/cpuProfilerMiddleware');
|
|
const getDevToolsMiddleware = require('./middleware/getDevToolsMiddleware');
|
|
const http = require('http');
|
|
const isAbsolutePath = require('absolute-path');
|
|
const loadRawBodyMiddleware = require('./middleware/loadRawBodyMiddleware');
|
|
const openStackFrameInEditorMiddleware = require('./middleware/openStackFrameInEditorMiddleware');
|
|
const path = require('path');
|
|
const ReactPackager = require('../../packager/react-packager');
|
|
const statusPageMiddleware = require('./middleware/statusPageMiddleware.js');
|
|
const systraceProfileMiddleware = require('./middleware/systraceProfileMiddleware.js');
|
|
const webSocketProxy = require('./util/webSocketProxy.js');
|
|
|
|
function runServer(args, config, readyCallback) {
|
|
var wsProxy = null;
|
|
const app = connect()
|
|
.use(loadRawBodyMiddleware)
|
|
.use(connect.compress())
|
|
.use(getDevToolsMiddleware(args, () => wsProxy && wsProxy.isChromeConnected()))
|
|
.use(openStackFrameInEditorMiddleware)
|
|
.use(statusPageMiddleware)
|
|
.use(systraceProfileMiddleware)
|
|
.use(cpuProfilerMiddleware)
|
|
// Temporarily disable flow check until it's more stable
|
|
//.use(getFlowTypeCheckMiddleware(args))
|
|
.use(getAppMiddleware(args, config));
|
|
|
|
args.projectRoots.forEach(root => app.use(connect.static(root)));
|
|
|
|
app.use(connect.logger())
|
|
.use(connect.errorHandler());
|
|
|
|
const serverInstance = http.createServer(app).listen(
|
|
args.port,
|
|
'::',
|
|
function() {
|
|
wsProxy = webSocketProxy.attachToServer(serverInstance, '/debugger-proxy');
|
|
webSocketProxy.attachToServer(serverInstance, '/devtools');
|
|
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 getAppMiddleware(args, config) {
|
|
let transformerPath = args.transformer;
|
|
if (!isAbsolutePath(transformerPath)) {
|
|
transformerPath = path.resolve(process.cwd(), transformerPath);
|
|
}
|
|
|
|
return ReactPackager.middleware({
|
|
nonPersistent: args.nonPersistent,
|
|
projectRoots: args.projectRoots,
|
|
blacklistRE: config.getBlacklistRE(),
|
|
cacheVersion: '3',
|
|
getTransformOptionsModulePath: config.getTransformOptionsModulePath,
|
|
transformModulePath: transformerPath,
|
|
enableInternalTransforms: args['enable-internal-transforms'],
|
|
assetRoots: args.assetRoots,
|
|
assetExts: ['png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp'],
|
|
resetCache: args.resetCache || args['reset-cache'],
|
|
polyfillModuleNames: [
|
|
require.resolve(
|
|
'../../Libraries/JavaScriptAppEngine/polyfills/document.js'
|
|
),
|
|
],
|
|
verbose: args.verbose,
|
|
});
|
|
}
|
|
|
|
module.exports = runServer;
|