From abde1e06b072c7f4994bd2d030b878d4a65ece43 Mon Sep 17 00:00:00 2001 From: Boshen Date: Tue, 21 Nov 2023 17:28:27 +0800 Subject: [PATCH] refactor(resolver): do not search for package.json inside non-existing directories (#1482) --- crates/oxc_resolver/src/cache.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/crates/oxc_resolver/src/cache.rs b/crates/oxc_resolver/src/cache.rs index d02b495a0..086794507 100644 --- a/crates/oxc_resolver/src/cache.rs +++ b/crates/oxc_resolver/src/cache.rs @@ -242,17 +242,12 @@ impl CachedPathImpl { options: &ResolveOptions, ) -> Result>, ResolveError> { let mut cache_value = self; - // Go up a directory when querying a file, this avoids a file read from example.js/package.json - if cache_value.is_file(fs) { + // Go up directories when the querying path is not a directory + while !cache_value.is_dir(fs) { if let Some(cv) = &cache_value.parent { cache_value = cv.as_ref(); - } - } else { - // Go up a directory when the querying path is neither a file nor a directory - if !cache_value.is_dir(fs) { - if let Some(cv) = &cache_value.parent { - cache_value = cv.as_ref(); - } + } else { + break; } } let mut cache_value = Some(cache_value);