@@ -95,9 +95,9 @@ export const resolve = (
9595
9696 // eslint-disable-next-line sonarjs/label-position, sonarjs/no-labels
9797 createResolver: if ( ! resolver ) {
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 ) ) {
98+ // must be an array with 2+ items here already ensured by `normalizeOptions`
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
@@ -135,11 +135,27 @@ export const resolve = (
135135 } ,
136136 }
137137 resolver = new ResolverFactory ( options )
138- resolverCache . set ( tsconfigPath , resolver )
139- break createResolver
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