packager: Resolver: remove opt defaults, simplify load()
Summary: Not having default everywhere (keeping them at the top level instead) makes for a code that is easier to understand, and more robust as different pieces of code cannot default to different values. This changeset also unifies the option types (ex. `platform`). Reviewed By: cpojer Differential Revision: D4688882 fbshipit-source-id: b5f407601386336f937a0ac1f68c666acc89dfd8
This commit is contained in:
parent
d9ae27ba89
commit
3e1542b485
|
@ -24,6 +24,7 @@ const ModuleTransport = require('../lib/ModuleTransport');
|
|||
const imageSize = require('image-size');
|
||||
const path = require('path');
|
||||
const denodeify = require('denodeify');
|
||||
const defaults = require('../../defaults');
|
||||
|
||||
const {
|
||||
sep: pathSeparator,
|
||||
|
@ -179,10 +180,11 @@ class Bundler {
|
|||
hasteImpl: opts.hasteImpl,
|
||||
minifyCode: this._transformer.minify,
|
||||
moduleFormat: opts.moduleFormat,
|
||||
platforms: opts.platforms,
|
||||
platforms: new Set(opts.platforms),
|
||||
polyfillModuleNames: opts.polyfillModuleNames,
|
||||
projectRoots: opts.projectRoots,
|
||||
providesModuleNodeModules: opts.providesModuleNodeModules,
|
||||
providesModuleNodeModules:
|
||||
opts.providesModuleNodeModules || defaults.providesModuleNodeModules,
|
||||
reporter: opts.reporter,
|
||||
resetCache: opts.resetCache,
|
||||
transformCode:
|
||||
|
|
|
@ -33,19 +33,19 @@ type Options = {
|
|||
assetExts: Array<string>,
|
||||
blacklistRE?: RegExp,
|
||||
cache: Cache,
|
||||
extraNodeModules?: {},
|
||||
extraNodeModules: ?{},
|
||||
getTransformCacheKey: GetTransformCacheKey,
|
||||
globalTransformCache: ?GlobalTransformCache,
|
||||
hasteImpl?: HasteImpl,
|
||||
minifyCode: MinifyCode,
|
||||
platforms: Array<string>,
|
||||
platforms: Set<string>,
|
||||
polyfillModuleNames?: Array<string>,
|
||||
projectRoots: Array<string>,
|
||||
providesModuleNodeModules?: Array<string>,
|
||||
providesModuleNodeModules: Array<string>,
|
||||
reporter: Reporter,
|
||||
resetCache: boolean,
|
||||
transformCode: TransformCode,
|
||||
watch?: boolean,
|
||||
watch: boolean,
|
||||
};
|
||||
|
||||
class Resolver {
|
||||
|
@ -61,15 +61,10 @@ class Resolver {
|
|||
}
|
||||
|
||||
static async load(opts: Options): Promise<Resolver> {
|
||||
const depGraph = await DependencyGraph.load({
|
||||
const depGraphOpts = Object.assign(Object.create(opts), {
|
||||
assetDependencies: ['react-native/Libraries/Image/AssetRegistry'],
|
||||
assetExts: opts.assetExts,
|
||||
cache: opts.cache,
|
||||
extraNodeModules: opts.extraNodeModules,
|
||||
extensions: ['js', 'json'],
|
||||
forceNodeFilesystemAPI: false,
|
||||
getTransformCacheKey: opts.getTransformCacheKey,
|
||||
globalTransformCache: opts.globalTransformCache,
|
||||
ignoreFilePath(filepath) {
|
||||
return filepath.indexOf('__tests__') !== -1 ||
|
||||
(opts.blacklistRE != null && opts.blacklistRE.test(filepath));
|
||||
|
@ -80,17 +75,11 @@ class Resolver {
|
|||
hasteImpl: opts.hasteImpl,
|
||||
resetCache: opts.resetCache,
|
||||
},
|
||||
platforms: new Set(opts.platforms),
|
||||
preferNativePlatform: true,
|
||||
providesModuleNodeModules:
|
||||
opts.providesModuleNodeModules || defaults.providesModuleNodeModules,
|
||||
reporter: opts.reporter,
|
||||
resetCache: opts.resetCache,
|
||||
roots: opts.projectRoots,
|
||||
transformCode: opts.transformCode,
|
||||
useWatchman: true,
|
||||
watch: opts.watch || false,
|
||||
});
|
||||
const depGraph = await DependencyGraph.load(depGraphOpts);
|
||||
return new Resolver(opts, depGraph);
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ type Options = {
|
|||
assetExts: Array<string>,
|
||||
cache: Cache,
|
||||
extensions: Array<string>,
|
||||
extraNodeModules: ?Object,
|
||||
extraNodeModules: ?{},
|
||||
forceNodeFilesystemAPI: boolean,
|
||||
getTransformCacheKey: GetTransformCacheKey,
|
||||
globalTransformCache: ?GlobalTransformCache,
|
||||
|
@ -87,7 +87,7 @@ class DependencyGraph extends EventEmitter {
|
|||
initialModuleMap: ModuleMap,
|
||||
}) {
|
||||
super();
|
||||
this._opts = {...config.opts};
|
||||
this._opts = config.opts;
|
||||
this._haste = config.haste;
|
||||
this._hasteFS = config.initialHasteFS;
|
||||
this._moduleMap = config.initialModuleMap;
|
||||
|
|
Loading…
Reference in New Issue