Skip to content

Commit 9b63ffb

Browse files
committed
Cache resolve-rc results
1 parent 4bac112 commit 9b63ffb

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/fs-cache.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const os = require("os");
1515
const path = require("path");
1616
const zlib = require("zlib");
1717

18+
let defaultCacheDirectory = null; // Lazily instantiated when needed
19+
1820
/**
1921
* Read the contents from the compressed file.
2022
*
@@ -162,8 +164,6 @@ const handleCache = function(directory, params, callback) {
162164
* });
163165
*/
164166

165-
var defaultCacheDirectory = null; // Lazily instantiated when needed
166-
167167
module.exports = function(params, callback) {
168168
let directory;
169169

src/resolve-rc.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const path = require("path");
1010
const exists = require("./utils/exists")({});
1111
const read = require("./utils/read")({});
1212

13+
const cache = {};
14+
1315
const find = function find(start, rel) {
1416
const file = path.join(start, rel);
1517

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

2830
module.exports = function(loc, rel) {
2931
rel = rel || ".babelrc";
30-
31-
return find(loc, rel);
32+
const cacheKey = `${loc}/${rel}`;
33+
if (!(cacheKey in cache)) {
34+
cache[cacheKey] = find(loc, rel);
35+
}
36+
return cache[cacheKey];
3237
};

0 commit comments

Comments
 (0)