Repository navigation
resolver: do not look up a "browser" map target again after resolution #46985
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
Changes from 1 commit
8690a13
628ec8d
37cf001
2ed92a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2277,6 +2277,7 @@ impl<'a> Resolver<'a> { | |
| } | ||
| }; | ||
|
|
||
| let mut remapped_to_relative_path = false; | ||
| if self.care_about_browser_field { | ||
| // Support remapping one package path to another via the "browser" field | ||
| if let Some(browser_scope) = source_dir_info.get_enclosing_browser_scope() { | ||
|
|
@@ -2333,6 +2334,7 @@ impl<'a> Resolver<'a> { | |
|
|
||
| import_path = remapped; | ||
| source_dir_info = browser_scope; | ||
| remapped_to_relative_path = !is_package_path(remapped); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -2375,7 +2377,12 @@ impl<'a> Resolver<'a> { | |
| return ResultUnion::Success(result); | ||
| } | ||
|
|
||
| if res.package_json.is_some() && self.care_about_browser_field { | ||
| // A path that a "browser" map lookup picked is final. | ||
| if res.package_json.is_some() | ||
| && self.care_about_browser_field | ||
| && !res.browser_remapped | ||
| && !remapped_to_relative_path | ||
|
robobun marked this conversation as resolved.
Resolved
|
||
| { | ||
|
robobun marked this conversation as resolved.
Resolved
|
||
| let base_dir_info = match res.dir_info { | ||
| Some(d) => d, | ||
| None => match self.read_dir_info(result.path_pair.primary.name().dir) { | ||
|
|
@@ -5265,6 +5272,7 @@ impl<'a> Resolver<'a> { | |
| dec_ret!(MatchStatus::NotFound); | ||
| }; | ||
|
|
||
| let mut browser_remapped = false; | ||
| if self.care_about_browser_field { | ||
| // Potentially remap using the "browser" field | ||
| if let Some(browser_scope) = dir_info.get_enclosing_browser_scope() { | ||
|
|
@@ -5300,32 +5308,22 @@ impl<'a> Resolver<'a> { | |
| Some(remapped) => remapped, | ||
| None => dec_ret!(MatchStatus::NotFound), | ||
| }; | ||
| browser_remapped = true; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Is this a file? | ||
| if let Some(result) = self.load_as_file(field_abs_path, extension_order) { | ||
| if let Some(package_json) = dir_info.package_json() { | ||
| *out = MatchResult { | ||
| path_pair: PathPair { | ||
| primary: Fs::Path::init(result.path), | ||
| secondary: None, | ||
| }, | ||
| package_json: Some(std::ptr::from_ref(package_json)), | ||
| dirname_fd: result.dirname_fd, | ||
| ..Default::default() | ||
| }; | ||
| dec_ret!(MatchStatus::Success); | ||
| } | ||
|
|
||
| *out = MatchResult { | ||
| path_pair: PathPair { | ||
| primary: Fs::Path::init(result.path), | ||
| secondary: None, | ||
| }, | ||
| package_json: dir_info.package_json().map(std::ptr::from_ref), | ||
| dirname_fd: result.dirname_fd, | ||
| browser_remapped, | ||
| ..Default::default() | ||
| }; | ||
| dec_ret!(MatchStatus::Success); | ||
|
|
@@ -5342,6 +5340,9 @@ impl<'a> Resolver<'a> { | |
| extension_order, | ||
| out, | ||
| ); | ||
| if browser_remapped && r.is_success() { | ||
| out.browser_remapped = true; | ||
| } | ||
| if let Some(d) = self.debug_logs.as_mut() { | ||
| d.decrease_indent(); | ||
| } | ||
|
|
@@ -5577,6 +5578,7 @@ impl<'a> Resolver<'a> { | |
| primary: Path::init(file_result.path), | ||
| secondary: None, | ||
| }, | ||
| browser_remapped: true, | ||
|
Comment on lines
5582
to
+5585
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 (optional) Browser builds that import a package subdirectory with a nested Why this was flaggedTrigger: pkg/package.json browser map {"./dir/index.js":"./a.js","./a.js":"./b.js"}, pkg/dir/package.json with "sideEffects": false, entry does Verification: The result is written with
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the second Downsides bullet of the description. The file that the map picks is right ( An earlier version of this branch attached the package.json of the map's owner to a picked file outside the imported directory. It dropped a file that main keeps when the map sends the entry into another package and the owner says |
||
| ..Default::default() | ||
| }; | ||
| return MatchStatus::Success; | ||
|
|
@@ -5588,6 +5590,7 @@ impl<'a> Resolver<'a> { | |
| .load_as_index(new_dir, extension_order, out) | ||
| .is_success() | ||
| { | ||
| out.browser_remapped = true; | ||
| return MatchStatus::Success; | ||
| } | ||
| } | ||
|
|
@@ -5820,6 +5823,7 @@ impl<'a> Resolver<'a> { | |
| dirname_fd: out.dirname_fd, | ||
| package_json, | ||
| file_fd: auto_main_result.file_fd, | ||
| browser_remapped: out.browser_remapped, | ||
| ..Default::default() | ||
| }; | ||
| dec_ret!(MatchStatus::Success); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.