diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2024-11-19 09:57:12 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-19 09:57:12 -0500 |
commit | 186b52731c6bb326c4d32905c5e732d082e83465 (patch) | |
tree | 043316c7fc58f18e29c42f35ebfbc6b68eddcca1 /resolvers/node/resolution.rs | |
parent | 661aa22c03f829489e2d9289dee0a8292a95227a (diff) |
fix(node): handle resolving ".//<something>" in npm packages (#26920)
The issue was this package had an import like: `".//index.js"` and we
resolved that as specified, but node normalizes it to `"./index.js"` so
we have to copy node.
Diffstat (limited to 'resolvers/node/resolution.rs')
-rw-r--r-- | resolvers/node/resolution.rs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/resolvers/node/resolution.rs b/resolvers/node/resolution.rs index 673a61abe..c2ec25aca 100644 --- a/resolvers/node/resolution.rs +++ b/resolvers/node/resolution.rs @@ -202,7 +202,7 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> { mode: NodeResolutionMode, ) -> Result<Url, NodeResolveError> { if should_be_treated_as_relative_or_absolute_path(specifier) { - Ok(referrer.join(specifier).map_err(|err| { + Ok(node_join_url(referrer, specifier).map_err(|err| { NodeResolveRelativeJoinError { path: specifier.to_string(), base: referrer.clone(), @@ -1763,6 +1763,17 @@ fn get_module_name_from_builtin_node_module_specifier( Some(specifier) } +/// Node is more lenient joining paths than the url crate is, +/// so this function handles that. +fn node_join_url(url: &Url, path: &str) -> Result<Url, url::ParseError> { + if let Some(suffix) = path.strip_prefix(".//") { + // specifier had two leading slashes + url.join(&format!("./{}", suffix)) + } else { + url.join(path) + } +} + #[cfg(test)] mod tests { use serde_json::json; |