diff --git a/src/core/resolve.js b/src/core/resolve.js index 8c5a76c20..1dc1ce2fe 100644 --- a/src/core/resolve.js +++ b/src/core/resolve.js @@ -14,13 +14,22 @@ function fileExistsWithCaseSync(filepath) { return fileExistsWithCaseSync(dir) } +const fileExistsCache = new Map() + function fileExists(filepath) { + if (fileExistsCache.has(filepath)) { + return fileExistsCache.get(filepath) + } + + let result if (CASE_INSENSITIVE) { // short-circuit if path doesn't exist, ignoring case - return !(!fs.existsSync(filepath) || !fileExistsWithCaseSync(filepath)) + result = !(!fs.existsSync(filepath) || !fileExistsWithCaseSync(filepath)) } else { - return fs.existsSync(filepath) + result = fs.existsSync(filepath) } + fileExistsCache.set(filepath, result) + return result } export function relative(modulePath, sourceFile, settings) {