refactor(resolver): do not search for package.json inside non-existing directories (#1482)

This commit is contained in:
Boshen 2023-11-21 17:28:27 +08:00 committed by GitHub
parent c762a85fcc
commit abde1e06b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -242,17 +242,12 @@ impl CachedPathImpl {
options: &ResolveOptions,
) -> Result<Option<Arc<PackageJson>>, 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);