@@ -49,6 +49,7 @@ export function fileExistsWithCaseSync(
49
49
filepath : string | null ,
50
50
cacheSettings : NormalizedCacheSettings ,
51
51
strict ?: boolean ,
52
+ leaf : boolean = true ,
52
53
) : boolean {
53
54
// don't care if the FS is case-sensitive
54
55
if ( CASE_SENSITIVE_FS ) {
@@ -76,8 +77,12 @@ export function fileExistsWithCaseSync(
76
77
} else {
77
78
const filenames = fs . readdirSync ( dir )
78
79
result = filenames . includes ( parsedPath . base )
79
- ? fileExistsWithCaseSync ( dir , cacheSettings , strict )
80
- : false
80
+ ? fileExistsWithCaseSync ( dir , cacheSettings , strict , false )
81
+ : ! leaf &&
82
+ // We tolerate case-insensitive matches if there are no case-insensitive matches.
83
+ // It'll fail anyway on the leaf node if the file truly doesn't exist (if it doesn't
84
+ // fail it's that we're probably working with a virtual in-memory filesystem).
85
+ ! filenames . some ( p => p . toLowerCase ( ) === parsedPath . base . toLowerCase ( ) )
81
86
}
82
87
fileExistsCache . set ( filepath , result )
83
88
return result
@@ -298,52 +303,61 @@ function fullResolve(
298
303
node : settings [ 'import-x/resolve' ] ,
299
304
} // backward compatibility
300
305
301
- for ( const { enable, name, options, resolver } of normalizeConfigResolvers (
302
- configResolvers ,
303
- sourceFile ,
304
- ) ) {
305
- if ( ! enable ) {
306
- continue
307
- }
306
+ const sourceFiles =
307
+ context . physicalFilename === sourceFile
308
+ ? [ sourceFile ]
309
+ : [ context . physicalFilename , sourceFile ]
308
310
309
- // if the resolver is `eslint-import-resolver-node`, we use the new `node` resolver first
310
- // and try `eslint-import-resolver-node` as fallback instead
311
- if ( LEGACY_NODE_RESOLVERS . has ( name ) ) {
312
- const resolverOptions = ( options || { } ) as NodeResolverOptions
313
- const resolved = legacyNodeResolve (
314
- resolverOptions ,
315
- // TODO: enable the following in the next major
316
- // {
317
- // ...resolverOptions,
318
- // extensions:
319
- // resolverOptions.extensions || settings['import-x/extensions'],
320
- // },
321
- context ,
322
- modulePath ,
323
- sourceFile ,
324
- )
311
+ for ( const sourceFile of sourceFiles ) {
312
+ for ( const {
313
+ enable,
314
+ name,
315
+ options,
316
+ resolver,
317
+ } of normalizeConfigResolvers ( configResolvers , sourceFile ) ) {
318
+ if ( ! enable ) {
319
+ continue
320
+ }
325
321
326
- if ( resolved ?. found ) {
327
- fileExistsCache . set ( cacheKey , resolved . path )
328
- return resolved
322
+ // if the resolver is `eslint-import-resolver-node`, we use the new `node` resolver first
323
+ // and try `eslint-import-resolver-node` as fallback instead
324
+ if ( LEGACY_NODE_RESOLVERS . has ( name ) ) {
325
+ const resolverOptions = ( options || { } ) as NodeResolverOptions
326
+ const resolved = legacyNodeResolve (
327
+ resolverOptions ,
328
+ // TODO: enable the following in the next major
329
+ // {
330
+ // ...resolverOptions,
331
+ // extensions:
332
+ // resolverOptions.extensions || settings['import-x/extensions'],
333
+ // },
334
+ context ,
335
+ modulePath ,
336
+ sourceFile ,
337
+ )
338
+
339
+ if ( resolved ?. found ) {
340
+ fileExistsCache . set ( cacheKey , resolved . path )
341
+ return resolved
342
+ }
343
+
344
+ if ( ! resolver ) {
345
+ continue
346
+ }
329
347
}
330
348
331
- if ( ! resolver ) {
349
+ const resolved = setRuleContext ( context , ( ) =>
350
+ resolveWithLegacyResolver ( resolver , options , modulePath , sourceFile ) ,
351
+ )
352
+
353
+ if ( ! resolved ?. found ) {
332
354
continue
333
355
}
334
- }
335
356
336
- const resolved = setRuleContext ( context , ( ) =>
337
- resolveWithLegacyResolver ( resolver , options , modulePath , sourceFile ) ,
338
- )
339
-
340
- if ( ! resolved ?. found ) {
341
- continue
357
+ // else, counts
358
+ fileExistsCache . set ( cacheKey , resolved . path as string | null )
359
+ return resolved
342
360
}
343
-
344
- // else, counts
345
- fileExistsCache . set ( cacheKey , resolved . path as string | null )
346
- return resolved
347
361
}
348
362
}
349
363
0 commit comments