mirror of
https://github.com/denoland/deno.git
synced 2024-12-21 23:04:45 -05:00
fix(cli): support --watch when running cjs npm packages (#25038)
This commit is contained in:
parent
533d31bc4e
commit
130a2592f1
3 changed files with 53 additions and 3 deletions
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue