Skip to content

Commit 773daf2

Browse files
authored
perf: skip searching for package.json when alias_fields is not provided (#194)
perf: omit searching for package.json when `alias_fields` is not provided
1 parent e18bd5e commit 773daf2

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/lib.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -647,11 +647,15 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
647647
}
648648

649649
fn load_alias_or_file(&self, cached_path: &CachedPath, ctx: &mut Ctx) -> ResolveResult {
650-
if let Some(package_json) =
651-
cached_path.find_package_json(&self.cache.fs, &self.options, ctx)?
652-
{
653-
if let Some(path) = self.load_browser_field(cached_path, None, &package_json, ctx)? {
654-
return Ok(Some(path));
650+
if !self.options.alias_fields.is_empty() {
651+
if let Some(package_json) =
652+
cached_path.find_package_json(&self.cache.fs, &self.options, ctx)?
653+
{
654+
if let Some(path) =
655+
self.load_browser_field(cached_path, None, &package_json, ctx)?
656+
{
657+
return Ok(Some(path));
658+
}
655659
}
656660
}
657661
// enhanced-resolve: try file as alias

src/tests/incorrect_description_file.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ fn incorrect_description_file_1() {
1717
column: 0,
1818
});
1919
assert_eq!(resolution, Err(error));
20-
assert_eq!(ctx.file_dependencies, FxHashSet::from_iter([f.join("pack1/package.json")]));
21-
assert!(ctx.missing_dependencies.is_empty());
20+
assert_eq!(
21+
ctx.file_dependencies,
22+
FxHashSet::from_iter([f.join("pack1"), f.join("pack1/package.json")])
23+
);
24+
assert!(!ctx.missing_dependencies.is_empty());
2225
}
2326

2427
// should not resolve main in incorrect description file #2

0 commit comments

Comments
 (0)