summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorLuca Casonato <hello@lcas.dev>2024-08-14 15:21:11 +0200
committerGitHub <noreply@github.com>2024-08-14 15:21:11 +0200
commit130a2592f1e946be563c7f167d7127f49a1014d1 (patch)
treea63627f8e153269b97c70bf4fc0445e6055dd1bd /cli
parent533d31bc4e9c0cae2b9047850c39c68bf494595e (diff)
fix(cli): support --watch when running cjs npm packages (#25038)
Diffstat (limited to 'cli')
-rw-r--r--cli/args/mod.rs2
-rw-r--r--cli/worker.rs17
2 files changed, 16 insertions, 3 deletions
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;