Skip to content

Commit

Permalink
Stronger typing for transform options / remove duplication
Browse files Browse the repository at this point in the history
Reviewed By: jeanlauliac

Differential Revision: D4929276

fbshipit-source-id: 0b23435a1502c72377425cae775e258106a5bf14
  • Loading branch information
davidaurelio authored and facebook-github-bot committed Apr 21, 2017
1 parent 6b19419 commit 13f89f4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
4 changes: 2 additions & 2 deletions packager/src/Bundler/Bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -309,7 +309,7 @@ class Bundle extends BundleBase {
].join('\n');
}

setRamGroups(ramGroups: Array<string>) {
setRamGroups(ramGroups: ?Array<string>) {
this._ramGroups = ramGroups;
}
}
Expand Down
43 changes: 25 additions & 18 deletions packager/src/Bundler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {|
Expand Down Expand Up @@ -749,7 +755,7 @@ class Bundler {
});
}

getTransformOptions(
async getTransformOptions(
mainModuleName: string,
options: {|
dev: boolean,
Expand All @@ -758,24 +764,25 @@ class Bundler {
platform: string,
projectRoots: Array<string>,
|},
): Promise<TransformOptions> {
): Promise<TransformOptions> {
const getDependencies = (entryFile: string) =>
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> {
Expand Down
2 changes: 1 addition & 1 deletion packager/src/JSTransformer/worker/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
|};
Expand Down

0 comments on commit 13f89f4

Please sign in to comment.