Skip to content

Commit 6531bad

Browse files
authoredJan 11, 2023
perf: avoid unnecessary fs.statSync calls (#206)
1 parent 46de0e8 commit 6531bad

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed
 

‎.changeset/mean-seals-tease.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'eslint-import-resolver-typescript': patch
3+
---
4+
5+
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.

‎src/index.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,26 @@ function getMappedPath(
287287
]),
288288
)
289289
.flat(2)
290-
.filter(mappedPath => isFile(mappedPath) || isModule(mappedPath))
290+
.filter(mappedPath => {
291+
if (mappedPath === undefined) {
292+
return false
293+
}
294+
295+
try {
296+
const stat = fs.statSync(mappedPath, { throwIfNoEntry: false })
297+
if (stat === undefined) return false
298+
if (stat.isFile()) return true
299+
300+
// Maybe this is a module dir?
301+
if (stat.isDirectory()) {
302+
return isModule(mappedPath)
303+
}
304+
} catch {
305+
return false
306+
}
307+
308+
return false
309+
})
291310
}
292311

293312
if (retry && paths.length === 0) {

0 commit comments

Comments
 (0)
Please sign in to comment.