mirror of https://github.com/status-im/metro.git
Clean server.js and runServer.js
Reviewed By: davidaurelio Differential Revision: D7628734 fbshipit-source-id: 3788b35b0f9b5034d9152c5c3b297313fbec231a
This commit is contained in:
parent
a334fd85d2
commit
910a71ba1a
|
@ -25,8 +25,6 @@ import type {
|
||||||
Options as WorkerOptions,
|
Options as WorkerOptions,
|
||||||
} from './JSTransformer/worker';
|
} from './JSTransformer/worker';
|
||||||
import type {DynamicRequiresBehavior} from './ModuleGraph/worker/collectDependencies';
|
import type {DynamicRequiresBehavior} from './ModuleGraph/worker/collectDependencies';
|
||||||
import type {GlobalTransformCache} from './lib/GlobalTransformCache';
|
|
||||||
import type {TransformCache} from './lib/TransformCaching';
|
|
||||||
import type {Reporter} from './lib/reporting';
|
import type {Reporter} from './lib/reporting';
|
||||||
import type Module from './node-haste/Module';
|
import type Module from './node-haste/Module';
|
||||||
import type {BabelSourceMap} from '@babel/core';
|
import type {BabelSourceMap} from '@babel/core';
|
||||||
|
@ -79,7 +77,6 @@ export type Options = {|
|
||||||
+extraNodeModules: {},
|
+extraNodeModules: {},
|
||||||
+getPolyfills: ({platform: ?string}) => $ReadOnlyArray<string>,
|
+getPolyfills: ({platform: ?string}) => $ReadOnlyArray<string>,
|
||||||
+getTransformOptions?: GetTransformOptions,
|
+getTransformOptions?: GetTransformOptions,
|
||||||
+globalTransformCache: ?GlobalTransformCache,
|
|
||||||
+hasteImplModulePath?: string,
|
+hasteImplModulePath?: string,
|
||||||
+maxWorkers: number,
|
+maxWorkers: number,
|
||||||
+minifierPath: string,
|
+minifierPath: string,
|
||||||
|
@ -90,10 +87,8 @@ export type Options = {|
|
||||||
+projectRoots: $ReadOnlyArray<string>,
|
+projectRoots: $ReadOnlyArray<string>,
|
||||||
+providesModuleNodeModules?: Array<string>,
|
+providesModuleNodeModules?: Array<string>,
|
||||||
+reporter: Reporter,
|
+reporter: Reporter,
|
||||||
+resetCache: boolean,
|
|
||||||
+resolveRequest: ?CustomResolver,
|
+resolveRequest: ?CustomResolver,
|
||||||
+sourceExts: Array<string>,
|
+sourceExts: Array<string>,
|
||||||
+transformCache: TransformCache,
|
|
||||||
+transformModulePath: string,
|
+transformModulePath: string,
|
||||||
+watch: boolean,
|
+watch: boolean,
|
||||||
+workerPath: ?string,
|
+workerPath: ?string,
|
||||||
|
@ -154,7 +149,6 @@ class Bundler {
|
||||||
opts.providesModuleNodeModules || defaults.providesModuleNodeModules,
|
opts.providesModuleNodeModules || defaults.providesModuleNodeModules,
|
||||||
reporter: opts.reporter,
|
reporter: opts.reporter,
|
||||||
resolveRequest: opts.resolveRequest,
|
resolveRequest: opts.resolveRequest,
|
||||||
resetCache: opts.resetCache,
|
|
||||||
sourceExts: opts.sourceExts,
|
sourceExts: opts.sourceExts,
|
||||||
transformCode: this._cachedTransformCode.bind(this),
|
transformCode: this._cachedTransformCode.bind(this),
|
||||||
watch: opts.watch,
|
watch: opts.watch,
|
||||||
|
|
|
@ -56,7 +56,6 @@ import type {CacheStore} from 'metro-cache';
|
||||||
import type {Delta, Graph} from './DeltaBundler';
|
import type {Delta, Graph} from './DeltaBundler';
|
||||||
import type {CustomResolver} from 'metro-resolver';
|
import type {CustomResolver} from 'metro-resolver';
|
||||||
import type {MetroSourceMap} from 'metro-source-map';
|
import type {MetroSourceMap} from 'metro-source-map';
|
||||||
import type {TransformCache} from './lib/TransformCaching';
|
|
||||||
import type {Symbolicate} from './Server/symbolicate/symbolicate';
|
import type {Symbolicate} from './Server/symbolicate/symbolicate';
|
||||||
import type {AssetData} from './Assets';
|
import type {AssetData} from './Assets';
|
||||||
import type {
|
import type {
|
||||||
|
@ -125,13 +124,11 @@ class Server {
|
||||||
projectRoots: $ReadOnlyArray<string>,
|
projectRoots: $ReadOnlyArray<string>,
|
||||||
providesModuleNodeModules?: Array<string>,
|
providesModuleNodeModules?: Array<string>,
|
||||||
reporter: Reporter,
|
reporter: Reporter,
|
||||||
resetCache: boolean,
|
|
||||||
resolveRequest: ?CustomResolver,
|
resolveRequest: ?CustomResolver,
|
||||||
+getModulesRunBeforeMainModule: (entryFilePath: string) => Array<string>,
|
+getModulesRunBeforeMainModule: (entryFilePath: string) => Array<string>,
|
||||||
+getRunModuleStatement: (number | string) => string,
|
+getRunModuleStatement: (number | string) => string,
|
||||||
silent: boolean,
|
silent: boolean,
|
||||||
+sourceExts: Array<string>,
|
+sourceExts: Array<string>,
|
||||||
+transformCache: TransformCache,
|
|
||||||
+transformModulePath: string,
|
+transformModulePath: string,
|
||||||
watch: boolean,
|
watch: boolean,
|
||||||
workerPath: ?string,
|
workerPath: ?string,
|
||||||
|
@ -180,7 +177,6 @@ class Server {
|
||||||
getPolyfills: options.getPolyfills,
|
getPolyfills: options.getPolyfills,
|
||||||
getRunModuleStatement: options.getRunModuleStatement,
|
getRunModuleStatement: options.getRunModuleStatement,
|
||||||
getTransformOptions: options.getTransformOptions,
|
getTransformOptions: options.getTransformOptions,
|
||||||
globalTransformCache: options.globalTransformCache,
|
|
||||||
hasteImplModulePath: options.hasteImplModulePath,
|
hasteImplModulePath: options.hasteImplModulePath,
|
||||||
maxWorkers,
|
maxWorkers,
|
||||||
minifierPath:
|
minifierPath:
|
||||||
|
@ -194,19 +190,22 @@ class Server {
|
||||||
projectRoots: options.projectRoots,
|
projectRoots: options.projectRoots,
|
||||||
providesModuleNodeModules: options.providesModuleNodeModules,
|
providesModuleNodeModules: options.providesModuleNodeModules,
|
||||||
reporter,
|
reporter,
|
||||||
resetCache: options.resetCache || false,
|
|
||||||
resolveRequest: options.resolveRequest,
|
resolveRequest: options.resolveRequest,
|
||||||
silent: options.silent || false,
|
silent: options.silent || false,
|
||||||
sourceExts: options.assetTransforms
|
sourceExts: options.assetTransforms
|
||||||
? sourceExts.concat(assetExts)
|
? sourceExts.concat(assetExts)
|
||||||
: sourceExts,
|
: sourceExts,
|
||||||
transformCache: options.transformCache,
|
|
||||||
transformModulePath:
|
transformModulePath:
|
||||||
options.transformModulePath || defaults.transformModulePath,
|
options.transformModulePath || defaults.transformModulePath,
|
||||||
watch: options.watch || false,
|
watch: options.watch || false,
|
||||||
workerPath: options.workerPath,
|
workerPath: options.workerPath,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (options.resetCache) {
|
||||||
|
options.cacheStores.forEach(store => store.clear());
|
||||||
|
reporter.update({type: 'transform_cache_reset'});
|
||||||
|
}
|
||||||
|
|
||||||
const processFileChange = ({type, filePath}) =>
|
const processFileChange = ({type, filePath}) =>
|
||||||
this.onFileChange(type, filePath);
|
this.onFileChange(type, filePath);
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,6 @@ describe('basic_bundle', () => {
|
||||||
getPolyfills: () => [polyfill1, polyfill2],
|
getPolyfills: () => [polyfill1, polyfill2],
|
||||||
getRunModuleStatement,
|
getRunModuleStatement,
|
||||||
projectRoots: [INPUT_PATH, POLYFILLS_PATH],
|
projectRoots: [INPUT_PATH, POLYFILLS_PATH],
|
||||||
transformCache: Metro.TransformCaching.none(),
|
|
||||||
transformModulePath: require.resolve('../../transformer'),
|
transformModulePath: require.resolve('../../transformer'),
|
||||||
nonPersistent: true,
|
nonPersistent: true,
|
||||||
enableBabelRCLookup: false, // dont use metro's own babelrc!
|
enableBabelRCLookup: false, // dont use metro's own babelrc!
|
||||||
|
@ -126,7 +125,6 @@ describe('basic_bundle', () => {
|
||||||
getPolyfills: () => [],
|
getPolyfills: () => [],
|
||||||
getRunModuleStatement,
|
getRunModuleStatement,
|
||||||
projectRoots: [INPUT_PATH, POLYFILLS_PATH],
|
projectRoots: [INPUT_PATH, POLYFILLS_PATH],
|
||||||
transformCache: Metro.TransformCaching.none(),
|
|
||||||
transformModulePath: require.resolve('../../transformer'),
|
transformModulePath: require.resolve('../../transformer'),
|
||||||
nonPersistent: true,
|
nonPersistent: true,
|
||||||
enableBabelRCLookup: false, // dont use metro's own babelrc!
|
enableBabelRCLookup: false, // dont use metro's own babelrc!
|
||||||
|
|
|
@ -10,8 +10,6 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const TransformCaching = require('./lib/TransformCaching');
|
|
||||||
|
|
||||||
const blacklist = require('./blacklist');
|
const blacklist = require('./blacklist');
|
||||||
const debug = require('debug');
|
const debug = require('debug');
|
||||||
const invariant = require('fbjs/lib/invariant');
|
const invariant = require('fbjs/lib/invariant');
|
||||||
|
@ -22,7 +20,6 @@ const {fromRawMappings, toSegmentTuple} = require('metro-source-map');
|
||||||
|
|
||||||
import type {ConfigT as MetroConfig} from './Config';
|
import type {ConfigT as MetroConfig} from './Config';
|
||||||
import type Server from './Server';
|
import type Server from './Server';
|
||||||
import type {TransformCache} from './lib/TransformCaching';
|
|
||||||
import type {Options as ServerOptions} from './shared/types.flow';
|
import type {Options as ServerOptions} from './shared/types.flow';
|
||||||
|
|
||||||
exports.createBlacklist = blacklist;
|
exports.createBlacklist = blacklist;
|
||||||
|
@ -36,7 +33,6 @@ type Options = {|
|
||||||
...ServerOptions,
|
...ServerOptions,
|
||||||
// optional types to force flow errors in `toServerOptions`
|
// optional types to force flow errors in `toServerOptions`
|
||||||
nonPersistent?: ?boolean,
|
nonPersistent?: ?boolean,
|
||||||
transformCache?: ?TransformCache,
|
|
||||||
verbose?: ?boolean,
|
verbose?: ?boolean,
|
||||||
targetBabelVersion?: number,
|
targetBabelVersion?: number,
|
||||||
|};
|
|};
|
||||||
|
@ -51,8 +47,6 @@ type PublicBundleOptions = {
|
||||||
+sourceMapUrl?: string,
|
+sourceMapUrl?: string,
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.TransformCaching = TransformCaching;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a public API, so we don't trust the value and purposefully downgrade
|
* This is a public API, so we don't trust the value and purposefully downgrade
|
||||||
* it as `mixed`. Because it understands `invariant`, Flow ensure that we
|
* it as `mixed`. Because it understands `invariant`, Flow ensure that we
|
||||||
|
@ -184,7 +178,6 @@ function toServerOptions(options: Options): ServerOptions {
|
||||||
getPolyfills: options.getPolyfills,
|
getPolyfills: options.getPolyfills,
|
||||||
getRunModuleStatement: options.getRunModuleStatement,
|
getRunModuleStatement: options.getRunModuleStatement,
|
||||||
getTransformOptions: options.getTransformOptions,
|
getTransformOptions: options.getTransformOptions,
|
||||||
globalTransformCache: options.globalTransformCache,
|
|
||||||
hasteImplModulePath: options.hasteImplModulePath,
|
hasteImplModulePath: options.hasteImplModulePath,
|
||||||
maxWorkers: options.maxWorkers,
|
maxWorkers: options.maxWorkers,
|
||||||
minifierPath: options.minifierPath,
|
minifierPath: options.minifierPath,
|
||||||
|
@ -199,7 +192,6 @@ function toServerOptions(options: Options): ServerOptions {
|
||||||
resolveRequest: options.resolveRequest,
|
resolveRequest: options.resolveRequest,
|
||||||
silent: options.silent,
|
silent: options.silent,
|
||||||
sourceExts: options.sourceExts,
|
sourceExts: options.sourceExts,
|
||||||
transformCache: options.transformCache || TransformCaching.useTempDir(),
|
|
||||||
transformModulePath: options.transformModulePath,
|
transformModulePath: options.transformModulePath,
|
||||||
watch:
|
watch:
|
||||||
typeof options.watch === 'boolean'
|
typeof options.watch === 'boolean'
|
||||||
|
|
|
@ -51,7 +51,6 @@ type Options = {|
|
||||||
+projectRoots: $ReadOnlyArray<string>,
|
+projectRoots: $ReadOnlyArray<string>,
|
||||||
+providesModuleNodeModules: Array<string>,
|
+providesModuleNodeModules: Array<string>,
|
||||||
+reporter: Reporter,
|
+reporter: Reporter,
|
||||||
+resetCache: boolean,
|
|
||||||
+resolveRequest: ?CustomResolver,
|
+resolveRequest: ?CustomResolver,
|
||||||
+sourceExts: Array<string>,
|
+sourceExts: Array<string>,
|
||||||
+transformCode: TransformCode,
|
+transformCode: TransformCode,
|
||||||
|
@ -111,7 +110,6 @@ class DependencyGraph extends EventEmitter {
|
||||||
name: 'metro-' + JEST_HASTE_MAP_CACHE_BREAKER,
|
name: 'metro-' + JEST_HASTE_MAP_CACHE_BREAKER,
|
||||||
platforms: Array.from(opts.platforms),
|
platforms: Array.from(opts.platforms),
|
||||||
providesModuleNodeModules: opts.providesModuleNodeModules,
|
providesModuleNodeModules: opts.providesModuleNodeModules,
|
||||||
resetCache: opts.resetCache,
|
|
||||||
retainAllFiles: true,
|
retainAllFiles: true,
|
||||||
roots: opts.projectRoots,
|
roots: opts.projectRoots,
|
||||||
throwOnModuleCollision: true,
|
throwOnModuleCollision: true,
|
||||||
|
@ -199,7 +197,6 @@ class DependencyGraph extends EventEmitter {
|
||||||
assetDependencies: [_opts.assetRegistryPath],
|
assetDependencies: [_opts.assetRegistryPath],
|
||||||
getClosestPackage: this._getClosestPackage.bind(this),
|
getClosestPackage: this._getClosestPackage.bind(this),
|
||||||
hasteImplModulePath: _opts.hasteImplModulePath,
|
hasteImplModulePath: _opts.hasteImplModulePath,
|
||||||
resetCache: _opts.resetCache,
|
|
||||||
roots: _opts.projectRoots,
|
roots: _opts.projectRoots,
|
||||||
transformCode: _opts.transformCode,
|
transformCode: _opts.transformCode,
|
||||||
},
|
},
|
||||||
|
|
|
@ -26,7 +26,6 @@ type Options = {|
|
||||||
hasteImplModulePath?: string,
|
hasteImplModulePath?: string,
|
||||||
getClosestPackage: GetClosestPackageFn,
|
getClosestPackage: GetClosestPackageFn,
|
||||||
roots: $ReadOnlyArray<string>,
|
roots: $ReadOnlyArray<string>,
|
||||||
resetCache: boolean,
|
|
||||||
transformCode: TransformCode,
|
transformCode: TransformCode,
|
||||||
|};
|
|};
|
||||||
|
|
||||||
|
@ -153,7 +152,6 @@ class ModuleCache {
|
||||||
|
|
||||||
_getModuleOptions() {
|
_getModuleOptions() {
|
||||||
return {
|
return {
|
||||||
resetCache: this._opts.resetCache,
|
|
||||||
hasteImplModulePath: this._opts.hasteImplModulePath,
|
hasteImplModulePath: this._opts.hasteImplModulePath,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ export type Options = {|
|
||||||
getPolyfills: ({platform: ?string}) => $ReadOnlyArray<string>,
|
getPolyfills: ({platform: ?string}) => $ReadOnlyArray<string>,
|
||||||
+getRunModuleStatement: (number | string) => string,
|
+getRunModuleStatement: (number | string) => string,
|
||||||
getTransformOptions?: GetTransformOptions,
|
getTransformOptions?: GetTransformOptions,
|
||||||
globalTransformCache: ?GlobalTransformCache,
|
globalTransformCache?: ?GlobalTransformCache,
|
||||||
hasteImplModulePath?: string,
|
hasteImplModulePath?: string,
|
||||||
maxWorkers?: number,
|
maxWorkers?: number,
|
||||||
minifierPath?: string,
|
minifierPath?: string,
|
||||||
|
@ -107,7 +107,7 @@ export type Options = {|
|
||||||
+getModulesRunBeforeMainModule: (entryPoint: string) => Array<string>,
|
+getModulesRunBeforeMainModule: (entryPoint: string) => Array<string>,
|
||||||
silent?: boolean,
|
silent?: boolean,
|
||||||
+sourceExts: ?Array<string>,
|
+sourceExts: ?Array<string>,
|
||||||
+transformCache: TransformCache,
|
+transformCache?: TransformCache,
|
||||||
transformModulePath?: string,
|
transformModulePath?: string,
|
||||||
watch?: boolean,
|
watch?: boolean,
|
||||||
workerPath: ?string,
|
workerPath: ?string,
|
||||||
|
|
Loading…
Reference in New Issue