Skip to content

Commit 799f1ce

Browse files
authored
fix: include options hash in cache key for options normalization (#466)
1 parent c06392f commit 799f1ce

File tree

9 files changed

+68
-3
lines changed

9 files changed

+68
-3
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: include options hash in cache key for options normalization

src/normalize-options.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { stableHash } from 'stable-hash-x'
12
import { globSync, isDynamicPattern } from 'tinyglobby'
23
import type { TsconfigOptions } from 'unrs-resolver'
34

@@ -76,10 +77,12 @@ export function normalizeOptions(
7677
ensured = true
7778
}
7879

80+
const optionsHash = stableHash(options)
81+
const cacheKey = `${configFile}\0${optionsHash}`
7982
if (configFile) {
80-
const cachedOptions = configFileMapping.get(configFile)
83+
const cachedOptions = configFileMapping.get(cacheKey)
8184
if (cachedOptions) {
82-
log('using cached options for', configFile)
85+
log('using cached options for', configFile, 'with options', options)
8386
return cachedOptions
8487
}
8588
}
@@ -101,7 +104,7 @@ export function normalizeOptions(
101104
}
102105

103106
if (configFile) {
104-
configFileMapping.set(configFile, options)
107+
configFileMapping.set(cacheKey, options)
105108
}
106109

107110
return options

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ exports[`e2e cases > should exec eslint successfully > dotProject 1`] = `
3232
}
3333
`;
3434

35+
exports[`e2e cases > should exec eslint successfully > filesWithDifferentOptions 1`] = `
36+
{
37+
"exitCode": 0,
38+
"stderr": "",
39+
"stdout": "",
40+
}
41+
`;
42+
3543
exports[`e2e cases > should exec eslint successfully > importXResolverV3 1`] = `
3644
{
3745
"exitCode": 0,
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { defineConfig, globalIgnores } from 'eslint/config'
2+
import { defaultExtensions } from 'eslint-import-resolver-typescript'
3+
import importX, { flatConfigs } from 'eslint-plugin-import-x'
4+
5+
export default defineConfig(
6+
globalIgnores(['eslint.config.js']),
7+
{
8+
files: ['**/*.foo.js', '**/*.bar.js'],
9+
plugins: {
10+
'import-x': importX,
11+
},
12+
settings: {
13+
...flatConfigs.typescript.settings,
14+
'import-x/resolver': {
15+
typescript: {},
16+
},
17+
},
18+
rules: {
19+
'import-x/no-unresolved': 'error',
20+
},
21+
},
22+
// .foo.js files should prefer importing other .foo.js files.
23+
{
24+
files: ['**/*.foo.js'],
25+
settings: {
26+
'import-x/resolver': {
27+
typescript: {
28+
extensions: ['.foo.js', ...defaultExtensions],
29+
},
30+
},
31+
},
32+
},
33+
// .bar.js files should prefer importing other .bar.js files.
34+
{
35+
files: ['**/*.bar.js'],
36+
settings: {
37+
'import-x/resolver': {
38+
typescript: {
39+
extensions: ['.bar.js', ...defaultExtensions],
40+
},
41+
},
42+
},
43+
},
44+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import y from './y'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import x from './x'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const x = 'x'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const y = 'y'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

0 commit comments

Comments
 (0)