Skip to content

Commit

Permalink
perf: avoid unnecessary fs.statSync calls (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister authored Jan 11, 2023
1 parent 46de0e8 commit 6531bad
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/mean-seals-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'eslint-import-resolver-typescript': patch
---

Only try to resolve a module directory when we know that the path is a directory. This can lead to a 15% speedup on projects with many files.
21 changes: 20 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,26 @@ function getMappedPath(
]),
)
.flat(2)
.filter(mappedPath => isFile(mappedPath) || isModule(mappedPath))
.filter(mappedPath => {
if (mappedPath === undefined) {
return false
}

try {
const stat = fs.statSync(mappedPath, { throwIfNoEntry: false })
if (stat === undefined) return false
if (stat.isFile()) return true

// Maybe this is a module dir?
if (stat.isDirectory()) {
return isModule(mappedPath)
}
} catch {
return false
}

return false
})
}

if (retry && paths.length === 0) {
Expand Down

0 comments on commit 6531bad

Please sign in to comment.