mirror of https://github.com/status-im/metro.git
Stronger typing for transform options / remove duplication
Reviewed By: jeanlauliac Differential Revision: D4929276 fbshipit-source-id: 0b23435a1502c72377425cae775e258106a5bf14
This commit is contained in:
parent
3e9063fba6
commit
ca24ab1da6
|
@ -41,7 +41,7 @@ class Bundle extends BundleBase {
|
||||||
_minify: boolean | void;
|
_minify: boolean | void;
|
||||||
_numRequireCalls: number;
|
_numRequireCalls: number;
|
||||||
_ramBundle: Unbundle | null;
|
_ramBundle: Unbundle | null;
|
||||||
_ramGroups: Array<string> | void;
|
_ramGroups: ?Array<string>;
|
||||||
_sourceMap: string | null;
|
_sourceMap: string | null;
|
||||||
_sourceMapFormat: SourceMapFormat;
|
_sourceMapFormat: SourceMapFormat;
|
||||||
_sourceMapUrl: ?string;
|
_sourceMapUrl: ?string;
|
||||||
|
@ -309,7 +309,7 @@ class Bundle extends BundleBase {
|
||||||
].join('\n');
|
].join('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
setRamGroups(ramGroups: Array<string>) {
|
setRamGroups(ramGroups: ?Array<string>) {
|
||||||
this._ramGroups = ramGroups;
|
this._ramGroups = ramGroups;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,16 +47,22 @@ import type {
|
||||||
import type {Reporter} from '../lib/reporting';
|
import type {Reporter} from '../lib/reporting';
|
||||||
import type {GlobalTransformCache} from '../lib/GlobalTransformCache';
|
import type {GlobalTransformCache} from '../lib/GlobalTransformCache';
|
||||||
|
|
||||||
export type ExtraTransformOptions = {
|
export type ExtraTransformOptions = {|
|
||||||
+inlineRequires?: {+blacklist: {[string]: true}} | boolean,
|
+inlineRequires?: {+blacklist: {[string]: true}} | boolean,
|
||||||
+preloadedModules?: Array<string> | false,
|
+preloadedModules?: {[path: string]: true} | false,
|
||||||
+ramGroups?: Array<string>,
|
+ramGroups?: Array<string>,
|
||||||
};
|
|};
|
||||||
|
|
||||||
|
export type GetTransformOptionsOpts = {|
|
||||||
|
dev: boolean,
|
||||||
|
hot: boolean,
|
||||||
|
platform: string,
|
||||||
|
|};
|
||||||
|
|
||||||
export type GetTransformOptions = (
|
export type GetTransformOptions = (
|
||||||
mainModuleName: string,
|
mainModuleName: string,
|
||||||
options: {},
|
options: GetTransformOptionsOpts,
|
||||||
getDependencies: string => Promise<Array<string>>,
|
getDependenciesOf: string => Promise<Array<string>>,
|
||||||
) => Promise<ExtraTransformOptions>;
|
) => Promise<ExtraTransformOptions>;
|
||||||
|
|
||||||
type Asset = {|
|
type Asset = {|
|
||||||
|
@ -749,7 +755,7 @@ class Bundler {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getTransformOptions(
|
async getTransformOptions(
|
||||||
mainModuleName: string,
|
mainModuleName: string,
|
||||||
options: {|
|
options: {|
|
||||||
dev: boolean,
|
dev: boolean,
|
||||||
|
@ -758,24 +764,25 @@ class Bundler {
|
||||||
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 {dev, hot, platform} = options;
|
||||||
? this._getTransformOptions(mainModuleName, options, getDependencies)
|
const extraOptions = this._getTransformOptions
|
||||||
: Promise.resolve({});
|
? await this._getTransformOptions(mainModuleName, {dev, hot, platform}, getDependencies)
|
||||||
return extraOptions.then(extraOpts => ({
|
: {};
|
||||||
dev: options.dev,
|
return {
|
||||||
|
dev,
|
||||||
generateSourceMaps: options.generateSourceMaps,
|
generateSourceMaps: options.generateSourceMaps,
|
||||||
hot: options.hot,
|
hot,
|
||||||
inlineRequires: extraOpts.inlineRequires || false,
|
inlineRequires: extraOptions.inlineRequires || false,
|
||||||
platform: options.platform,
|
platform,
|
||||||
preloadedModules: extraOpts.preloadedModules,
|
preloadedModules: extraOptions.preloadedModules,
|
||||||
projectRoots: options.projectRoots,
|
projectRoots: options.projectRoots,
|
||||||
ramGroups: extraOpts.ramGroups,
|
ramGroups: extraOptions.ramGroups,
|
||||||
}));
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
getResolver(): Promise<Resolver> {
|
getResolver(): Promise<Resolver> {
|
||||||
|
|
|
@ -41,7 +41,7 @@ export type TransformOptions = {|
|
||||||
+hot: boolean,
|
+hot: boolean,
|
||||||
+inlineRequires: {+blacklist: {[string]: true}} | boolean,
|
+inlineRequires: {+blacklist: {[string]: true}} | boolean,
|
||||||
+platform: string,
|
+platform: string,
|
||||||
+preloadedModules: ?Array<string> | false,
|
+preloadedModules: ?{[string]: true} | false,
|
||||||
+projectRoots: Array<string>,
|
+projectRoots: Array<string>,
|
||||||
+ramGroups: ?Array<string>,
|
+ramGroups: ?Array<string>,
|
||||||
|};
|
|};
|
||||||
|
|
Loading…
Reference in New Issue