@@ -10,7 +10,7 @@ import {
10
10
} from 'get-tsconfig'
11
11
import { isBunBuiltin } from 'is-bun-module'
12
12
import { stableHash } from 'stable-hash'
13
- import { ResolverFactory } from 'unrs-resolver'
13
+ import { ResolverFactory , type NapiResolveOptions } from 'unrs-resolver'
14
14
15
15
import {
16
16
IMPORT_RESOLVER_NAME ,
@@ -96,8 +96,8 @@ export const resolve = (
96
96
// eslint-disable-next-line sonarjs/label-position, sonarjs/no-labels
97
97
createResolver: if ( ! resolver ) {
98
98
// 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 ) {
101
101
const resolverCached = resolverCache . get ( tsconfigPath )
102
102
if ( resolverCached ) {
103
103
resolver = resolverCached
@@ -126,20 +126,36 @@ export const resolve = (
126
126
continue
127
127
}
128
128
log ( 'matched tsconfig at:' , tsconfigPath , 'for' , file )
129
- options = {
129
+ const resolverOptions : NapiResolveOptions = {
130
130
...options ,
131
131
tsconfig : {
132
132
references : 'auto' ,
133
133
...options . tsconfig ,
134
134
configFile : tsconfigPath ,
135
135
} ,
136
136
}
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
+ }
140
143
}
141
144
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
+ }
143
159
}
144
160
145
161
if ( ! resolver ) {
0 commit comments