Remove socket interface from buildBundle command

Reviewed By: davidaurelio

Differential Revision: D3137070

fb-gh-sync-id: 8f3bb4af597bf509d16e5ce26f31fe1646acbc57
fbshipit-source-id: 8f3bb4af597bf509d16e5ce26f31fe1646acbc57
This commit is contained in:
Sam Swarr 2016-04-11 09:23:04 -07:00 committed by Facebook Github Bot 4
parent 838cc48059
commit bc81cc4073

View File

@ -10,8 +10,8 @@
const log = require('../util/log').out('bundle'); const log = require('../util/log').out('bundle');
const outputBundle = require('./output/bundle'); const outputBundle = require('./output/bundle');
const Promise = require('promise'); const Promise = require('promise');
const ReactPackager = require('../../packager/react-packager');
const saveAssets = require('./saveAssets'); const saveAssets = require('./saveAssets');
const Server = require('../../packager/react-packager/src/Server');
function saveBundle(output, bundle, args) { function saveBundle(output, bundle, args) {
return Promise.resolve( return Promise.resolve(
@ -32,7 +32,7 @@ function buildBundle(args, config, output = outputBundle, packagerInstance) {
blacklistRE: config.getBlacklistRE(args.platform), blacklistRE: config.getBlacklistRE(args.platform),
getTransformOptionsModulePath: config.getTransformOptionsModulePath, getTransformOptionsModulePath: config.getTransformOptionsModulePath,
transformModulePath: args.transformer, transformModulePath: args.transformer,
verbose: args.verbose, nonPersistent: true,
}; };
const requestOpts = { const requestOpts = {
@ -43,29 +43,22 @@ function buildBundle(args, config, output = outputBundle, packagerInstance) {
platform: args.platform, platform: args.platform,
}; };
var bundlePromise; // If a packager instance was not provided, then just create one for this
if (packagerInstance) { // bundle command and close it down afterwards.
bundlePromise = output.build(packagerInstance, requestOpts) var shouldClosePackager = false;
.then(bundle => saveBundle(output, bundle, args)); if (!packagerInstance) {
} else { packagerInstance = new Server(options);
const clientPromise = ReactPackager.createClientFor(options); shouldClosePackager = true;
// Build and save the bundle
bundlePromise = clientPromise
.then(client => {
log('Created ReactPackager');
return output.build(client, requestOpts);
})
.then(bundle => saveBundle(output, bundle, args));
// When we're done bundling, close the client
Promise.all([clientPromise, bundlePromise])
.then(([client]) => {
log('Closing client');
client.close();
});
} }
const bundlePromise = output.build(packagerInstance, requestOpts)
.then(bundle => {
if (shouldClosePackager) {
packagerInstance.end();
}
return saveBundle(output, bundle, args);
});
// Save the assets of the bundle // Save the assets of the bundle
const assets = bundlePromise const assets = bundlePromise
.then(bundle => bundle.getAssets()) .then(bundle => bundle.getAssets())