Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/slick-breads-feel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-import-resolver-typescript": patch
---

fix: include options hash in cache key for options normalization
13 changes: 10 additions & 3 deletions src/normalize-options.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { stableHash } from 'stable-hash-x'
import { globSync, isDynamicPattern } from 'tinyglobby'
import type { TsconfigOptions } from 'unrs-resolver'

Expand Down Expand Up @@ -76,10 +77,16 @@ export function normalizeOptions(
ensured = true
}

const optionsHash = stableHash(options)
if (configFile) {
const cachedOptions = configFileMapping.get(configFile)
const cachedOptions = configFileMapping.get(`${configFile}\0${optionsHash}`)
if (cachedOptions) {
log('using cached options for', configFile)
log(
'using cached options for',
configFile,
'with options hash',
optionsHash,
)
return cachedOptions
}
}
Expand All @@ -101,7 +108,7 @@ export function normalizeOptions(
}

if (configFile) {
configFileMapping.set(configFile, options)
configFileMapping.set(`${configFile}\0${optionsHash}`, options)
}

return options
Expand Down
8 changes: 8 additions & 0 deletions tests/e2e/__snapshots__/e2e.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ exports[`e2e cases > should exec eslint successfully > dotProject 1`] = `
}
`;

exports[`e2e cases > should exec eslint successfully > filesWithDifferentOptions 1`] = `
{
"exitCode": 0,
"stderr": "",
"stdout": "",
}
`;

exports[`e2e cases > should exec eslint successfully > importXResolverV3 1`] = `
{
"exitCode": 0,
Expand Down
44 changes: 44 additions & 0 deletions tests/e2e/filesWithDifferentOptions/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { defineConfig, globalIgnores } from 'eslint/config'
import { defaultExtensions } from 'eslint-import-resolver-typescript'
import importX, { flatConfigs } from 'eslint-plugin-import-x'

export default defineConfig(
globalIgnores(['eslint.config.js']),
{
files: ['**/*.foo.js', '**/*.bar.js'],
plugins: {
'import-x': importX,
},
settings: {
...flatConfigs.typescript.settings,
'import-x/resolver': {
typescript: {},
},
},
rules: {
'import-x/no-unresolved': 'error',
},
},
// .foo.js files should prefer importing other .foo.js files.
{
files: ['**/*.foo.js'],
settings: {
'import-x/resolver': {
typescript: {
extensions: ['.foo.js', ...defaultExtensions],
},
},
},
},
// .bar.js files should prefer importing other .bar.js files.
{
files: ['**/*.bar.js'],
settings: {
'import-x/resolver': {
typescript: {
extensions: ['.bar.js', ...defaultExtensions],
},
},
},
},
)
1 change: 1 addition & 0 deletions tests/e2e/filesWithDifferentOptions/src/a.bar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import y from './y'
1 change: 1 addition & 0 deletions tests/e2e/filesWithDifferentOptions/src/a.foo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import x from './x'
1 change: 1 addition & 0 deletions tests/e2e/filesWithDifferentOptions/src/x.foo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const x = 'x'
1 change: 1 addition & 0 deletions tests/e2e/filesWithDifferentOptions/src/y.bar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const y = 'y'
1 change: 1 addition & 0 deletions tests/e2e/filesWithDifferentOptions/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}