summaryrefslogtreecommitdiff
path: root/cli/cache/mod.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-01-24 15:05:54 +0100
committerGitHub <noreply@github.com>2023-01-24 09:05:54 -0500
commitfc2e00152b162280e78b06028d51274e33275629 (patch)
treeee567a99cabc6633454de231939f7d898146f1d8 /cli/cache/mod.rs
parentcadeaae045d2489fe125286b8c2c641c6d973c3f (diff)
feat: support node built-in module imports (#17264)
Co-authored-by: David Sherret <dsherret@gmail.com>
Diffstat (limited to 'cli/cache/mod.rs')
-rw-r--r--cli/cache/mod.rs23
1 files changed, 21 insertions, 2 deletions
diff --git a/cli/cache/mod.rs b/cli/cache/mod.rs
index 4d255b014..c8fcaa223 100644
--- a/cli/cache/mod.rs
+++ b/cli/cache/mod.rs
@@ -65,7 +65,7 @@ impl FetchCacher {
impl Loader for FetchCacher {
fn get_cache_info(&self, specifier: &ModuleSpecifier) -> Option<CacheInfo> {
- if specifier.scheme() == "npm" {
+ if matches!(specifier.scheme(), "npm" | "node") {
return None;
}
@@ -101,7 +101,26 @@ impl Loader for FetchCacher {
));
}
- let specifier = specifier.clone();
+ let specifier =
+ if let Some(module_name) = specifier.as_str().strip_prefix("node:") {
+ if module_name == "module" {
+ // the source code for "node:module" is built-in rather than
+ // being from deno_std like the other modules
+ return Box::pin(futures::future::ready(Ok(Some(
+ deno_graph::source::LoadResponse::External {
+ specifier: specifier.clone(),
+ },
+ ))));
+ }
+
+ match crate::node::resolve_builtin_node_module(module_name) {
+ Ok(specifier) => specifier,
+ Err(err) => return Box::pin(futures::future::ready(Err(err))),
+ }
+ } else {
+ specifier.clone()
+ };
+
let permissions = if is_dynamic {
self.dynamic_permissions.clone()
} else {