From ac04787c30b67ba9c7fb800eae8361ba419e7f4e Mon Sep 17 00:00:00 2001 From: David Sherret Date: Thu, 14 Dec 2023 16:09:05 +0100 Subject: fix(node): support resolving a package.json import to a builtin node module (#21576) Closes https://github.com/denoland/deno/issues/21501 --- ext/node/ops/require.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'ext/node/ops') diff --git a/ext/node/ops/require.rs b/ext/node/ops/require.rs index 8010558c5..ada123686 100644 --- a/ext/node/ops/require.rs +++ b/ext/node/ops/require.rs @@ -431,7 +431,13 @@ where NodeResolutionMode::Execution, permissions, ) - .map(|r| Some(r.to_string_lossy().to_string())) + .map(|r| { + Some(if r.scheme() == "file" { + r.to_file_path().unwrap().to_string_lossy().to_string() + } else { + r.to_string() + }) + }) } else { Ok(None) } @@ -515,7 +521,13 @@ where NodeResolutionMode::Execution, permissions, ) - .map(|r| Some(r.to_string_lossy().to_string())) + .map(|r| { + Some(if r.scheme() == "file" { + r.to_file_path().unwrap().to_string_lossy().to_string() + } else { + r.to_string() + }) + }) } else { Ok(None) } @@ -588,7 +600,7 @@ where NodeResolutionMode::Execution, permissions, ) - .map(|r| Some(Url::from_file_path(r).unwrap().to_string())) + .map(|r| Some(r.to_string())) } else { Ok(None) } -- cgit v1.2.3