Simplify the parameters needed to call the delta calculator

Reviewed By: BYK

Differential Revision: D7185274

fbshipit-source-id: 0bb4040556dfa96f288c9d4aef2314ded44bcd0d
This commit is contained in:
Rafael Oleza 2018-03-19 10:04:45 -07:00 committed by Facebook Github Bot
parent 45123d822b
commit ab25e7c475
5 changed files with 37 additions and 26 deletions

View File

@ -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<string>,
options: {dev: boolean, platform: ?string},
getDependencies: string => Promise<Array<string>>,
): Promise<TransformOptions> {
@ -209,7 +209,7 @@ class Bundler {
}
const {transform} = await this._getTransformOptions(
[entryFile],
entryFiles,
{dev: options.dev, hot: true, platform: options.platform},
getDependencies,
);

View File

@ -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<string>,
+customTransformOptions: CustomTransformOptions,
+dev: boolean,
+entryPoints: $ReadOnlyArray<string>,
+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<DeltaResult>;
@ -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(

View File

@ -124,11 +124,10 @@ class DeltaTransformer extends EventEmitter {
): Promise<DeltaTransformer> {
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,

View File

@ -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}},
}),

View File

@ -22,7 +22,7 @@ async function getTransformOptions(): Promise<JSTransformerOptions> {
projectRoot: '/root',
};
},
async getTransformOptionsForEntryFile() {
async getTransformOptionsForEntryFiles() {
return {
inlineRequires: true,
};
@ -39,6 +39,7 @@ async function getTransformOptions(): Promise<JSTransformerOptions> {
const options = {
assetPlugins: [],
dev: true,
entryPoints: [],
hot: true,
minify: false,
platform: 'ios',