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 crypto = require('crypto');
|
||||||
const docblock = require('./DependencyGraph/docblock');
|
const docblock = require('./DependencyGraph/docblock');
|
||||||
const isAbsolutePath = require('absolute-path');
|
const isAbsolutePath = require('absolute-path');
|
||||||
|
const jsonStableStringify = require('json-stable-stringify');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const extractRequires = require('./lib/extractRequires');
|
const extractRequires = require('./lib/extractRequires');
|
||||||
|
|
||||||
|
@ -206,29 +207,15 @@ function whileInDocBlock(chunk, i, result) {
|
||||||
const knownHashes = new WeakMap();
|
const knownHashes = new WeakMap();
|
||||||
function stableObjectHash(object) {
|
function stableObjectHash(object) {
|
||||||
let digest = knownHashes.get(object);
|
let digest = knownHashes.get(object);
|
||||||
|
|
||||||
if (!digest) {
|
if (!digest) {
|
||||||
const hash = crypto.createHash('md5');
|
digest = crypto.createHash('md5')
|
||||||
stableObjectHash.addTo(object, hash);
|
.update(jsonStableStringify(object))
|
||||||
digest = hash.digest('base64');
|
.digest('base64');
|
||||||
knownHashes.set(object, digest);
|
knownHashes.set(object, digest);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 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) {
|
function cacheKey(field, transformOptions) {
|
||||||
return transformOptions !== undefined
|
return transformOptions !== undefined
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
jest
|
jest
|
||||||
.dontMock('absolute-path')
|
.dontMock('absolute-path')
|
||||||
|
.dontMock('json-stable-stringify')
|
||||||
.dontMock('../fastfs')
|
.dontMock('../fastfs')
|
||||||
.dontMock('../lib/extractRequires')
|
.dontMock('../lib/extractRequires')
|
||||||
.dontMock('../lib/replacePatterns')
|
.dontMock('../lib/replacePatterns')
|
||||||
|
|
Loading…
Reference in New Issue