Stronger typing for transform options / remove duplication

Reviewed By: jeanlauliac

Differential Revision: D4929276

fbshipit-source-id: 0b23435a1502c72377425cae775e258106a5bf14
This commit is contained in:
David Aurelio 2017-04-21 08:40:38 -07:00 committed by Facebook Github Bot
parent 3e9063fba6
commit ca24ab1da6
3 changed files with 28 additions and 21 deletions

View File

@ -41,7 +41,7 @@ class Bundle extends BundleBase {
_minify: boolean | void;
_numRequireCalls: number;
_ramBundle: Unbundle | null;
_ramGroups: Array<string> | void;
_ramGroups: ?Array<string>;
_sourceMap: string | null;
_sourceMapFormat: SourceMapFormat;
_sourceMapUrl: ?string;
@ -309,7 +309,7 @@ class Bundle extends BundleBase {
].join('\n');
}
setRamGroups(ramGroups: Array<string>) {
setRamGroups(ramGroups: ?Array<string>) {
this._ramGroups = ramGroups;
}
}

View File

@ -47,16 +47,22 @@ import type {
import type {Reporter} from '../lib/reporting';
import type {GlobalTransformCache} from '../lib/GlobalTransformCache';
export type ExtraTransformOptions = {
export type ExtraTransformOptions = {|
+inlineRequires?: {+blacklist: {[string]: true}} | boolean,
+preloadedModules?: Array<string> | false,
+preloadedModules?: {[path: string]: true} | false,
+ramGroups?: Array<string>,
};
|};
export type GetTransformOptionsOpts = {|
dev: boolean,
hot: boolean,
platform: string,
|};
export type GetTransformOptions = (
mainModuleName: string,
options: {},
getDependencies: string => Promise<Array<string>>,
options: GetTransformOptionsOpts,
getDependenciesOf: string => Promise<Array<string>>,
) => Promise<ExtraTransformOptions>;
type Asset = {|
@ -749,7 +755,7 @@ class Bundler {
});
}
getTransformOptions(
async getTransformOptions(
mainModuleName: string,
options: {|
dev: boolean,
@ -763,19 +769,20 @@ class Bundler {
this.getDependencies({...options, entryFile})
.then(r => r.dependencies.map(d => d.path));
const extraOptions: Promise<ExtraTransformOptions> = this._getTransformOptions
? this._getTransformOptions(mainModuleName, options, getDependencies)
: Promise.resolve({});
return extraOptions.then(extraOpts => ({
dev: options.dev,
const {dev, hot, platform} = options;
const extraOptions = this._getTransformOptions
? await this._getTransformOptions(mainModuleName, {dev, hot, platform}, getDependencies)
: {};
return {
dev,
generateSourceMaps: options.generateSourceMaps,
hot: options.hot,
inlineRequires: extraOpts.inlineRequires || false,
platform: options.platform,
preloadedModules: extraOpts.preloadedModules,
hot,
inlineRequires: extraOptions.inlineRequires || false,
platform,
preloadedModules: extraOptions.preloadedModules,
projectRoots: options.projectRoots,
ramGroups: extraOpts.ramGroups,
}));
ramGroups: extraOptions.ramGroups,
};
}
getResolver(): Promise<Resolver> {

View File

@ -41,7 +41,7 @@ export type TransformOptions = {|
+hot: boolean,
+inlineRequires: {+blacklist: {[string]: true}} | boolean,
+platform: string,
+preloadedModules: ?Array<string> | false,
+preloadedModules: ?{[string]: true} | false,
+projectRoots: Array<string>,
+ramGroups: ?Array<string>,
|};