From 130a2592f1e946be563c7f167d7127f49a1014d1 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Wed, 14 Aug 2024 15:21:11 +0200 Subject: fix(cli): support --watch when running cjs npm packages (#25038) --- cli/args/mod.rs | 2 -- cli/worker.rs | 17 ++++++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'cli') diff --git a/cli/args/mod.rs b/cli/args/mod.rs index 0f6f050ef..65f9183d5 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -1151,8 +1151,6 @@ impl CliOptions { resolve_url_or_path("./$deno$stdin.ts", &cwd) .map_err(AnyError::from) })? - } else if run_flags.watch.is_some() { - resolve_url_or_path(&run_flags.script, self.initial_cwd())? } else if NpmPackageReqReference::from_str(&run_flags.script).is_ok() { ModuleSpecifier::parse(&run_flags.script)? } else { diff --git a/cli/worker.rs b/cli/worker.rs index 8673804ab..82051da6c 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -280,7 +280,22 @@ impl CliMainWorker { /// Execute the given main module emitting load and unload events before and after execution /// respectively. pub async fn execute(&mut self) -> Result<(), AnyError> { - self.inner.execute_main_module_possibly_with_npm().await?; + if self.inner.is_main_cjs { + deno_node::load_cjs_module( + &mut self.inner.worker.js_runtime, + &self + .inner + .main_module + .to_file_path() + .unwrap() + .to_string_lossy(), + true, + self.inner.shared.options.inspect_brk, + )?; + } else { + self.inner.execute_main_module_possibly_with_npm().await?; + } + self.inner.worker.dispatch_load_event()?; self.pending_unload = true; -- cgit v1.2.3