feat: support node built-in module imports (#17264)

Co-authored-by: David Sherret <dsherret@gmail.com>
This commit is contained in:
Bartek Iwańczuk 2023-01-24 15:05:54 +01:00 committed by GitHub
parent cadeaae045
commit fc2e00152b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 925 additions and 445 deletions

23
cli/cache/mod.rs vendored
View file

@ -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 {