@@ -49,6 +49,7 @@ export function fileExistsWithCaseSync(
4949 filepath : string | null ,
5050 cacheSettings : NormalizedCacheSettings ,
5151 strict ?: boolean ,
52+ leaf : boolean = true ,
5253) : boolean {
5354 // don't care if the FS is case-sensitive
5455 if ( CASE_SENSITIVE_FS ) {
@@ -76,8 +77,12 @@ export function fileExistsWithCaseSync(
7677 } else {
7778 const filenames = fs . readdirSync ( dir )
7879 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 ( ) )
8186 }
8287 fileExistsCache . set ( filepath , result )
8388 return result
@@ -298,52 +303,61 @@ function fullResolve(
298303 node : settings [ 'import-x/resolve' ] ,
299304 } // backward compatibility
300305
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 ]
308310
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+ }
325321
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+ }
329347 }
330348
331- if ( ! resolver ) {
349+ const resolved = setRuleContext ( context , ( ) =>
350+ resolveWithLegacyResolver ( resolver , options , modulePath , sourceFile ) ,
351+ )
352+
353+ if ( ! resolved ?. found ) {
332354 continue
333355 }
334- }
335356
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
342360 }
343-
344- // else, counts
345- fileExistsCache . set ( cacheKey , resolved . path as string | null )
346- return resolved
347361 }
348362 }
349363
0 commit comments