From 08d5d32dfccc4dc38c2aa95c81229bf031d3ac7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Czerniawski?= <33061335+lczerniawski@users.noreply.github.com> Date: Wed, 27 Mar 2024 23:47:46 +0100 Subject: feat: add `--watch-exclude` flag (#21935) This PR introduces the ability to exclude certain paths from the file watcher in Deno. This is particularly useful when running scripts in watch mode, as it allows developers to prevent unnecessary restarts when changes are made to files that do not affect the running script, or when executing scripts that generate new files which results in an infinite restart loop. --------- Co-authored-by: David Sherret --- tests/integration/watcher_tests.rs | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'tests') diff --git a/tests/integration/watcher_tests.rs b/tests/integration/watcher_tests.rs index 6a2cab08a..6d18ad2f4 100644 --- a/tests/integration/watcher_tests.rs +++ b/tests/integration/watcher_tests.rs @@ -1613,6 +1613,45 @@ async fn run_watch_inspect() { check_alive_then_kill(child); } +#[tokio::test] +async fn run_watch_with_excluded_paths() { + let t = TempDir::new(); + + let file_to_exclude = t.path().join("file_to_exclude.js"); + file_to_exclude.write("export const foo = 0;"); + + let file_to_watch = t.path().join("file_to_watch.js"); + file_to_watch + .write("import { foo } from './file_to_exclude.js'; console.log(foo);"); + + let mjs_file_to_exclude = t.path().join("file_to_exclude.mjs"); + mjs_file_to_exclude.write("export const foo = 0;"); + + let mut child = util::deno_cmd() + .current_dir(util::testdata_path()) + .arg("run") + .arg("--watch") + .arg("--watch-exclude=file_to_exclude.js,*.mjs") + .arg("-L") + .arg("debug") + .arg(&file_to_watch) + .env("NO_COLOR", "1") + .piped_output() + .spawn() + .unwrap(); + let (mut stdout_lines, mut stderr_lines) = child_lines(&mut child); + + wait_contains("0", &mut stdout_lines).await; + wait_for_watcher("file_to_watch.js", &mut stderr_lines).await; + + // Confirm that restarting doesn't occurs when a excluded file is updated + file_to_exclude.write("export const foo = 42;"); + mjs_file_to_exclude.write("export const foo = 42;"); + + wait_contains("finished", &mut stderr_lines).await; + check_alive_then_kill(child); +} + #[tokio::test] async fn run_hmr_server() { let t = TempDir::new(); -- cgit v1.2.3