mirror of https://github.com/status-im/metro.git
Saner entry point
Summary: makes flow typing for the entry point more sound and fixes two issues Reviewed By: BYK Differential Revision: D5507650 fbshipit-source-id: 6b03f7de792ffcece4d0d61950e136a61ea7db2e
This commit is contained in:
parent
43457e6674
commit
2dda50893f
|
@ -66,7 +66,7 @@ function debounceAndBatch(fn, delay) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
type Options = {
|
export type Options = {|
|
||||||
assetExts?: Array<string>,
|
assetExts?: Array<string>,
|
||||||
+assetRegistryPath: string,
|
+assetRegistryPath: string,
|
||||||
blacklistRE?: RegExp,
|
blacklistRE?: RegExp,
|
||||||
|
@ -86,7 +86,7 @@ type Options = {
|
||||||
postProcessBundleSourcemap: PostProcessBundleSourcemap,
|
postProcessBundleSourcemap: PostProcessBundleSourcemap,
|
||||||
projectRoots: $ReadOnlyArray<string>,
|
projectRoots: $ReadOnlyArray<string>,
|
||||||
providesModuleNodeModules?: Array<string>,
|
providesModuleNodeModules?: Array<string>,
|
||||||
reporter: Reporter,
|
reporter?: Reporter,
|
||||||
resetCache?: boolean,
|
resetCache?: boolean,
|
||||||
silent?: boolean,
|
silent?: boolean,
|
||||||
+sourceExts: ?Array<string>,
|
+sourceExts: ?Array<string>,
|
||||||
|
@ -95,7 +95,7 @@ type Options = {
|
||||||
transformTimeoutInterval?: number,
|
transformTimeoutInterval?: number,
|
||||||
watch?: boolean,
|
watch?: boolean,
|
||||||
workerPath: ?string,
|
workerPath: ?string,
|
||||||
};
|
|};
|
||||||
|
|
||||||
export type BundleOptions = {
|
export type BundleOptions = {
|
||||||
+assetPlugins: Array<string>,
|
+assetPlugins: Array<string>,
|
||||||
|
@ -174,6 +174,8 @@ class Server {
|
||||||
_nextBundleBuildID: number;
|
_nextBundleBuildID: number;
|
||||||
|
|
||||||
constructor(options: Options) {
|
constructor(options: Options) {
|
||||||
|
const reporter =
|
||||||
|
options.reporter || require('../lib/reporting').nullReporter;
|
||||||
const maxWorkers = getMaxWorkers(options.maxWorkers);
|
const maxWorkers = getMaxWorkers(options.maxWorkers);
|
||||||
this._opts = {
|
this._opts = {
|
||||||
assetExts: options.assetExts || defaults.assetExts,
|
assetExts: options.assetExts || defaults.assetExts,
|
||||||
|
@ -199,7 +201,7 @@ class Server {
|
||||||
postProcessBundleSourcemap: options.postProcessBundleSourcemap,
|
postProcessBundleSourcemap: options.postProcessBundleSourcemap,
|
||||||
projectRoots: options.projectRoots,
|
projectRoots: options.projectRoots,
|
||||||
providesModuleNodeModules: options.providesModuleNodeModules,
|
providesModuleNodeModules: options.providesModuleNodeModules,
|
||||||
reporter: options.reporter,
|
reporter,
|
||||||
resetCache: options.resetCache || false,
|
resetCache: options.resetCache || false,
|
||||||
silent: options.silent || false,
|
silent: options.silent || false,
|
||||||
sourceExts: options.sourceExts || defaults.sourceExts,
|
sourceExts: options.sourceExts || defaults.sourceExts,
|
||||||
|
@ -213,7 +215,7 @@ class Server {
|
||||||
const processFileChange = ({type, filePath}) =>
|
const processFileChange = ({type, filePath}) =>
|
||||||
this.onFileChange(type, filePath);
|
this.onFileChange(type, filePath);
|
||||||
|
|
||||||
this._reporter = options.reporter;
|
this._reporter = reporter;
|
||||||
this._projectRoots = this._opts.projectRoots;
|
this._projectRoots = this._opts.projectRoots;
|
||||||
this._bundles = Object.create(null);
|
this._bundles = Object.create(null);
|
||||||
this._changeWatchers = [];
|
this._changeWatchers = [];
|
||||||
|
@ -230,7 +232,7 @@ class Server {
|
||||||
bundlerOpts.allowBundleUpdates = this._opts.watch;
|
bundlerOpts.allowBundleUpdates = this._opts.watch;
|
||||||
bundlerOpts.globalTransformCache = options.globalTransformCache;
|
bundlerOpts.globalTransformCache = options.globalTransformCache;
|
||||||
bundlerOpts.watch = this._opts.watch;
|
bundlerOpts.watch = this._opts.watch;
|
||||||
bundlerOpts.reporter = options.reporter;
|
bundlerOpts.reporter = reporter;
|
||||||
this._bundler = new Bundler(bundlerOpts);
|
this._bundler = new Bundler(bundlerOpts);
|
||||||
|
|
||||||
// changes to the haste map can affect resolution of files in the bundle
|
// changes to the haste map can affect resolution of files in the bundle
|
||||||
|
|
|
@ -21,7 +21,7 @@ const invariant = require('fbjs/lib/invariant');
|
||||||
const {fromRawMappings, compactMapping} = require('./Bundler/source-map');
|
const {fromRawMappings, compactMapping} = require('./Bundler/source-map');
|
||||||
|
|
||||||
import type {PostProcessModules, PostMinifyProcess, PostProcessBundleSourcemap} from './Bundler';
|
import type {PostProcessModules, PostMinifyProcess, PostProcessBundleSourcemap} from './Bundler';
|
||||||
import type Server from './Server';
|
import type Server, {Options as ServerOptions} from './Server';
|
||||||
import type {GlobalTransformCache} from './lib/GlobalTransformCache';
|
import type {GlobalTransformCache} from './lib/GlobalTransformCache';
|
||||||
import type {TransformCache} from './lib/TransformCaching';
|
import type {TransformCache} from './lib/TransformCaching';
|
||||||
import type {Reporter} from './lib/reporting';
|
import type {Reporter} from './lib/reporting';
|
||||||
|
@ -33,27 +33,13 @@ exports.createServer = createServer;
|
||||||
exports.Logger = Logger;
|
exports.Logger = Logger;
|
||||||
|
|
||||||
type Options = {|
|
type Options = {|
|
||||||
+assetRegistryPath: string,
|
...ServerOptions,
|
||||||
+sourceExts: ?Array<string>,
|
// optional types to force flow errors in `toServerOptions`
|
||||||
+transformCache: TransformCache,
|
nonPersistent?: ?boolean,
|
||||||
+transformModulePath: string,
|
transformCache?: ?TransformCache,
|
||||||
enableBabelRCLookup?: boolean,
|
verbose?: ?boolean,
|
||||||
getPolyfills: ({platform: ?string}) => $ReadOnlyArray<string>,
|
|
||||||
globalTransformCache: ?GlobalTransformCache,
|
|
||||||
hasteImpl?: HasteImpl,
|
|
||||||
+maxWorkers?: number,
|
|
||||||
nonPersistent?: boolean,
|
|
||||||
postMinifyProcess?: PostMinifyProcess,
|
|
||||||
postProcessBundleSourcemap?: PostProcessBundleSourcemap,
|
|
||||||
postProcessModules?: PostProcessModules,
|
|
||||||
projectRoots: $ReadOnlyArray<string>,
|
|
||||||
reporter?: Reporter,
|
|
||||||
watch?: boolean,
|
|
||||||
workerPath: ?string,
|
|
||||||
|};
|
|};
|
||||||
|
|
||||||
type StrictOptions = {...Options, reporter: Reporter};
|
|
||||||
|
|
||||||
type PublicBundleOptions = {
|
type PublicBundleOptions = {
|
||||||
+dev?: boolean,
|
+dev?: boolean,
|
||||||
+entryFile: string,
|
+entryFile: string,
|
||||||
|
@ -127,7 +113,7 @@ function enableDebug() {
|
||||||
debug.enable(debugPattern);
|
debug.enable(debugPattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createServer(options: StrictOptions): Server {
|
function createServer(options: Options): Server {
|
||||||
// the debug module is configured globally, we need to enable debugging
|
// the debug module is configured globally, we need to enable debugging
|
||||||
// *before* requiring any packages that use `debug` for logging
|
// *before* requiring any packages that use `debug` for logging
|
||||||
if (options.verbose) {
|
if (options.verbose) {
|
||||||
|
@ -135,25 +121,45 @@ function createServer(options: StrictOptions): Server {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Some callsites may not be Flowified yet.
|
// Some callsites may not be Flowified yet.
|
||||||
invariant(options.reporter != null, 'createServer() requires reporter');
|
invariant(options.assetRegistryPath != null, 'createServer() requires assetRegistryPath');
|
||||||
if (options.transformCache == null) {
|
|
||||||
options.transformCache = TransformCaching.useTempDir();
|
|
||||||
}
|
|
||||||
const serverOptions = Object.assign({}, options);
|
|
||||||
delete serverOptions.verbose;
|
|
||||||
const ServerClass = require('./Server');
|
const ServerClass = require('./Server');
|
||||||
return new ServerClass(serverOptions);
|
return new ServerClass(toServerOptions(options));
|
||||||
}
|
}
|
||||||
|
|
||||||
function createNonPersistentServer(options: Options): Server {
|
function createNonPersistentServer(options: Options): Server {
|
||||||
const serverOptions = {
|
return createServer(options);
|
||||||
// It's unsound to set-up the reporter here,
|
}
|
||||||
// but this allows backward compatibility.
|
|
||||||
reporter: options.reporter == null
|
function toServerOptions(options: Options): ServerOptions {
|
||||||
? require('./lib/reporting').nullReporter
|
return {
|
||||||
: options.reporter,
|
assetExts: options.assetExts,
|
||||||
...options,
|
assetRegistryPath: options.assetRegistryPath,
|
||||||
watch: !options.nonPersistent,
|
blacklistRE: options.blacklistRE,
|
||||||
};
|
cacheVersion: options.cacheVersion,
|
||||||
return createServer(serverOptions);
|
enableBabelRCLookup: options.enableBabelRCLookup,
|
||||||
|
extraNodeModules: options.extraNodeModules,
|
||||||
|
getPolyfills: options.getPolyfills,
|
||||||
|
getTransformOptions: options.getTransformOptions,
|
||||||
|
globalTransformCache: options.globalTransformCache,
|
||||||
|
hasteImpl: options.hasteImpl,
|
||||||
|
maxWorkers: options.maxWorkers,
|
||||||
|
moduleFormat: options.moduleFormat,
|
||||||
|
platforms: options.platforms,
|
||||||
|
polyfillModuleNames: options.polyfillModuleNames,
|
||||||
|
postProcessModules: options.postProcessModules,
|
||||||
|
postMinifyProcess: options.postMinifyProcess,
|
||||||
|
postProcessBundleSourcemap: options.postProcessBundleSourcemap,
|
||||||
|
projectRoots: options.projectRoots,
|
||||||
|
providesModuleNodeModules: options.providesModuleNodeModules,
|
||||||
|
reporter: options.reporter,
|
||||||
|
resetCache: options.resetCache,
|
||||||
|
silent: options.silent,
|
||||||
|
sourceExts: options.sourceExts,
|
||||||
|
transformCache: options.transformCache || TransformCaching.useTempDir(),
|
||||||
|
transformModulePath: options.transformModulePath,
|
||||||
|
transformTimeoutInterval: options.transformTimeoutInterval,
|
||||||
|
watch: typeof options.watch === 'boolean' ? options.watch : !!options.nonPersistent,
|
||||||
|
workerPath: options.workerPath,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue