From 75209e12f19ca5d4a2a7c9008fba63a487ad8e6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 15 Feb 2023 19:44:52 +0100 Subject: feat: wire up ext/node to the Node compatibility layer (#17785) This PR changes Node.js/npm compatibility layer to use polyfills for built-in Node.js embedded in the snapshot (that are coming from "ext/node" extension). As a result loading `std/node`, either from "https://deno.land/std@/" or from "DENO_NODE_COMPAT_URL" env variable were removed. All code that is imported via "npm:" specifiers now uses code embedded in the snapshot. Several fixes were applied to various modules in "ext/node" to make tests pass. --------- Co-authored-by: Yoshiya Hinosawa Co-authored-by: Divy Srivastava --- cli/node/mod.rs | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) (limited to 'cli/node/mod.rs') diff --git a/cli/node/mod.rs b/cli/node/mod.rs index e0ab2f050..397e189d6 100644 --- a/cli/node/mod.rs +++ b/cli/node/mod.rs @@ -27,7 +27,6 @@ use deno_runtime::deno_node::package_imports_resolve; use deno_runtime::deno_node::package_resolve; use deno_runtime::deno_node::path_to_declaration_path; use deno_runtime::deno_node::NodeModuleKind; -use deno_runtime::deno_node::NodeModulePolyfillSpecifier; use deno_runtime::deno_node::NodePermissions; use deno_runtime::deno_node::NodeResolutionMode; use deno_runtime::deno_node::PackageJson; @@ -39,7 +38,6 @@ use once_cell::sync::Lazy; use regex::Regex; use crate::cache::NodeAnalysisCache; -use crate::deno_std::CURRENT_STD_URL; use crate::file_fetcher::FileFetcher; use crate::npm::NpmPackageResolver; @@ -106,33 +104,10 @@ impl NodeResolution { } } -static NODE_COMPAT_URL: Lazy = Lazy::new(|| { - if let Ok(url_str) = std::env::var("DENO_NODE_COMPAT_URL") { - let url = Url::parse(&url_str).expect( - "Malformed DENO_NODE_COMPAT_URL value, make sure it's a file URL ending with a slash" - ); - return url; - } - - CURRENT_STD_URL.clone() -}); - -pub static MODULE_ALL_URL: Lazy = - Lazy::new(|| NODE_COMPAT_URL.join("node/module_all.ts").unwrap()); - +// TODO(bartlomieju): seems super wasteful to parse specified each time pub fn resolve_builtin_node_module(specifier: &str) -> Result { if let Some(module) = find_builtin_node_module(specifier) { - match module.specifier { - // We will load the source code from the `std/node` polyfill. - NodeModulePolyfillSpecifier::StdNode(specifier) => { - let module_url = NODE_COMPAT_URL.join(specifier).unwrap(); - return Ok(module_url); - } - // The module has already been snapshotted and is present in the binary. - NodeModulePolyfillSpecifier::Embedded(specifier) => { - return Ok(ModuleSpecifier::parse(specifier).unwrap()); - } - } + return Ok(ModuleSpecifier::parse(module.specifier).unwrap()); } Err(generic_error(format!( -- cgit v1.2.3