Skip to content
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/ready-mirrors-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-import-resolver-typescript": patch
---

fix: always sort projects by affinity before iterating
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# eslint-import-resolver-typescript

[![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/import-js/eslint-import-resolver-typescript/ci.yml?branch=master)](https://github.com/import-js/eslint-import-resolver-typescript/actions/workflows/ci.yml?query=branch%3Amaster)
[![Codecov](https://img.shields.io/codecov/c/github/import-js/eslint-import-resolver-typescript.svg)](https://codecov.io/gh/import-js/eslint-import-resolver-typescript)
[![type-coverage](https://img.shields.io/badge/dynamic/json.svg?label=type-coverage&prefix=%E2%89%A5&suffix=%&query=$.typeCoverage.atLeast&uri=https%3A%2F%2Fraw.githubusercontent.com%2Fimport-js%2Feslint-import-resolver-typescript%2Fmaster%2Fpackage.json)](https://github.com/plantain-00/type-coverage)
[![npm](https://img.shields.io/npm/v/eslint-import-resolver-typescript.svg)](https://www.npmjs.com/package/eslint-import-resolver-typescript)
[![GitHub Release](https://img.shields.io/github/release/import-js/eslint-import-resolver-typescript)](https://github.com/import-js/eslint-import-resolver-typescript/releases)
Expand Down
27 changes: 13 additions & 14 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ export const resolve = (

// eslint-disable-next-line sonarjs/label-position, sonarjs/no-labels
createResolver: if (!resolver) {
// must be a array with 2+ items here already ensured by `normalizeOptions`
const project = options.project as string[]
for (const tsconfigPath of project) {
// must be an array with 2+ items here already ensured by `normalizeOptions`
const projects = sortProjectsByAffinity(options.project as string[], file)
for (const tsconfigPath of projects) {
const resolverCached = resolverCache.get(tsconfigPath)
if (resolverCached) {
resolver = resolverCached
Expand Down Expand Up @@ -135,24 +135,23 @@ export const resolve = (
},
}
resolver = new ResolverFactory(options)
resolverCache.set(tsconfigPath, resolver)
break createResolver
const resolved = resolve(source, file, options, resolver)
if (resolved.found) {
resolverCache.set(tsconfigPath, resolver)
return resolved
}
}

log(
'no tsconfig matched',
file,
'with',
...project,
', trying from the the nearest one',
...projects,
', trying from the the nearest one instead',
)
for (const p of sortProjectsByAffinity(project, file)) {
const resolved = resolve(
source,
file,
{ ...options, project: p },
resolver,
)

for (const project of projects) {
const resolved = resolve(source, file, { ...options, project }, resolver)
if (resolved.found) {
return resolved
}
Expand Down