packager: worker: strenghten TransformOptions

Reviewed By: davidaurelio

Differential Revision: D4906499

fbshipit-source-id: e7948d09c678d3e270ddd9fd355597eb5d535781
This commit is contained in:
Jean Lauliac 2017-04-19 06:28:02 -07:00 committed by Facebook Github Bot
parent 7253a0d532
commit b721e8207e
4 changed files with 34 additions and 19 deletions

View File

@ -270,14 +270,20 @@ describe('Bundler', function() {
// jest calledWith does not support jasmine.any // jest calledWith does not support jasmine.any
expect(getDependencies.mock.calls[0].slice(0, -2)).toEqual([ expect(getDependencies.mock.calls[0].slice(0, -2)).toEqual([
'/root/foo.js', '/root/foo.js',
{dev: true, recursive: true}, {dev: true, platform: undefined, recursive: true},
{minify: false, {
dev: true, dev: true,
minify: false,
platform: undefined,
transform: { transform: {
dev: true, dev: true,
hot: false,
generateSourceMaps: false, generateSourceMaps: false,
hot: false,
inlineRequires: false,
platform: undefined,
preloadedModules: undefined,
projectRoots, projectRoots,
ramGroups: undefined,
}, },
}, },
]) ])

View File

@ -751,22 +751,31 @@ class Bundler {
getTransformOptions( getTransformOptions(
mainModuleName: string, mainModuleName: string,
options: { options: {|
dev?: boolean, dev: boolean,
generateSourceMaps?: boolean, generateSourceMaps: boolean,
hot?: boolean, hot: boolean,
platform: string, platform: string,
projectRoots: Array<string>, projectRoots: Array<string>,
}, |},
): Promise<TransformOptions> { ): Promise<TransformOptions> {
const getDependencies = (entryFile: string) => const getDependencies = (entryFile: string) =>
this.getDependencies({...options, entryFile}) this.getDependencies({...options, entryFile})
.then(r => r.dependencies.map(d => d.path)); .then(r => r.dependencies.map(d => d.path));
const extraOptions: Promise<?ExtraTransformOptions> = this._getTransformOptions const extraOptions: Promise<ExtraTransformOptions> = this._getTransformOptions
? this._getTransformOptions(mainModuleName, options, getDependencies) ? this._getTransformOptions(mainModuleName, options, getDependencies)
: Promise.resolve(null); : Promise.resolve({});
return extraOptions.then(extraOpts => ({...options, ...extraOpts})); return extraOptions.then(extraOpts => ({
dev: options.dev,
generateSourceMaps: options.generateSourceMaps,
hot: options.hot,
inlineRequires: extraOpts.inlineRequires || false,
platform: options.platform,
preloadedModules: extraOpts.preloadedModules,
projectRoots: options.projectRoots,
ramGroups: extraOpts.ramGroups,
}));
} }
getResolver(): Promise<Resolver> { getResolver(): Promise<Resolver> {

View File

@ -18,7 +18,7 @@ const invariant = require('fbjs/lib/invariant');
const minify = require('./minify'); const minify = require('./minify');
import type {LogEntry} from '../../Logger/Types'; import type {LogEntry} from '../../Logger/Types';
import type {Ast, SourceMap, TransformOptions as BabelTransformOptions} from 'babel-core'; import type {Ast, SourceMap} from 'babel-core';
export type TransformedCode = { export type TransformedCode = {
code: string, code: string,
@ -35,23 +35,23 @@ type Transformer = {
) => {ast: ?Ast, code: string, map: ?SourceMap} ) => {ast: ?Ast, code: string, map: ?SourceMap}
}; };
export type TransformOptions = { export type TransformOptions = {|
+dev: boolean, +dev: boolean,
+generateSourceMaps: boolean, +generateSourceMaps: boolean,
+hot: boolean, +hot: boolean,
+inlineRequires: {+blacklist: {[string]: true}} | boolean, +inlineRequires: {+blacklist: {[string]: true}} | boolean,
+platform: string, +platform: string,
+preloadedModules?: Array<string> | false, +preloadedModules: ?Array<string> | false,
+projectRoots: Array<string>, +projectRoots: Array<string>,
+ramGroups?: Array<string>, +ramGroups: ?Array<string>,
} & BabelTransformOptions; |};
export type Options = { export type Options = {|
+dev: boolean, +dev: boolean,
+minify: boolean, +minify: boolean,
+platform: string, +platform: string,
+transform: TransformOptions, +transform: TransformOptions,
}; |};
export type Data = { export type Data = {
result: TransformedCode, result: TransformedCode,

View File

@ -19,7 +19,7 @@ type SourceMapOrMappings = MixedSourceMap | Array<RawMapping>;
type Metadata = { type Metadata = {
dependencies?: ?Array<string>, dependencies?: ?Array<string>,
dependencyPairs?: Array<[mixed, {path: string}]>, dependencyPairs?: Array<[mixed, {path: string}]>,
preloaded?: boolean, preloaded: ?boolean,
}; };
class ModuleTransport { class ModuleTransport {