packager: GlobalTransformCache: remove global variable

Reviewed By: davidaurelio

Differential Revision: D4449333

fbshipit-source-id: b9546b90d2fd5ddca9c1ee2719c6c454b60bdfa4
This commit is contained in:
Jean Lauliac authored and Facebook Github Bot committed 2017-01-24 03:43:36 -08:00
1 parent ac1aba4b94
commit ccf94aa65a
9 files changed
+59 -55

No files matched your search

+13 -10
View File
@@ -16,13 +16,11 @@ const Module = require('./Module');
const Package = require('./Package');
const Polyfill = require('./Polyfill');
import type GlobalTransformCache from '../lib/GlobalTransformCache';
import type {Reporter} from '../lib/reporting';
import type Cache from './Cache';
import type DependencyGraphHelpers from './DependencyGraph/DependencyGraphHelpers';
import type {
TransformCode,
Options as ModuleOptions,
} from './Module';
import type {TransformCode, Options as ModuleOptions} from './Module';
type GetClosestPackageFn = (filePath: string) => ?string;
@@ -32,6 +30,7 @@ class ModuleCache {
_cache: Cache;
_depGraphHelpers: DependencyGraphHelpers;
_getClosestPackage: GetClosestPackageFn;
_globalTransformCache: ?GlobalTransformCache;
_moduleCache: {[filePath: string]: Module};
_moduleOptions: ModuleOptions;
_packageCache: {[filePath: string]: Package};
@@ -47,22 +46,25 @@ class ModuleCache {
depGraphHelpers,
extractRequires,
getClosestPackage,
globalTransformCache,
moduleOptions,
reporter,
transformCacheKey,
transformCode,
reporter,
}: {
assetDependencies: Array<string>,
cache: Cache,
depGraphHelpers: DependencyGraphHelpers,
getClosestPackage: GetClosestPackageFn,
globalTransformCache: ?GlobalTransformCache,
moduleOptions: ModuleOptions,
reporter: Reporter,
transformCacheKey: string,
transformCode: TransformCode,
reporter: Reporter,
}, platforms: Set<string>) {
this._assetDependencies = assetDependencies;
this._getClosestPackage = getClosestPackage;
this._globalTransformCache = globalTransformCache;
this._cache = cache;
this._depGraphHelpers = depGraphHelpers;
this._moduleCache = Object.create(null);
@@ -78,14 +80,15 @@ class ModuleCache {
getModule(filePath: string) {
if (!this._moduleCache[filePath]) {
this._moduleCache[filePath] = new Module({
file: filePath,
moduleCache: this,
cache: this._cache,
transformCode: this._transformCode,
transformCacheKey: this._transformCacheKey,
depGraphHelpers: this._depGraphHelpers,
file: filePath,
globalTransformCache: this._globalTransformCache,
moduleCache: this,
options: this._moduleOptions,
reporter: this._reporter,
transformCacheKey: this._transformCacheKey,
transformCode: this._transformCode,
});
}
return this._moduleCache[filePath];