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 --- ext/node/lib.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'ext/node/lib.rs') diff --git a/ext/node/lib.rs b/ext/node/lib.rs index 0987febe8..16d15e677 100644 --- a/ext/node/lib.rs +++ b/ext/node/lib.rs @@ -26,7 +26,6 @@ pub use path::PathClean; pub use polyfill::find_builtin_node_module; pub use polyfill::is_builtin_node_module; pub use polyfill::NodeModulePolyfill; -pub use polyfill::NodeModulePolyfillSpecifier; pub use polyfill::SUPPORTED_BUILTIN_NODE_MODULES; pub use resolution::get_closest_package_json; pub use resolution::get_package_scope_config; @@ -462,18 +461,15 @@ pub fn init( pub async fn initialize_runtime( js_runtime: &mut JsRuntime, - module_all_url: &str, uses_local_node_modules_dir: bool, ) -> Result<(), AnyError> { let source_code = &format!( - r#"(async function loadBuiltinNodeModules(moduleAllUrl, nodeGlobalThisName, usesLocalNodeModulesDir) {{ - const moduleAll = await import(moduleAllUrl); - Deno[Deno.internal].node.initialize(moduleAll.default, nodeGlobalThisName); + r#"(async function loadBuiltinNodeModules(nodeGlobalThisName, usesLocalNodeModulesDir) {{ + Deno[Deno.internal].node.initialize(Deno[Deno.internal].nodeModuleAll, nodeGlobalThisName); if (usesLocalNodeModulesDir) {{ Deno[Deno.internal].require.setUsesLocalNodeModulesDir(); }} - }})('{}', '{}', {});"#, - module_all_url, + }})('{}', {});"#, NODE_GLOBAL_THIS_NAME.as_str(), uses_local_node_modules_dir, ); -- cgit v1.2.3