Skip to content

Commit aba5ddf

Browse files
committed
fix: only cache filename lookup, not options
Presumably to avoid excessive stat calls, the return value of `normalizeOptions()` is cached for each input tsconfig file. But the return value also depends on the input `options`: eslint configuration may pass different options for the same tsconfig file. Instead, cache only the result of the `tryFile()` call.
1 parent c4cb88d commit aba5ddf

File tree

3 files changed

+16
-21
lines changed

3 files changed

+16
-21
lines changed

.changeset/slick-breads-feel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-import-resolver-typescript": patch
3+
---
4+
5+
fix: only cache filename lookup, not options

src/normalize-options.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import type { TypeScriptResolverOptions } from './types.js'
1616

1717
export let defaultConfigFile: string
1818

19-
const configFileMapping = new Map<string, TypeScriptResolverOptions>()
19+
const configFileMapping = new Map<string, string>()
2020

2121
let warned: boolean | undefined
2222

@@ -77,17 +77,17 @@ export function normalizeOptions(
7777
}
7878

7979
if (configFile) {
80-
const cachedOptions = configFileMapping.get(configFile)
81-
if (cachedOptions) {
82-
log('using cached options for', configFile)
83-
return cachedOptions
80+
let cachedConfigFile: string | undefined = configFileMapping.get(configFile)
81+
if (cachedConfigFile) {
82+
log('using cached config file for', configFile)
83+
configFile = cachedConfigFile
84+
} else if (!ensured && configFile !== defaultConfigFile) {
85+
cachedConfigFile = tryFile(DEFAULT_TRY_PATHS, false, configFile)
86+
configFileMapping.set(configFile, cachedConfigFile)
87+
configFile = cachedConfigFile
8488
}
8589
}
8690

87-
if (!ensured && configFile && configFile !== defaultConfigFile) {
88-
configFile = tryFile(DEFAULT_TRY_PATHS, false, configFile)
89-
}
90-
9191
options = {
9292
conditionNames: defaultConditionNames,
9393
extensions: defaultExtensions,
@@ -100,9 +100,5 @@ export function normalizeOptions(
100100
: undefined,
101101
}
102102

103-
if (configFile) {
104-
configFileMapping.set(configFile, options)
105-
}
106-
107103
return options
108104
}

tests/e2e/__snapshots__/e2e.spec.ts.snap

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,9 @@ exports[`e2e cases > should exec eslint successfully > dotProject 1`] = `
3434

3535
exports[`e2e cases > should exec eslint successfully > filesWithDifferentOptions 1`] = `
3636
{
37-
"exitCode": 1,
37+
"exitCode": 0,
3838
"stderr": "",
39-
"stdout": "
40-
<ROOT>/tests/e2e/filesWithDifferentOptions/src/a.foo.js
41-
1:15 error Unable to resolve path to module './x' import-x/no-unresolved
42-
43-
1 problem (1 error, 0 warnings)
44-
45-
",
39+
"stdout": "",
4640
}
4741
`;
4842

0 commit comments

Comments
 (0)