From 910a71ba1a0fbae2a4cd313588d4d923f5aa7dad Mon Sep 17 00:00:00 2001 From: Miguel Jimenez Esun Date: Fri, 20 Apr 2018 07:24:14 -0700 Subject: [PATCH] Clean server.js and runServer.js Reviewed By: davidaurelio Differential Revision: D7628734 fbshipit-source-id: 3788b35b0f9b5034d9152c5c3b297313fbec231a --- packages/metro/src/Bundler.js | 6 ------ packages/metro/src/Server.js | 11 +++++------ .../integration_tests/__tests__/basic_bundle-test.js | 2 -- packages/metro/src/legacy.js | 8 -------- packages/metro/src/node-haste/DependencyGraph.js | 3 --- packages/metro/src/node-haste/ModuleCache.js | 2 -- packages/metro/src/shared/types.flow.js | 4 ++-- 7 files changed, 7 insertions(+), 29 deletions(-) diff --git a/packages/metro/src/Bundler.js b/packages/metro/src/Bundler.js index 2fa69dca..bb4dcae1 100644 --- a/packages/metro/src/Bundler.js +++ b/packages/metro/src/Bundler.js @@ -25,8 +25,6 @@ import type { Options as WorkerOptions, } from './JSTransformer/worker'; 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 Module from './node-haste/Module'; import type {BabelSourceMap} from '@babel/core'; @@ -79,7 +77,6 @@ export type Options = {| +extraNodeModules: {}, +getPolyfills: ({platform: ?string}) => $ReadOnlyArray, +getTransformOptions?: GetTransformOptions, - +globalTransformCache: ?GlobalTransformCache, +hasteImplModulePath?: string, +maxWorkers: number, +minifierPath: string, @@ -90,10 +87,8 @@ export type Options = {| +projectRoots: $ReadOnlyArray, +providesModuleNodeModules?: Array, +reporter: Reporter, - +resetCache: boolean, +resolveRequest: ?CustomResolver, +sourceExts: Array, - +transformCache: TransformCache, +transformModulePath: string, +watch: boolean, +workerPath: ?string, @@ -154,7 +149,6 @@ class Bundler { opts.providesModuleNodeModules || defaults.providesModuleNodeModules, reporter: opts.reporter, resolveRequest: opts.resolveRequest, - resetCache: opts.resetCache, sourceExts: opts.sourceExts, transformCode: this._cachedTransformCode.bind(this), watch: opts.watch, diff --git a/packages/metro/src/Server.js b/packages/metro/src/Server.js index fc9cee57..f36f83de 100644 --- a/packages/metro/src/Server.js +++ b/packages/metro/src/Server.js @@ -56,7 +56,6 @@ import type {CacheStore} from 'metro-cache'; import type {Delta, Graph} from './DeltaBundler'; import type {CustomResolver} from 'metro-resolver'; import type {MetroSourceMap} from 'metro-source-map'; -import type {TransformCache} from './lib/TransformCaching'; import type {Symbolicate} from './Server/symbolicate/symbolicate'; import type {AssetData} from './Assets'; import type { @@ -125,13 +124,11 @@ class Server { projectRoots: $ReadOnlyArray, providesModuleNodeModules?: Array, reporter: Reporter, - resetCache: boolean, resolveRequest: ?CustomResolver, +getModulesRunBeforeMainModule: (entryFilePath: string) => Array, +getRunModuleStatement: (number | string) => string, silent: boolean, +sourceExts: Array, - +transformCache: TransformCache, +transformModulePath: string, watch: boolean, workerPath: ?string, @@ -180,7 +177,6 @@ class Server { getPolyfills: options.getPolyfills, getRunModuleStatement: options.getRunModuleStatement, getTransformOptions: options.getTransformOptions, - globalTransformCache: options.globalTransformCache, hasteImplModulePath: options.hasteImplModulePath, maxWorkers, minifierPath: @@ -194,19 +190,22 @@ class Server { projectRoots: options.projectRoots, providesModuleNodeModules: options.providesModuleNodeModules, reporter, - resetCache: options.resetCache || false, resolveRequest: options.resolveRequest, silent: options.silent || false, sourceExts: options.assetTransforms ? sourceExts.concat(assetExts) : sourceExts, - transformCache: options.transformCache, transformModulePath: options.transformModulePath || defaults.transformModulePath, watch: options.watch || false, workerPath: options.workerPath, }; + if (options.resetCache) { + options.cacheStores.forEach(store => store.clear()); + reporter.update({type: 'transform_cache_reset'}); + } + const processFileChange = ({type, filePath}) => this.onFileChange(type, filePath); diff --git a/packages/metro/src/integration_tests/__tests__/basic_bundle-test.js b/packages/metro/src/integration_tests/__tests__/basic_bundle-test.js index 8ffbffa0..5e1031e2 100644 --- a/packages/metro/src/integration_tests/__tests__/basic_bundle-test.js +++ b/packages/metro/src/integration_tests/__tests__/basic_bundle-test.js @@ -101,7 +101,6 @@ describe('basic_bundle', () => { getPolyfills: () => [polyfill1, polyfill2], getRunModuleStatement, projectRoots: [INPUT_PATH, POLYFILLS_PATH], - transformCache: Metro.TransformCaching.none(), transformModulePath: require.resolve('../../transformer'), nonPersistent: true, enableBabelRCLookup: false, // dont use metro's own babelrc! @@ -126,7 +125,6 @@ describe('basic_bundle', () => { getPolyfills: () => [], getRunModuleStatement, projectRoots: [INPUT_PATH, POLYFILLS_PATH], - transformCache: Metro.TransformCaching.none(), transformModulePath: require.resolve('../../transformer'), nonPersistent: true, enableBabelRCLookup: false, // dont use metro's own babelrc! diff --git a/packages/metro/src/legacy.js b/packages/metro/src/legacy.js index c89cb3b7..e71918fa 100644 --- a/packages/metro/src/legacy.js +++ b/packages/metro/src/legacy.js @@ -10,8 +10,6 @@ 'use strict'; -const TransformCaching = require('./lib/TransformCaching'); - const blacklist = require('./blacklist'); const debug = require('debug'); 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 Server from './Server'; -import type {TransformCache} from './lib/TransformCaching'; import type {Options as ServerOptions} from './shared/types.flow'; exports.createBlacklist = blacklist; @@ -36,7 +33,6 @@ type Options = {| ...ServerOptions, // optional types to force flow errors in `toServerOptions` nonPersistent?: ?boolean, - transformCache?: ?TransformCache, verbose?: ?boolean, targetBabelVersion?: number, |}; @@ -51,8 +47,6 @@ type PublicBundleOptions = { +sourceMapUrl?: string, }; -exports.TransformCaching = TransformCaching; - /** * 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 @@ -184,7 +178,6 @@ function toServerOptions(options: Options): ServerOptions { getPolyfills: options.getPolyfills, getRunModuleStatement: options.getRunModuleStatement, getTransformOptions: options.getTransformOptions, - globalTransformCache: options.globalTransformCache, hasteImplModulePath: options.hasteImplModulePath, maxWorkers: options.maxWorkers, minifierPath: options.minifierPath, @@ -199,7 +192,6 @@ function toServerOptions(options: Options): ServerOptions { resolveRequest: options.resolveRequest, silent: options.silent, sourceExts: options.sourceExts, - transformCache: options.transformCache || TransformCaching.useTempDir(), transformModulePath: options.transformModulePath, watch: typeof options.watch === 'boolean' diff --git a/packages/metro/src/node-haste/DependencyGraph.js b/packages/metro/src/node-haste/DependencyGraph.js index d855d1d1..e22afdd5 100644 --- a/packages/metro/src/node-haste/DependencyGraph.js +++ b/packages/metro/src/node-haste/DependencyGraph.js @@ -51,7 +51,6 @@ type Options = {| +projectRoots: $ReadOnlyArray, +providesModuleNodeModules: Array, +reporter: Reporter, - +resetCache: boolean, +resolveRequest: ?CustomResolver, +sourceExts: Array, +transformCode: TransformCode, @@ -111,7 +110,6 @@ class DependencyGraph extends EventEmitter { name: 'metro-' + JEST_HASTE_MAP_CACHE_BREAKER, platforms: Array.from(opts.platforms), providesModuleNodeModules: opts.providesModuleNodeModules, - resetCache: opts.resetCache, retainAllFiles: true, roots: opts.projectRoots, throwOnModuleCollision: true, @@ -199,7 +197,6 @@ class DependencyGraph extends EventEmitter { assetDependencies: [_opts.assetRegistryPath], getClosestPackage: this._getClosestPackage.bind(this), hasteImplModulePath: _opts.hasteImplModulePath, - resetCache: _opts.resetCache, roots: _opts.projectRoots, transformCode: _opts.transformCode, }, diff --git a/packages/metro/src/node-haste/ModuleCache.js b/packages/metro/src/node-haste/ModuleCache.js index d0bf7f12..604f190e 100644 --- a/packages/metro/src/node-haste/ModuleCache.js +++ b/packages/metro/src/node-haste/ModuleCache.js @@ -26,7 +26,6 @@ type Options = {| hasteImplModulePath?: string, getClosestPackage: GetClosestPackageFn, roots: $ReadOnlyArray, - resetCache: boolean, transformCode: TransformCode, |}; @@ -153,7 +152,6 @@ class ModuleCache { _getModuleOptions() { return { - resetCache: this._opts.resetCache, hasteImplModulePath: this._opts.hasteImplModulePath, }; } diff --git a/packages/metro/src/shared/types.flow.js b/packages/metro/src/shared/types.flow.js index 09d91112..8dc121d1 100644 --- a/packages/metro/src/shared/types.flow.js +++ b/packages/metro/src/shared/types.flow.js @@ -91,7 +91,7 @@ export type Options = {| getPolyfills: ({platform: ?string}) => $ReadOnlyArray, +getRunModuleStatement: (number | string) => string, getTransformOptions?: GetTransformOptions, - globalTransformCache: ?GlobalTransformCache, + globalTransformCache?: ?GlobalTransformCache, hasteImplModulePath?: string, maxWorkers?: number, minifierPath?: string, @@ -107,7 +107,7 @@ export type Options = {| +getModulesRunBeforeMainModule: (entryPoint: string) => Array, silent?: boolean, +sourceExts: ?Array, - +transformCache: TransformCache, + +transformCache?: TransformCache, transformModulePath?: string, watch?: boolean, workerPath: ?string,