Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: try browsers field and alias before resolving directory in node_modules #349

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,11 @@
Ok(None)
}

fn load_alias_or_file(&self, cached_path: &CachedPath, ctx: &mut Ctx) -> ResolveResult {
fn load_browser_field_or_alias(
&self,
cached_path: &CachedPath,
ctx: &mut Ctx,
) -> ResolveResult {
if !self.options.alias_fields.is_empty() {
if let Some((package_url, package_json)) =
cached_path.find_package_json(&self.options, &self.cache, ctx)?
Expand All @@ -679,6 +683,13 @@
return Ok(Some(path));
}
}
Ok(None)
}

fn load_alias_or_file(&self, cached_path: &CachedPath, ctx: &mut Ctx) -> ResolveResult {
if let Some(path) = self.load_browser_field_or_alias(cached_path, ctx)? {
return Ok(Some(path));
}
if cached_path.is_file(&self.cache.fs, ctx) {
return Ok(Some(cached_path.clone()));
}
Expand Down Expand Up @@ -750,19 +761,25 @@
let cached_path = cached_path.normalize_with(specifier, &self.cache);

// Perf: try the directory first for package specifiers.
if cached_path.is_dir(&self.cache.fs, ctx) {
if let Some(path) = self.load_as_directory(&cached_path, ctx)? {
return Ok(Some(path));
}
}
if self.options.resolve_to_context {
return Ok(cached_path
.is_dir(&self.cache.fs, ctx)
.then(|| cached_path.clone()));
}
if cached_path.is_dir(&self.cache.fs, ctx) {
if let Some(path) = self.load_browser_field_or_alias(&cached_path, ctx)? {
return Ok(Some(path));

Check warning on line 771 in src/lib.rs

View check run for this annotation

Codecov / codecov/patch

src/lib.rs#L771

Added line #L771 was not covered by tests
}
if let Some(path) = self.load_as_directory(&cached_path, ctx)? {
return Ok(Some(path));
}
}
if let Some(path) = self.load_as_file(&cached_path, ctx)? {
return Ok(Some(path));
}
if let Some(path) = self.load_as_directory(&cached_path, ctx)? {
return Ok(Some(path));

Check warning on line 781 in src/lib.rs

View check run for this annotation

Codecov / codecov/patch

src/lib.rs#L781

Added line #L781 was not covered by tests
}
}
}
Ok(None)
Expand Down
Loading