From a28fba69c8459bdf1f5e4052c8e3f47ef10f76ef Mon Sep 17 00:00:00 2001 From: Christoph Nakazawa Date: Wed, 7 Feb 2018 07:12:54 -0800 Subject: [PATCH] Allow to pass output bundle object Reviewed By: davidaurelio Differential Revision: D6923820 fbshipit-source-id: 99a9cdeab867f0f749792ca62edee8ebdee33328 --- packages/metro/src/index.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/metro/src/index.js b/packages/metro/src/index.js index 6b5c5a62..037631fd 100644 --- a/packages/metro/src/index.js +++ b/packages/metro/src/index.js @@ -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) => void, + ) => Promise, + }, 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};