Allow to pass output bundle object

Reviewed By: davidaurelio

Differential Revision: D6923820

fbshipit-source-id: 99a9cdeab867f0f749792ca62edee8ebdee33328
This commit is contained in:
Christoph Nakazawa 2018-02-07 07:12:54 -08:00 committed by Facebook Github Bot
parent 532a2139b8
commit a28fba69c8
1 changed files with 15 additions and 3 deletions

View File

@ -13,7 +13,6 @@
'use strict';
const Config = require('./Config');
const MetroBundler = require('./shared/output/bundle');
const MetroHmrServer = require('./HmrServer');
const MetroServer = require('./Server');
const TerminalReporter = require('./lib/TerminalReporter');
@ -25,6 +24,7 @@ const fs = require('fs');
const getMaxWorkers = require('./lib/getMaxWorkers');
const http = require('http');
const https = require('https');
const outputBundle = require('./shared/output/bundle');
const path = require('path');
const {realpath} = require('fs');
@ -278,6 +278,17 @@ type RunBuildOptions = {|
onProgress?: (transformedFileCount: number, totalFileCount: number) => void,
onComplete?: () => void,
optimize?: boolean,
output?: {
build: (
MetroServer,
RequestOptions,
) => Promise<{code: string, map: string}>,
save: (
{code: string, map: string},
OutputOptions,
(...args: Array<string>) => void,
) => Promise<mixed>,
},
platform?: string,
sourceMap?: boolean,
sourceMapUrl?: string,
@ -290,6 +301,7 @@ exports.runBuild = async (options: RunBuildOptions) => {
resetCache: options.resetCache,
});
const output = options.output || outputBundle;
const requestOptions: RequestOptions = {
dev: options.dev,
entryFile: options.entry,
@ -308,7 +320,7 @@ exports.runBuild = async (options: RunBuildOptions) => {
options.onBegin();
}
const metroBundle = await MetroBundler.build(metroServer, requestOptions);
const metroBundle = await output.build(metroServer, requestOptions);
if (options.onComplete) {
options.onComplete();
@ -324,7 +336,7 @@ exports.runBuild = async (options: RunBuildOptions) => {
platform: options.platform || `web`,
};
await MetroBundler.save(metroBundle, outputOptions, console.log);
await output.save(metroBundle, outputOptions, console.log);
await metroServer.end();
return {metroServer, metroBundle};