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:
David Aurelio 2016-02-15 06:57:26 -08:00 committed by facebook-github-bot-7
parent 012caf0e22
commit 5357bd7d99
2 changed files with 5 additions and 17 deletions

View File

@ -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

View File

@ -10,6 +10,7 @@
jest
.dontMock('absolute-path')
.dontMock('json-stable-stringify')
.dontMock('../fastfs')
.dontMock('../lib/extractRequires')
.dontMock('../lib/replacePatterns')