summaryrefslogtreecommitdiff
path: root/ext/node
diff options
context:
space:
mode:
authorNathan Whitaker <17734409+nathanwhit@users.noreply.github.com>2024-10-31 10:02:31 -0700
committerGitHub <noreply@github.com>2024-10-31 10:02:31 -0700
commit6d44952d4daaaab8ed9ec82212d2256c058eb05d (patch)
treefb46c0acd6d04a896a1424592e7ef703a573db01 /ext/node
parent951103fc8de952f32386121d3f0e4803fe267ea4 (diff)
fix(ext/node): resolve exports even if parent module filename isn't present (#26553)
Fixes https://github.com/denoland/deno/issues/26505 I'm not exactly sure how this case comes about (I tried to write tests for it but couldn't manage to reproduce it), but what happens is the parent filename ends up null, and we bail out of resolving the specifier in package exports. I've checked, and in node the parent filename is also null (so that's not a bug on our part), but node continues to resolve even in that case. So this PR should match node's behavior more closely than we currently do.
Diffstat (limited to 'ext/node')
-rw-r--r--ext/node/ops/require.rs8
-rw-r--r--ext/node/polyfills/01_require.js6
2 files changed, 7 insertions, 7 deletions
diff --git a/ext/node/ops/require.rs b/ext/node/ops/require.rs
index 43867053b..7524fb43c 100644
--- a/ext/node/ops/require.rs
+++ b/ext/node/ops/require.rs
@@ -529,12 +529,16 @@ where
return Ok(None);
};
- let referrer = Url::from_file_path(parent_path).unwrap();
+ let referrer = if parent_path.is_empty() {
+ None
+ } else {
+ Some(Url::from_file_path(parent_path).unwrap())
+ };
let r = node_resolver.package_exports_resolve(
&pkg.path,
&format!(".{expansion}"),
exports,
- Some(&referrer),
+ referrer.as_ref(),
NodeModuleKind::Cjs,
REQUIRE_CONDITIONS,
NodeResolutionMode::Execution,
diff --git a/ext/node/polyfills/01_require.js b/ext/node/polyfills/01_require.js
index 5b0980c31..7935903a8 100644
--- a/ext/node/polyfills/01_require.js
+++ b/ext/node/polyfills/01_require.js
@@ -523,17 +523,13 @@ function resolveExports(
return;
}
- if (!parentPath) {
- return false;
- }
-
return op_require_resolve_exports(
usesLocalNodeModulesDir,
modulesPath,
request,
name,
expansion,
- parentPath,
+ parentPath ?? "",
) ?? false;
}