mirror of https://github.com/status-im/metro.git
packager: GlobalTransformCache: cache the transform options digest
Reviewed By: davidaurelio Differential Revision: D4906974 fbshipit-source-id: b6cf83ba6a072400685948329070e171f65c837d
This commit is contained in:
parent
561ca97519
commit
7253a0d532
|
@ -225,7 +225,7 @@ class URIBasedGlobalTransformCache {
|
|||
keyOf(props: FetchProps) {
|
||||
const hash = crypto.createHash('sha1');
|
||||
const {sourceCode, filePath, transformOptions} = props;
|
||||
this._optionsHasher.hashTransformWorkerOptions(hash, transformOptions);
|
||||
hash.update(this._optionsHasher.getTransformWorkerOptionsDigest(transformOptions));
|
||||
const cacheKey = props.getTransformCacheKey(sourceCode, filePath, transformOptions);
|
||||
hash.update(JSON.stringify(cacheKey));
|
||||
hash.update(crypto.createHash('sha1').update(sourceCode).digest('hex'));
|
||||
|
@ -313,9 +313,23 @@ class URIBasedGlobalTransformCache {
|
|||
|
||||
class OptionsHasher {
|
||||
_rootPath: string;
|
||||
_cache: WeakMap<TransformWorkerOptions, string>;
|
||||
|
||||
constructor(rootPath: string) {
|
||||
this._rootPath = rootPath;
|
||||
this._cache = new WeakMap();
|
||||
}
|
||||
|
||||
getTransformWorkerOptionsDigest(options: TransformWorkerOptions): string {
|
||||
const digest = this._cache.get(options);
|
||||
if (digest != null) {
|
||||
return digest;
|
||||
}
|
||||
const hash = crypto.createHash('sha1');
|
||||
this.hashTransformWorkerOptions(hash, options);
|
||||
const newDigest = hash.digest('hex');
|
||||
this._cache.set(options, newDigest);
|
||||
return newDigest;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,12 +19,12 @@ Object {
|
|||
exports[`GlobalTransformCache fetches results 1`] = `
|
||||
Array [
|
||||
Object {
|
||||
"code": "/* code from http://globalcache.com/fb94b11256237327e4eef5daa08bad33573b3781-foo.js */",
|
||||
"code": "/* code from http://globalcache.com/43e279be6916de8be463ef98bd72ded391608371-foo.js */",
|
||||
"dependencies": Array [],
|
||||
"dependencyOffsets": Array [],
|
||||
},
|
||||
Object {
|
||||
"code": "/* code from http://globalcache.com/b902b4a8841fcea2919c2fe9b21e68d96dff59c9-bar.js */",
|
||||
"code": "/* code from http://globalcache.com/e09598ad4c807cb22b32d68cfc16e0cba7fdb85c-bar.js */",
|
||||
"dependencies": Array [],
|
||||
"dependencyOffsets": Array [],
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue