diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2023-03-20 14:05:13 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-20 14:05:13 -0400 |
commit | cd53ab5427811bddbed1c30d3733e1df87bb23f9 (patch) | |
tree | 0e2ea8e1b45f2d1d4acd20b666ae1d52d40940c6 /cli | |
parent | d78db7c0910aded010c2faee9a8c0f128f513985 (diff) |
refactor(ext/node): untangle dependencies between js files (#18284)
Moving some code around in `ext/node` is it's a bit better well defined
and makes it possible for others to embed it.
I expect to see no difference in startup perf with this change.
Diffstat (limited to 'cli')
-rw-r--r-- | cli/build.rs | 3 | ||||
-rw-r--r-- | cli/node/mod.rs | 4 | ||||
-rw-r--r-- | cli/tests/testdata/commonjs/init.js | 10 | ||||
-rw-r--r-- | cli/tools/repl/session.rs | 1 | ||||
-rw-r--r-- | cli/worker.rs | 19 |
5 files changed, 16 insertions, 21 deletions
diff --git a/cli/build.rs b/cli/build.rs index 173c8b85d..4943b729a 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -362,8 +362,7 @@ fn create_cli_snapshot(snapshot_path: PathBuf) { deno_io::deno_io::init_ops(Default::default()), deno_fs::deno_fs::init_ops::<PermissionsContainer>(false), deno_flash::deno_flash::init_ops::<PermissionsContainer>(false), // No --unstable - deno_node::deno_node_loading::init_ops::<PermissionsContainer>(None), // No --unstable. - deno_node::deno_node::init_ops(), + deno_node::deno_node::init_ops::<PermissionsContainer>(None), cli::init_ops_and_esm(), // NOTE: This needs to be init_ops_and_esm! ]; diff --git a/cli/node/mod.rs b/cli/node/mod.rs index 8a2f988e1..4cbb1ef05 100644 --- a/cli/node/mod.rs +++ b/cli/node/mod.rs @@ -680,7 +680,9 @@ pub fn translate_cjs_to_esm( let mut handled_reexports: HashSet<String> = HashSet::default(); let mut source = vec![ - r#"const require = Deno[Deno.internal].require.Module.createRequire(import.meta.url);"#.to_string(), + r#"import {createRequire as __internalCreateRequire} from "node:module"; + const require = __internalCreateRequire(import.meta.url);"# + .to_string(), ]; let analysis = perform_cjs_analysis( diff --git a/cli/tests/testdata/commonjs/init.js b/cli/tests/testdata/commonjs/init.js deleted file mode 100644 index 77992a0ad..000000000 --- a/cli/tests/testdata/commonjs/init.js +++ /dev/null @@ -1,10 +0,0 @@ -import { fromFileUrl } from "../../../../test_util/std/path/mod.ts"; - -const DENO_NODE_COMPAT_URL = Deno.env.get("DENO_NODE_COMPAT_URL"); -const moduleAllUrl = `${DENO_NODE_COMPAT_URL}node/module_all.ts`; -let moduleName = import.meta.resolve(Deno.args[0]); -moduleName = fromFileUrl(moduleName); - -const moduleAll = await import(moduleAllUrl); -Deno[Deno.internal].node.initialize(moduleAll.default); -Deno[Deno.internal].require.Module._load(moduleName, null, true); diff --git a/cli/tools/repl/session.rs b/cli/tools/repl/session.rs index 5fa3e4b05..350b38bb9 100644 --- a/cli/tools/repl/session.rs +++ b/cli/tools/repl/session.rs @@ -507,6 +507,7 @@ impl ReplSession { deno_node::initialize_runtime( &mut self.worker.js_runtime, self.proc_state.options.has_node_modules_dir(), + None, )?; self.has_initialized_node_runtime = true; } diff --git a/cli/worker.rs b/cli/worker.rs index 2d467e01d..c505516a0 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -301,10 +301,8 @@ impl CliMainWorker { } fn initialize_main_module_for_node(&mut self) -> Result<(), AnyError> { - deno_node::initialize_runtime( - &mut self.worker.js_runtime, - self.ps.options.has_node_modules_dir(), - )?; + let mut maybe_binary_command_name = None; + if let DenoSubcommand::Run(flags) = self.ps.options.sub_command() { if let Ok(pkg_ref) = NpmPackageReqReference::from_str(&flags.script) { // if the user ran a binary command, we'll need to set process.argv[0] @@ -313,12 +311,16 @@ impl CliMainWorker { .sub_path .as_deref() .unwrap_or(pkg_ref.req.name.as_str()); - deno_node::initialize_binary_command( - &mut self.worker.js_runtime, - binary_name, - )?; + maybe_binary_command_name = Some(binary_name.to_string()); } } + + deno_node::initialize_runtime( + &mut self.worker.js_runtime, + self.ps.options.has_node_modules_dir(), + maybe_binary_command_name, + )?; + Ok(()) } @@ -627,6 +629,7 @@ fn create_web_worker_pre_execute_module_callback( deno_node::initialize_runtime( &mut worker.js_runtime, ps.options.has_node_modules_dir(), + None, )?; } |