Skip to content

Commit

Permalink
Fix getHashOfOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
sosukesuzuki committed May 9, 2022
1 parent 558728a commit 70a2972
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/cli/format-results-cache.js
Expand Up @@ -9,18 +9,22 @@ const stringify = require("fast-json-stable-stringify");
const { version: prettierVersion } = require("../index.js");
const { createHash } = require("./utils.js");

const configHashCache = new WeakMap();
const optionsHashCache = new WeakMap();
const nodeVersion = process && process.version;

/**
* @param {*} options
* @returns {string}
*/
function getHashOfOptions(options) {
if (configHashCache.has(options)) {
return configHashCache.get(options);
if (optionsHashCache.has(options)) {
return optionsHashCache.get(options);
}
return createHash(`${prettierVersion}_${nodeVersion}_${stringify(options)}`);
const hash = createHash(
`${prettierVersion}_${nodeVersion}_${stringify(options)}`
);
optionsHashCache.set(options, hash);
return hash;
}

/**
Expand Down

0 comments on commit 70a2972

Please sign in to comment.