refactor: allow to provide polyfills for Node modules from the snapshot (#17706)

This commit does preparatory work to allow snapshotting Node.js
compatibility layer, that currently lives in `std/node`. The logic was 
changed to allow loading some modules from the snapshot and 
some from the remote URL.

Additionally "module_es_shim.js" that provides exports for "node:module"
is now snapshotted.
This commit is contained in:
Bartek Iwańczuk 2023-02-10 12:40:45 +01:00 committed by GitHub
parent 9ea899afa7
commit ed3a7ce2f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 83 additions and 69 deletions

View file

@ -77,13 +77,11 @@ impl CliModuleLoader {
specifier: &ModuleSpecifier,
maybe_referrer: Option<ModuleSpecifier>,
) -> Result<ModuleCodeSource, AnyError> {
if specifier.as_str() == "node:module" {
return Ok(ModuleCodeSource {
code: deno_runtime::deno_node::MODULE_ES_SHIM.to_string(),
found_url: specifier.to_owned(),
media_type: MediaType::JavaScript,
});
}
// TODO(bartlomieju): uncomment, when all `node:` module have been
// snapshotted
// if specifier.scheme() == "node" {
// unreachable!("Node built-in modules should be handled internally.");
// }
let graph = self.ps.graph();
match graph.get(specifier) {
Some(deno_graph::Module {