summaryrefslogtreecommitdiff
path: root/ext/node/path.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-12-14 16:09:05 +0100
committerGitHub <noreply@github.com>2023-12-14 15:09:05 +0000
commitac04787c30b67ba9c7fb800eae8361ba419e7f4e (patch)
tree0260d7b5ac0c94c1ec1220813c16ef9318be102e /ext/node/path.rs
parent19d52b9a55a6d5a67f27cbcc6cbe9c6c15865d63 (diff)
fix(node): support resolving a package.json import to a builtin node module (#21576)
Closes https://github.com/denoland/deno/issues/21501
Diffstat (limited to 'ext/node/path.rs')
-rw-r--r--ext/node/path.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/ext/node/path.rs b/ext/node/path.rs
index 71cc0741e..e20555a2c 100644
--- a/ext/node/path.rs
+++ b/ext/node/path.rs
@@ -1,8 +1,11 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
use std::path::Component;
+use std::path::Path;
use std::path::PathBuf;
+use deno_core::ModuleSpecifier;
+
/// Extension to path_clean::PathClean
pub trait PathClean<T> {
fn clean(&self) -> T;
@@ -38,3 +41,10 @@ impl PathClean<PathBuf> for PathBuf {
}
}
}
+
+pub(crate) fn to_file_specifier(path: &Path) -> ModuleSpecifier {
+ match ModuleSpecifier::from_file_path(path) {
+ Ok(url) => url,
+ Err(_) => panic!("Invalid path: {}", path.display()),
+ }
+}