Skip to content

Commit

Permalink
Cache resolve-rc results
Browse files Browse the repository at this point in the history
  • Loading branch information
akx committed Feb 12, 2017
1 parent 4bac112 commit 9b63ffb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/fs-cache.js
Expand Up @@ -15,6 +15,8 @@ const os = require("os");
const path = require("path");
const zlib = require("zlib");

let defaultCacheDirectory = null; // Lazily instantiated when needed

/**
* Read the contents from the compressed file.
*
Expand Down Expand Up @@ -162,8 +164,6 @@ const handleCache = function(directory, params, callback) {
* });
*/

var defaultCacheDirectory = null; // Lazily instantiated when needed

module.exports = function(params, callback) {
let directory;

Expand Down
9 changes: 7 additions & 2 deletions src/resolve-rc.js
Expand Up @@ -10,6 +10,8 @@ const path = require("path");
const exists = require("./utils/exists")({});
const read = require("./utils/read")({});

const cache = {};

const find = function find(start, rel) {
const file = path.join(start, rel);

Expand All @@ -27,6 +29,9 @@ const find = function find(start, rel) {

module.exports = function(loc, rel) {
rel = rel || ".babelrc";

return find(loc, rel);
const cacheKey = `${loc}/${rel}`;
if (!(cacheKey in cache)) {
cache[cacheKey] = find(loc, rel);
}
return cache[cacheKey];
};

0 comments on commit 9b63ffb

Please sign in to comment.