mirror of https://github.com/status-im/metro.git
Clean ModuleCache.js
Reviewed By: cpojer Differential Revision: D7628729 fbshipit-source-id: 0c9d617cfdb6f1e514e2bc61fe393ef1b589bd97
This commit is contained in:
parent
fecc8d3508
commit
b88d8d1f99
|
@ -205,15 +205,9 @@ class DependencyGraph extends EventEmitter {
|
|||
return new ModuleCache(
|
||||
{
|
||||
assetDependencies: [_opts.assetRegistryPath],
|
||||
depGraphHelpers: this._helpers,
|
||||
experimentalCaches: _opts.experimentalCaches,
|
||||
getClosestPackage: this._getClosestPackage.bind(this),
|
||||
getTransformCacheKey: _opts.getTransformCacheKey,
|
||||
globalTransformCache: _opts.globalTransformCache,
|
||||
hasteImplModulePath: _opts.hasteImplModulePath,
|
||||
resetCache: _opts.resetCache,
|
||||
transformCache: _opts.transformCache,
|
||||
reporter: _opts.reporter,
|
||||
roots: _opts.projectRoots,
|
||||
transformCode: _opts.transformCode,
|
||||
},
|
||||
|
|
|
@ -17,83 +17,52 @@ const Polyfill = require('./Polyfill');
|
|||
|
||||
const toLocalPath = require('./lib/toLocalPath');
|
||||
|
||||
import type {GlobalTransformCache} from '../lib/GlobalTransformCache';
|
||||
import type {
|
||||
TransformCache,
|
||||
GetTransformCacheKey,
|
||||
} from '../lib/TransformCaching';
|
||||
import type {Reporter} from '../lib/reporting';
|
||||
import type DependencyGraphHelpers from './DependencyGraph/DependencyGraphHelpers';
|
||||
import type {TransformCode} from './Module';
|
||||
|
||||
type GetClosestPackageFn = (filePath: string) => ?string;
|
||||
|
||||
type Options = {|
|
||||
assetDependencies: Array<string>,
|
||||
depGraphHelpers: DependencyGraphHelpers,
|
||||
experimentalCaches: boolean,
|
||||
hasteImplModulePath?: string,
|
||||
getClosestPackage: GetClosestPackageFn,
|
||||
getTransformCacheKey: GetTransformCacheKey,
|
||||
globalTransformCache: ?GlobalTransformCache,
|
||||
roots: $ReadOnlyArray<string>,
|
||||
reporter: Reporter,
|
||||
resetCache: boolean,
|
||||
transformCache: TransformCache,
|
||||
transformCode: TransformCode,
|
||||
|};
|
||||
|
||||
class ModuleCache {
|
||||
_assetDependencies: Array<string>;
|
||||
_depGraphHelpers: DependencyGraphHelpers;
|
||||
_experimentalCaches: boolean;
|
||||
_getClosestPackage: GetClosestPackageFn;
|
||||
_getTransformCacheKey: GetTransformCacheKey;
|
||||
_globalTransformCache: ?GlobalTransformCache;
|
||||
_moduleCache: {[filePath: string]: Module, __proto__: null};
|
||||
_packageCache: {[filePath: string]: Package, __proto__: null};
|
||||
_packageModuleMap: WeakMap<Module, string>;
|
||||
_platforms: Set<string>;
|
||||
_transformCode: TransformCode;
|
||||
_reporter: Reporter;
|
||||
_roots: $ReadOnlyArray<string>;
|
||||
_opts: Options;
|
||||
|
||||
constructor(options: Options, platforms: Set<string>) {
|
||||
const {
|
||||
assetDependencies,
|
||||
depGraphHelpers,
|
||||
experimentalCaches,
|
||||
getClosestPackage,
|
||||
getTransformCacheKey,
|
||||
globalTransformCache,
|
||||
roots,
|
||||
reporter,
|
||||
transformCode,
|
||||
} = options;
|
||||
this._opts = options;
|
||||
this._assetDependencies = assetDependencies;
|
||||
this._experimentalCaches = experimentalCaches;
|
||||
this._getClosestPackage = getClosestPackage;
|
||||
this._getTransformCacheKey = getTransformCacheKey;
|
||||
this._globalTransformCache = globalTransformCache;
|
||||
this._depGraphHelpers = depGraphHelpers;
|
||||
this._moduleCache = Object.create(null);
|
||||
this._packageCache = Object.create(null);
|
||||
this._packageModuleMap = new WeakMap();
|
||||
this._platforms = platforms;
|
||||
this._transformCode = transformCode;
|
||||
this._reporter = reporter;
|
||||
this._roots = roots;
|
||||
}
|
||||
|
||||
getModule(filePath: string) {
|
||||
if (!this._moduleCache[filePath]) {
|
||||
this._moduleCache[filePath] = new Module({
|
||||
depGraphHelpers: this._depGraphHelpers,
|
||||
experimentalCaches: this._experimentalCaches,
|
||||
file: filePath,
|
||||
getTransformCacheKey: this._getTransformCacheKey,
|
||||
localPath: toLocalPath(this._roots, filePath),
|
||||
moduleCache: this,
|
||||
options: this._getModuleOptions(),
|
||||
|
@ -114,15 +83,10 @@ class ModuleCache {
|
|||
* simpler than a normal Module, should not inherit the Module class.
|
||||
*/
|
||||
this._moduleCache[filePath] = new AssetModule({
|
||||
depGraphHelpers: this._depGraphHelpers,
|
||||
experimentalCaches: this._experimentalCaches,
|
||||
file: filePath,
|
||||
getTransformCacheKey: this._getTransformCacheKey,
|
||||
globalTransformCache: this._globalTransformCache,
|
||||
localPath: toLocalPath(this._roots, filePath),
|
||||
moduleCache: this,
|
||||
options: this._getModuleOptions(),
|
||||
reporter: this._reporter,
|
||||
transformCode: this._transformCode,
|
||||
});
|
||||
}
|
||||
|
@ -168,10 +132,7 @@ class ModuleCache {
|
|||
createPolyfill({file}: {file: string}) {
|
||||
/* $FlowFixMe: there are missing arguments. */
|
||||
return new Polyfill({
|
||||
depGraphHelpers: this._depGraphHelpers,
|
||||
experimentalCaches: this._experimentalCaches,
|
||||
file,
|
||||
getTransformCacheKey: this._getTransformCacheKey,
|
||||
localPath: toLocalPath(this._roots, file),
|
||||
moduleCache: this,
|
||||
options: this._getModuleOptions(),
|
||||
|
@ -192,9 +153,6 @@ class ModuleCache {
|
|||
|
||||
_getModuleOptions() {
|
||||
return {
|
||||
reporter: this._opts.reporter,
|
||||
transformCache: this._opts.transformCache,
|
||||
globalTransformCache: this._opts.globalTransformCache,
|
||||
resetCache: this._opts.resetCache,
|
||||
hasteImplModulePath: this._opts.hasteImplModulePath,
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue