Skip to content

Commit 2bec63e

Browse files
committed
fix: try all projects one by one when normal matching fails due to files, include, exclude
1 parent 3824683 commit 2bec63e

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# eslint-import-resolver-typescript
22

33
[![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)
4+
[![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)
45
[![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)
56
[![npm](https://img.shields.io/npm/v/eslint-import-resolver-typescript.svg)](https://www.npmjs.com/package/eslint-import-resolver-typescript)
67
[![GitHub Release](https://img.shields.io/github/release/import-js/eslint-import-resolver-typescript)](https://github.com/import-js/eslint-import-resolver-typescript/releases)

src/index.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from 'get-tsconfig'
1111
import { isBunBuiltin } from 'is-bun-module'
1212
import { stableHash } from 'stable-hash'
13-
import { ResolverFactory } from 'unrs-resolver'
13+
import { ResolverFactory, type NapiResolveOptions } from 'unrs-resolver'
1414

1515
import {
1616
IMPORT_RESOLVER_NAME,
@@ -96,8 +96,8 @@ export const resolve = (
9696
// eslint-disable-next-line sonarjs/label-position, sonarjs/no-labels
9797
createResolver: if (!resolver) {
9898
// must be a array with 2+ items here already ensured by `normalizeOptions`
99-
const project = options.project as string[]
100-
for (const tsconfigPath of sortProjectsByAffinity(project, file)) {
99+
const projects = sortProjectsByAffinity(options.project as string[], file)
100+
for (const tsconfigPath of projects) {
101101
const resolverCached = resolverCache.get(tsconfigPath)
102102
if (resolverCached) {
103103
resolver = resolverCached
@@ -126,20 +126,36 @@ export const resolve = (
126126
continue
127127
}
128128
log('matched tsconfig at:', tsconfigPath, 'for', file)
129-
options = {
129+
const resolverOptions: NapiResolveOptions = {
130130
...options,
131131
tsconfig: {
132132
references: 'auto',
133133
...options.tsconfig,
134134
configFile: tsconfigPath,
135135
},
136136
}
137-
resolver = new ResolverFactory(options)
138-
resolverCache.set(tsconfigPath, resolver)
139-
break createResolver
137+
resolver = new ResolverFactory(resolverOptions)
138+
const resolved = resolve(source, file, options, resolver)
139+
if (resolved.found) {
140+
resolverCache.set(tsconfigPath, resolver)
141+
return resolved
142+
}
140143
}
141144

142-
log('no tsconfig matched', file, 'with', ...project)
145+
log(
146+
'no tsconfig matched',
147+
file,
148+
'with',
149+
...projects,
150+
', trying from the the nearest one instead',
151+
)
152+
153+
for (const project of projects) {
154+
const resolved = resolve(source, file, { ...options, project }, resolver)
155+
if (resolved.found) {
156+
return resolved
157+
}
158+
}
143159
}
144160

145161
if (!resolver) {

0 commit comments

Comments
 (0)