mirror of https://github.com/status-im/metro.git
Replace custom rolled stable string hashing with library
Reviewed By: cpojer Differential Revision: D2937202 fb-gh-sync-id: dc08547c71da2bc35cfad108e63fd5e87f0ba734 shipit-source-id: dc08547c71da2bc35cfad108e63fd5e87f0ba734
This commit is contained in:
parent
012caf0e22
commit
5357bd7d99
|
@ -11,6 +11,7 @@
|
|||
const crypto = require('crypto');
|
||||
const docblock = require('./DependencyGraph/docblock');
|
||||
const isAbsolutePath = require('absolute-path');
|
||||
const jsonStableStringify = require('json-stable-stringify');
|
||||
const path = require('path');
|
||||
const extractRequires = require('./lib/extractRequires');
|
||||
|
||||
|
@ -206,29 +207,15 @@ function whileInDocBlock(chunk, i, result) {
|
|||
const knownHashes = new WeakMap();
|
||||
function stableObjectHash(object) {
|
||||
let digest = knownHashes.get(object);
|
||||
|
||||
if (!digest) {
|
||||
const hash = crypto.createHash('md5');
|
||||
stableObjectHash.addTo(object, hash);
|
||||
digest = hash.digest('base64');
|
||||
digest = crypto.createHash('md5')
|
||||
.update(jsonStableStringify(object))
|
||||
.digest('base64');
|
||||
knownHashes.set(object, digest);
|
||||
}
|
||||
|
||||
return digest;
|
||||
}
|
||||
stableObjectHash.addTo = function addTo(value, hash) {
|
||||
if (value === null || typeof value !== 'object') {
|
||||
hash.update(JSON.stringify(value));
|
||||
} else {
|
||||
Object.keys(value).sort().forEach(key => {
|
||||
const valueForKey = value[key];
|
||||
if (valueForKey !== undefined) {
|
||||
hash.update(key);
|
||||
addTo(valueForKey, hash);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function cacheKey(field, transformOptions) {
|
||||
return transformOptions !== undefined
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
jest
|
||||
.dontMock('absolute-path')
|
||||
.dontMock('json-stable-stringify')
|
||||
.dontMock('../fastfs')
|
||||
.dontMock('../lib/extractRequires')
|
||||
.dontMock('../lib/replacePatterns')
|
||||
|
|
Loading…
Reference in New Issue