From 42c513956bc2f941d0461e8a70240b906c8424c8 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sun, 17 Oct 2021 18:54:48 +0200 Subject: [PATCH] use existent file check --- packages/jest-resolve/src/fileWalkers.ts | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/packages/jest-resolve/src/fileWalkers.ts b/packages/jest-resolve/src/fileWalkers.ts index fcbcbdef2f32..5834f3fad495 100644 --- a/packages/jest-resolve/src/fileWalkers.ts +++ b/packages/jest-resolve/src/fileWalkers.ts @@ -14,7 +14,6 @@ export function clearFsCache(): void { checkedPaths.clear(); checkedRealpathPaths.clear(); packageContents.clear(); - packageJsonInDir.clear(); } enum IPathType { @@ -89,22 +88,9 @@ export function readPackageCached(path: Config.Path): PkgJson { return result; } -const packageJsonInDir = new Map(); -function directoryHasPackageJson(file: Config.Path): boolean { - let cachedValue = packageJsonInDir.get(file); - - if (cachedValue != null) { - return cachedValue; - } - - cachedValue = fs.existsSync(file); - - packageJsonInDir.set(file, cachedValue); - - return cachedValue; -} - -// adapted from https://github.com/lukeed/escalade/blob/2477005062cdbd8407afc90d3f48f4930354252b/src/sync.js to use cached `fs.stat` calls +// adapted from +// https://github.com/lukeed/escalade/blob/2477005062cdbd8407afc90d3f48f4930354252b/src/sync.js +// to use cached `fs` calls export function findClosestPackageJson( start: Config.Path, ): Config.Path | undefined { @@ -115,7 +101,7 @@ export function findClosestPackageJson( while (true) { const pkgJsonFile = resolve(dir, './package.json'); - const hasPackageJson = directoryHasPackageJson(pkgJsonFile); + const hasPackageJson = isFile(pkgJsonFile); if (hasPackageJson) { return pkgJsonFile;