packager: stronger option types

Reviewed By: davidaurelio

Differential Revision: D4868612

fbshipit-source-id: 50d72ce56d8e3ef0d917ee5bbe3dd42faf075584
This commit is contained in:
Jean Lauliac 2017-04-12 04:24:47 -07:00 committed by Facebook Github Bot
parent deebf15a56
commit 3c85a6b902
4 changed files with 69 additions and 72 deletions

View File

@ -89,27 +89,26 @@ const assetPropertyBlacklist = new Set([
'path', 'path',
]); ]);
type Options = { type Options = {|
allowBundleUpdates: boolean, +allowBundleUpdates: boolean,
assetExts: Array<string>, +assetExts: Array<string>,
assetServer: AssetServer, +assetServer: AssetServer,
blacklistRE?: RegExp, +blacklistRE?: RegExp,
cacheVersion: string, +cacheVersion: string,
extraNodeModules: {}, +extraNodeModules: {},
getTransformOptions?: GetTransformOptions, +getTransformOptions?: GetTransformOptions,
globalTransformCache: ?GlobalTransformCache, +globalTransformCache: ?GlobalTransformCache,
hasteImpl?: HasteImpl, +hasteImpl?: HasteImpl,
moduleFormat: string, +platforms: Array<string>,
platforms: Array<string>, +polyfillModuleNames: Array<string>,
polyfillModuleNames: Array<string>, +projectRoots: Array<string>,
projectRoots: Array<string>, +providesModuleNodeModules?: Array<string>,
providesModuleNodeModules?: Array<string>, +reporter: Reporter,
reporter: Reporter, +resetCache: boolean,
resetCache: boolean, +transformModulePath?: string,
transformModulePath?: string, +transformTimeoutInterval: ?number,
transformTimeoutInterval: ?number, +watch: boolean,
watch: boolean, |};
};
class Bundler { class Bundler {
@ -190,7 +189,6 @@ class Bundler {
hasteImpl: opts.hasteImpl, hasteImpl: opts.hasteImpl,
maxWorkerCount, maxWorkerCount,
minifyCode: this._transformer.minify, minifyCode: this._transformer.minify,
moduleFormat: opts.moduleFormat,
platforms: new Set(opts.platforms), platforms: new Set(opts.platforms),
polyfillModuleNames: opts.polyfillModuleNames, polyfillModuleNames: opts.polyfillModuleNames,
projectRoots: opts.projectRoots, projectRoots: opts.projectRoots,

View File

@ -29,25 +29,25 @@ import type {GlobalTransformCache} from '../lib/GlobalTransformCache';
type MinifyCode = (filePath: string, code: string, map: SourceMap) => type MinifyCode = (filePath: string, code: string, map: SourceMap) =>
Promise<{code: string, map: SourceMap}>; Promise<{code: string, map: SourceMap}>;
type Options = { type Options = {|
assetExts: Array<string>, +assetExts: Array<string>,
blacklistRE?: RegExp, +blacklistRE?: RegExp,
cache: Cache, +cache: Cache,
extraNodeModules: ?{}, +extraNodeModules: ?{},
getTransformCacheKey: GetTransformCacheKey, +getTransformCacheKey: GetTransformCacheKey,
globalTransformCache: ?GlobalTransformCache, +globalTransformCache: ?GlobalTransformCache,
hasteImpl?: HasteImpl, +hasteImpl?: HasteImpl,
maxWorkerCount: number, +maxWorkerCount: number,
minifyCode: MinifyCode, +minifyCode: MinifyCode,
platforms: Set<string>, +platforms: Set<string>,
polyfillModuleNames?: Array<string>, +polyfillModuleNames?: Array<string>,
projectRoots: Array<string>, +projectRoots: Array<string>,
providesModuleNodeModules: Array<string>, +providesModuleNodeModules: Array<string>,
reporter: Reporter, +reporter: Reporter,
resetCache: boolean, +resetCache: boolean,
transformCode: TransformCode, +transformCode: TransformCode,
watch: boolean, +watch: boolean,
}; |};
class Resolver { class Resolver {
@ -70,7 +70,6 @@ class Resolver {
return filepath.indexOf('__tests__') !== -1 || return filepath.indexOf('__tests__') !== -1 ||
(opts.blacklistRE != null && opts.blacklistRE.test(filepath)); (opts.blacklistRE != null && opts.blacklistRE.test(filepath));
}, },
maxWorkers: null,
moduleOptions: { moduleOptions: {
cacheTransformResults: true, cacheTransformResults: true,
hasteImpl: opts.hasteImpl, hasteImpl: opts.hasteImpl,

View File

@ -21,8 +21,8 @@ class DependencyGraphHelpers {
_assetExts: Array<string>; _assetExts: Array<string>;
constructor({providesModuleNodeModules, assetExts}: { constructor({providesModuleNodeModules, assetExts}: {
providesModuleNodeModules: Array<string>, +providesModuleNodeModules: Array<string>,
assetExts: Array<string>, +assetExts: Array<string>,
}) { }) {
this._providesModuleNodeModules = providesModuleNodeModules; this._providesModuleNodeModules = providesModuleNodeModules;
this._assetExts = assetExts; this._assetExts = assetExts;

View File

@ -49,28 +49,28 @@ import type {
} from './Module'; } from './Module';
import type {HasteFS} from './types'; import type {HasteFS} from './types';
type Options = { type Options = {|
assetDependencies: Array<string>, +assetDependencies: Array<string>,
assetExts: Array<string>, +assetExts: Array<string>,
cache: Cache, +cache: Cache,
extensions: Array<string>, +extensions: Array<string>,
extraNodeModules: ?{}, +extraNodeModules: ?{},
forceNodeFilesystemAPI: boolean, +forceNodeFilesystemAPI: boolean,
getTransformCacheKey: GetTransformCacheKey, +getTransformCacheKey: GetTransformCacheKey,
globalTransformCache: ?GlobalTransformCache, +globalTransformCache: ?GlobalTransformCache,
ignoreFilePath: (filePath: string) => boolean, +ignoreFilePath: (filePath: string) => boolean,
maxWorkerCount: number, +maxWorkerCount: number,
moduleOptions: ModuleOptions, +moduleOptions: ModuleOptions,
platforms: Set<string>, +platforms: Set<string>,
preferNativePlatform: boolean, +preferNativePlatform: boolean,
providesModuleNodeModules: Array<string>, +providesModuleNodeModules: Array<string>,
reporter: Reporter, +reporter: Reporter,
resetCache: boolean, +resetCache: boolean,
roots: Array<string>, +roots: Array<string>,
transformCode: TransformCode, +transformCode: TransformCode,
useWatchman: boolean, +useWatchman: boolean,
watch: boolean, +watch: boolean,
}; |};
const JEST_HASTE_MAP_CACHE_BREAKER = 1; const JEST_HASTE_MAP_CACHE_BREAKER = 1;
@ -84,12 +84,12 @@ class DependencyGraph extends EventEmitter {
_hasteFS: HasteFS; _hasteFS: HasteFS;
_moduleMap: ModuleMap; _moduleMap: ModuleMap;
constructor(config: { constructor(config: {|
opts: Options, +opts: Options,
haste: JestHasteMap, +haste: JestHasteMap,
initialHasteFS: HasteFS, +initialHasteFS: HasteFS,
initialModuleMap: ModuleMap, +initialModuleMap: ModuleMap,
}) { |}) {
super(); super();
invariant(config.opts.maxWorkerCount >= 1, 'worker count must be greater or equal to 1'); invariant(config.opts.maxWorkerCount >= 1, 'worker count must be greater or equal to 1');
this._opts = config.opts; this._opts = config.opts;