Skip to content

Commit

Permalink
use existent file check
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Oct 17, 2021
1 parent 313346a commit 42c5139
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions packages/jest-resolve/src/fileWalkers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export function clearFsCache(): void {
checkedPaths.clear();
checkedRealpathPaths.clear();
packageContents.clear();
packageJsonInDir.clear();
}

enum IPathType {
Expand Down Expand Up @@ -89,22 +88,9 @@ export function readPackageCached(path: Config.Path): PkgJson {
return result;
}

const packageJsonInDir = new Map<string, boolean>();
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 {
Expand All @@ -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;
Expand Down

0 comments on commit 42c5139

Please sign in to comment.