Skip to content

Commit

Permalink
perf: omit searching for package.json when alias_fields is not prov…
Browse files Browse the repository at this point in the history
…ided
  • Loading branch information
Boshen committed Jun 27, 2024
1 parent e18bd5e commit 99fb397
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
14 changes: 9 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,11 +647,15 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
}

fn load_alias_or_file(&self, cached_path: &CachedPath, ctx: &mut Ctx) -> ResolveResult {
if let Some(package_json) =
cached_path.find_package_json(&self.cache.fs, &self.options, ctx)?
{
if let Some(path) = self.load_browser_field(cached_path, None, &package_json, ctx)? {
return Ok(Some(path));
if !self.options.alias_fields.is_empty() {
if let Some(package_json) =
cached_path.find_package_json(&self.cache.fs, &self.options, ctx)?
{
if let Some(path) =
self.load_browser_field(cached_path, None, &package_json, ctx)?
{
return Ok(Some(path));
}
}
}
// enhanced-resolve: try file as alias
Expand Down
7 changes: 5 additions & 2 deletions src/tests/incorrect_description_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ fn incorrect_description_file_1() {
column: 0,
});
assert_eq!(resolution, Err(error));
assert_eq!(ctx.file_dependencies, FxHashSet::from_iter([f.join("pack1/package.json")]));
assert!(ctx.missing_dependencies.is_empty());
assert_eq!(
ctx.file_dependencies,
FxHashSet::from_iter([f.join("pack1"), f.join("pack1/package.json")])
);
assert!(!ctx.missing_dependencies.is_empty());
}

// should not resolve main in incorrect description file #2
Expand Down

0 comments on commit 99fb397

Please sign in to comment.