diff --git a/.changeset/mean-seals-tease.md b/.changeset/mean-seals-tease.md new file mode 100644 index 00000000..173c1c2f --- /dev/null +++ b/.changeset/mean-seals-tease.md @@ -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. diff --git a/src/index.ts b/src/index.ts index b7656f96..54d17cc9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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) {