diff --git a/packages/metro/src/Bundler/index.js b/packages/metro/src/Bundler/index.js index 1f7b4fb0..14e63039 100644 --- a/packages/metro/src/Bundler/index.js +++ b/packages/metro/src/Bundler/index.js @@ -194,11 +194,11 @@ class Bundler { } /** - * Returns the transform options related to a specific entry file, by calling + * Returns the transform options related to several entry files, by calling * the config parameter getTransformOptions(). */ - async getTransformOptionsForEntryFile( - entryFile: string, + async getTransformOptionsForEntryFiles( + entryFiles: $ReadOnlyArray, options: {dev: boolean, platform: ?string}, getDependencies: string => Promise>, ): Promise { @@ -209,7 +209,7 @@ class Bundler { } const {transform} = await this._getTransformOptions( - [entryFile], + entryFiles, {dev: options.dev, hot: true, platform: options.platform}, getDependencies, ); diff --git a/packages/metro/src/DeltaBundler/DeltaCalculator.js b/packages/metro/src/DeltaBundler/DeltaCalculator.js index c2505ee8..2dd10a18 100644 --- a/packages/metro/src/DeltaBundler/DeltaCalculator.js +++ b/packages/metro/src/DeltaBundler/DeltaCalculator.js @@ -18,9 +18,11 @@ const { const {EventEmitter} = require('events'); import type Bundler from '../Bundler'; -import type {Options as JSTransformerOptions} from '../JSTransformer/worker'; +import type { + Options as JSTransformerOptions, + CustomTransformOptions, +} from '../JSTransformer/worker'; import type DependencyGraph from '../node-haste/DependencyGraph'; -import type {BundleOptions} from '../shared/types.flow'; import type {DependencyEdge, Graph} from './traverseDependencies'; export type DeltaResult = {| @@ -31,6 +33,17 @@ export type DeltaResult = {| export type {Graph} from './traverseDependencies'; +export type Options = { + +assetPlugins: Array, + +customTransformOptions: CustomTransformOptions, + +dev: boolean, + +entryPoints: $ReadOnlyArray, + +hot: boolean, + +minify: boolean, + +onProgress: ?(doneCont: number, totalCount: number) => mixed, + +platform: ?string, +}; + /** * This class is in charge of calculating the delta of changed modules that * happen between calls. To do so, it subscribes to file changes, so it can @@ -40,7 +53,7 @@ export type {Graph} from './traverseDependencies'; class DeltaCalculator extends EventEmitter { _bundler: Bundler; _dependencyGraph: DependencyGraph; - _options: BundleOptions; + _options: Options; _transformerOptions: ?JSTransformerOptions; _currentBuildPromise: ?Promise; @@ -52,7 +65,7 @@ class DeltaCalculator extends EventEmitter { constructor( bundler: Bundler, dependencyGraph: DependencyGraph, - options: BundleOptions, + options: Options, ) { super(); @@ -60,11 +73,9 @@ class DeltaCalculator extends EventEmitter { this._options = options; this._dependencyGraph = dependencyGraph; - // The traverse dependencies logic supports multiple entry points, but - // currently metro only supports to pass a single entry point when bundling. - const entryPoints = [ - this._dependencyGraph.getAbsolutePath(this._options.entryFile), - ]; + const entryPoints = this._options.entryPoints.map(entryPoint => + this._dependencyGraph.getAbsolutePath(entryPoint), + ); this._graph = { dependencies: new Map(), @@ -89,7 +100,7 @@ class DeltaCalculator extends EventEmitter { // Clean up all the cache data structures to deallocate memory. this._graph = { dependencies: new Map(), - entryPoints: [this._options.entryFile], + entryPoints: this._options.entryPoints, }; this._modifiedFiles = new Set(); this._deletedFiles = new Set(); @@ -194,8 +205,8 @@ class DeltaCalculator extends EventEmitter { const { inlineRequires, - } = await this._bundler.getTransformOptionsForEntryFile( - this._options.entryFile, + } = await this._bundler.getTransformOptionsForEntryFiles( + this._options.entryPoints, {dev: this._options.dev, platform: this._options.platform}, async path => { const {added} = await initialTraverseDependencies( diff --git a/packages/metro/src/DeltaBundler/DeltaTransformer.js b/packages/metro/src/DeltaBundler/DeltaTransformer.js index f84c1dd9..c5658aa8 100644 --- a/packages/metro/src/DeltaBundler/DeltaTransformer.js +++ b/packages/metro/src/DeltaBundler/DeltaTransformer.js @@ -124,11 +124,10 @@ class DeltaTransformer extends EventEmitter { ): Promise { const dependencyGraph = await bundler.getDependencyGraph(); - const deltaCalculator = new DeltaCalculator( - bundler, - dependencyGraph, - bundleOptions, - ); + const deltaCalculator = new DeltaCalculator(bundler, dependencyGraph, { + ...bundleOptions, + entryPoints: [bundleOptions.entryFile], + }); return new DeltaTransformer( bundler, diff --git a/packages/metro/src/DeltaBundler/__tests__/DeltaCalculator-test.js b/packages/metro/src/DeltaBundler/__tests__/DeltaCalculator-test.js index 92b6b15c..616ff076 100644 --- a/packages/metro/src/DeltaBundler/__tests__/DeltaCalculator-test.js +++ b/packages/metro/src/DeltaBundler/__tests__/DeltaCalculator-test.js @@ -43,7 +43,7 @@ describe('DeltaCalculator', () => { const options = { assetPlugins: [], dev: true, - entryFile: 'bundle', + entryPoints: ['bundle'], entryModuleOnly: false, excludeSource: false, hot: true, @@ -137,7 +137,7 @@ describe('DeltaCalculator', () => { projectRoot: '/foo', }); - Bundler.prototype.getTransformOptionsForEntryFile.mockReturnValue( + Bundler.prototype.getTransformOptionsForEntryFiles.mockReturnValue( Promise.resolve({ inlineRequires: false, }), @@ -416,7 +416,7 @@ describe('DeltaCalculator', () => { }); it('should handle inlineRequires=true correctly', async () => { - Bundler.prototype.getTransformOptionsForEntryFile.mockReturnValue( + Bundler.prototype.getTransformOptionsForEntryFiles.mockReturnValue( Promise.resolve({ inlineRequires: true, }), @@ -435,7 +435,7 @@ describe('DeltaCalculator', () => { }); it('should handle an inline requires blacklist correctly', async () => { - Bundler.prototype.getTransformOptionsForEntryFile.mockReturnValue( + Bundler.prototype.getTransformOptionsForEntryFiles.mockReturnValue( Promise.resolve({ inlineRequires: {blacklist: {'/bar': true, '/baz': true}}, }), diff --git a/packages/metro/src/__fixtures__/getTransformOptions.js b/packages/metro/src/__fixtures__/getTransformOptions.js index 00ea8e74..61ea5eec 100644 --- a/packages/metro/src/__fixtures__/getTransformOptions.js +++ b/packages/metro/src/__fixtures__/getTransformOptions.js @@ -22,7 +22,7 @@ async function getTransformOptions(): Promise { projectRoot: '/root', }; }, - async getTransformOptionsForEntryFile() { + async getTransformOptionsForEntryFiles() { return { inlineRequires: true, }; @@ -39,6 +39,7 @@ async function getTransformOptions(): Promise { const options = { assetPlugins: [], dev: true, + entryPoints: [], hot: true, minify: false, platform: 'ios',