mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 19:08:15 +00:00
feat: support node built-in module imports (#17264)
Co-authored-by: David Sherret <dsherret@gmail.com>
This commit is contained in:
parent
cadeaae045
commit
fc2e00152b
32 changed files with 925 additions and 445 deletions
23
cli/cache/mod.rs
vendored
23
cli/cache/mod.rs
vendored
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue