mirror of https://github.com/status-im/metro.git
packager: worker: strenghten TransformOptions
Reviewed By: davidaurelio Differential Revision: D4906499 fbshipit-source-id: e7948d09c678d3e270ddd9fd355597eb5d535781
This commit is contained in:
parent
7253a0d532
commit
b721e8207e
|
@ -270,14 +270,20 @@ describe('Bundler', function() {
|
|||
// jest calledWith does not support jasmine.any
|
||||
expect(getDependencies.mock.calls[0].slice(0, -2)).toEqual([
|
||||
'/root/foo.js',
|
||||
{dev: true, recursive: true},
|
||||
{minify: false,
|
||||
{dev: true, platform: undefined, recursive: true},
|
||||
{
|
||||
dev: true,
|
||||
minify: false,
|
||||
platform: undefined,
|
||||
transform: {
|
||||
dev: true,
|
||||
hot: false,
|
||||
generateSourceMaps: false,
|
||||
hot: false,
|
||||
inlineRequires: false,
|
||||
platform: undefined,
|
||||
preloadedModules: undefined,
|
||||
projectRoots,
|
||||
ramGroups: undefined,
|
||||
},
|
||||
},
|
||||
])
|
||||
|
|
|
@ -751,22 +751,31 @@ class Bundler {
|
|||
|
||||
getTransformOptions(
|
||||
mainModuleName: string,
|
||||
options: {
|
||||
dev?: boolean,
|
||||
generateSourceMaps?: boolean,
|
||||
hot?: boolean,
|
||||
options: {|
|
||||
dev: boolean,
|
||||
generateSourceMaps: boolean,
|
||||
hot: boolean,
|
||||
platform: string,
|
||||
projectRoots: Array<string>,
|
||||
},
|
||||
|},
|
||||
): Promise<TransformOptions> {
|
||||
const getDependencies = (entryFile: string) =>
|
||||
this.getDependencies({...options, entryFile})
|
||||
.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)
|
||||
: Promise.resolve(null);
|
||||
return extraOptions.then(extraOpts => ({...options, ...extraOpts}));
|
||||
: Promise.resolve({});
|
||||
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> {
|
||||
|
|
|
@ -18,7 +18,7 @@ const invariant = require('fbjs/lib/invariant');
|
|||
const minify = require('./minify');
|
||||
|
||||
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 = {
|
||||
code: string,
|
||||
|
@ -35,23 +35,23 @@ type Transformer = {
|
|||
) => {ast: ?Ast, code: string, map: ?SourceMap}
|
||||
};
|
||||
|
||||
export type TransformOptions = {
|
||||
export type TransformOptions = {|
|
||||
+dev: boolean,
|
||||
+generateSourceMaps: boolean,
|
||||
+hot: boolean,
|
||||
+inlineRequires: {+blacklist: {[string]: true}} | boolean,
|
||||
+platform: string,
|
||||
+preloadedModules?: Array<string> | false,
|
||||
+preloadedModules: ?Array<string> | false,
|
||||
+projectRoots: Array<string>,
|
||||
+ramGroups?: Array<string>,
|
||||
} & BabelTransformOptions;
|
||||
+ramGroups: ?Array<string>,
|
||||
|};
|
||||
|
||||
export type Options = {
|
||||
export type Options = {|
|
||||
+dev: boolean,
|
||||
+minify: boolean,
|
||||
+platform: string,
|
||||
+transform: TransformOptions,
|
||||
};
|
||||
|};
|
||||
|
||||
export type Data = {
|
||||
result: TransformedCode,
|
||||
|
|
|
@ -19,7 +19,7 @@ type SourceMapOrMappings = MixedSourceMap | Array<RawMapping>;
|
|||
type Metadata = {
|
||||
dependencies?: ?Array<string>,
|
||||
dependencyPairs?: Array<[mixed, {path: string}]>,
|
||||
preloaded?: boolean,
|
||||
preloaded: ?boolean,
|
||||
};
|
||||
|
||||
class ModuleTransport {
|
||||
|
|
Loading…
Reference in New Issue