summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/args/mod.rs2
-rw-r--r--cli/worker.rs17
-rw-r--r--tests/integration/watcher_tests.rs37
3 files changed, 53 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;
diff --git a/tests/integration/watcher_tests.rs b/tests/integration/watcher_tests.rs
index 3cec2f442..6203a62d9 100644
--- a/tests/integration/watcher_tests.rs
+++ b/tests/integration/watcher_tests.rs
@@ -3,6 +3,7 @@
use flaky_test::flaky_test;
use test_util as util;
use test_util::assert_contains;
+use test_util::env_vars_for_npm_tests;
use test_util::TempDir;
use tokio::io::AsyncBufReadExt;
use util::DenoChild;
@@ -707,6 +708,42 @@ async fn run_watch_no_dynamic() {
check_alive_then_kill(child);
}
+#[flaky_test(tokio)]
+async fn run_watch_npm_specifier() {
+ let _g = util::http_server();
+ let t = TempDir::new();
+
+ let file_to_watch = t.path().join("file_to_watch.txt");
+ file_to_watch.write("Hello world");
+
+ let mut child = util::deno_cmd()
+ .current_dir(t.path())
+ .envs(env_vars_for_npm_tests())
+ .arg("run")
+ .arg("--watch=file_to_watch.txt")
+ .arg("-L")
+ .arg("debug")
+ .arg("npm:@denotest/bin/cli-cjs")
+ .arg("Hello world")
+ .env("NO_COLOR", "1")
+ .piped_output()
+ .spawn()
+ .unwrap();
+ let (mut stdout_lines, mut stderr_lines) = child_lines(&mut child);
+
+ wait_contains("Hello world", &mut stdout_lines).await;
+ wait_for_watcher("file_to_watch.txt", &mut stderr_lines).await;
+
+ // Change content of the file
+ file_to_watch.write("Hello world2");
+
+ wait_contains("Restarting", &mut stderr_lines).await;
+ wait_contains("Hello world", &mut stdout_lines).await;
+ wait_for_watcher("file_to_watch.txt", &mut stderr_lines).await;
+
+ check_alive_then_kill(child);
+}
+
// TODO(bartlomieju): this test became flaky on macOS runner; it is unclear
// if that's because of a bug in code or the runner itself. We should reenable
// it once we upgrade to XL runners for macOS.