8000 fix: include options hash in cache key for options normalization by anomiex · Pull Request #466 · import-js/eslint-import-resolver-typescript · GitHub
[go: up one dir, main page]

Skip to content

fix: include options hash in cache key for options normalization #466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 6 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,12 @@ export function normalizeOptions(
ensured = true
}

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

if (configFile) {
configFileMapping.set(configFile, options)
configFileMapping.set(cacheKey, 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 @@
{}
0