From d54a7044f27c976efdd0f44f541280b9ce7bb349 Mon Sep 17 00:00:00 2001 From: Rafael Oleza Date: Wed, 11 Apr 2018 10:38:45 -0700 Subject: [PATCH] Support passing multiple entryPoints to the public buildGraph() method Reviewed By: mjesun Differential Revision: D7365288 fbshipit-source-id: 1d1b94858d2ad31307157839808b9a6c01c00365 --- packages/metro/src/Server/index.js | 44 ++++++++++++++++++++---------- packages/metro/src/index.js | 14 ++++++---- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/packages/metro/src/Server/index.js b/packages/metro/src/Server/index.js index a4330c3f..4ec876a1 100644 --- a/packages/metro/src/Server/index.js +++ b/packages/metro/src/Server/index.js @@ -59,7 +59,10 @@ import type {MetroSourceMap} from 'metro-source-map'; import type {TransformCache} from '../lib/TransformCaching'; import type {Symbolicate} from './symbolicate/symbolicate'; import type {AssetData} from '../Assets'; -import type {TransformedCode} from '../JSTransformer/worker'; +import type { + CustomTransformOptions, + TransformedCode, +} from '../JSTransformer/worker'; const { Logger: {createActionStartEntry, createActionEndEntry, log}, } = require('metro-core'); @@ -73,6 +76,18 @@ type GraphInfo = {| +sequenceId: string, |}; +type BuildGraphOptions = {| + +assetPlugins: Array, + +customTransformOptions: CustomTransformOptions, + +dev: boolean, + +entryFiles: $ReadOnlyArray, + +hot: boolean, + +minify: boolean, + +onProgress: ?(doneCont: number, totalCount: number) => mixed, + +platform: ?string, + +type: 'module' | 'script', +|}; + type DeltaOptions = BundleOptions & { deltaBundleId: ?string, }; @@ -269,22 +284,19 @@ class Server { }; } - async buildGraph(options: BundleOptions): Promise { - const entryPoint = getAbsolutePath( - options.entryFile, - this._opts.projectRoots, - ); - + async buildGraph(options: BuildGraphOptions): Promise { return await this._deltaBundler.buildGraph({ assetPlugins: options.assetPlugins, customTransformOptions: options.customTransformOptions, dev: options.dev, - entryPoints: [entryPoint], + entryPoints: options.entryFiles.map(entryFile => + getAbsolutePath(entryFile, this._opts.projectRoots), + ), hot: options.hot, minify: options.minify, onProgress: options.onProgress, platform: options.platform, - type: 'module', + type: options.type, }); } @@ -1123,20 +1135,24 @@ class Server { return this._opts.projectRoots; } - static DEFAULT_BUNDLE_OPTIONS = { + static DEFAULT_GRAPH_OPTIONS = { assetPlugins: [], customTransformOptions: Object.create(null), dev: true, - entryModuleOnly: false, - excludeSource: false, hot: false, - inlineSourceMap: false, minify: false, onProgress: null, + type: 'module', + }; + + static DEFAULT_BUNDLE_OPTIONS = { + ...Server.DEFAULT_GRAPH_OPTIONS, + entryModuleOnly: false, + excludeSource: false, + inlineSourceMap: false, runBeforeMainModule: [], runModule: true, sourceMapUrl: null, - type: 'script', }; } diff --git a/packages/metro/src/index.js b/packages/metro/src/index.js index ae4fa8ea..079ad6bf 100644 --- a/packages/metro/src/index.js +++ b/packages/metro/src/index.js @@ -279,7 +279,7 @@ exports.runServer = async ({ type BuildGraphOptions = {| ...PublicMetroOptions, - entry: string, + entries: $ReadOnlyArray, dev?: boolean, onProgress?: (transformedFileCount: number, totalFileCount: number) => void, platform?: string, @@ -287,10 +287,12 @@ type BuildGraphOptions = {| type RunBuildOptions = {| ...PublicMetroOptions, - ...BuildGraphOptions, + entry: string, + dev?: boolean, out: string, onBegin?: () => void, onComplete?: () => void, + onProgress?: (transformedFileCount: number, totalFileCount: number) => void, optimize?: boolean, output?: { build: ( @@ -303,6 +305,7 @@ type RunBuildOptions = {| (...args: Array) => void, ) => Promise, }, + platform?: string, sourceMap?: boolean, sourceMapUrl?: string, |}; @@ -377,7 +380,7 @@ exports.runBuild = async ({ exports.buildGraph = async function({ config, dev = false, - entry, + entries, onProgress, platform = `web`, ...rest @@ -390,10 +393,9 @@ exports.buildGraph = async function({ try { return await metroServer.buildGraph({ - ...MetroServer.DEFAULT_BUNDLE_OPTIONS, - bundleType: 'graph', + ...MetroServer.DEFAULT_GRAPH_OPTIONS, dev, - entryFile: entry, + entryFiles: entries, onProgress, platform, });