Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: watch exclude flag with watch flag for the directory containing the excluded file #26309

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions cli/util/file_watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ where
F: Future<Output = Result<(), AnyError>>,
{
let exclude_set = flags.resolve_watch_exclude_set()?;
let exclude_set_cloned = exclude_set.clone();
let (paths_to_watch_tx, mut paths_to_watch_rx) =
tokio::sync::mpsc::unbounded_channel();
let (restart_tx, mut restart_rx) = tokio::sync::mpsc::unbounded_channel();
Expand Down Expand Up @@ -284,15 +285,35 @@ where
changed_paths_
.borrow_mut()
.clone_from(&received_changed_paths);

match *watcher_.restart_mode.lock() {
WatcherRestartMode::Automatic => {
let _ = restart_tx.send(());
}
WatcherRestartMode::Manual => {
// TODO(bartlomieju): should we fail on sending changed paths?
let _ = changed_paths_tx.send(received_changed_paths);
let excluded_paths = &exclude_set_cloned;
let received_changed_paths_cloned = received_changed_paths.clone();
let is_excluded_file_changed = received_changed_paths_cloned
.clone()
.unwrap()
.iter()
.any(|path| {
excluded_paths.matches_path(path)
|| excluded_paths.inner().iter().any(|excluded_path| {
excluded_path.base_path().unwrap().is_dir()
&& path.starts_with(excluded_path.base_path().unwrap())
})
});
// skip restart when the changed path is from the excluded set
if !is_excluded_file_changed {
match *watcher_.restart_mode.lock() {
WatcherRestartMode::Automatic => {
let _ = restart_tx.send(());
}
WatcherRestartMode::Manual => {
// TODO(bartlomieju): should we fail on sending changed paths?
let _ = changed_paths_tx.send(received_changed_paths);
}
}
} else {
log::debug!(
"Following file content changed, but excluded from watch: {:?}",
received_changed_paths_cloned.unwrap()[0]
);
}
}
});
Expand Down
33 changes: 33 additions & 0 deletions tests/integration/watcher_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1695,6 +1695,39 @@ async fn run_watch_with_excluded_paths() {
check_alive_then_kill(child);
}

#[flaky_test(tokio)]
async fn watch_directory_with_excluded_file_in_same_directory() {
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("console.log('hello')");

let mut child = util::deno_cmd()
.current_dir(t.path())
.arg("run")
.arg("--watch=.")
.arg("--watch-exclude=file_to_exclude.js")
.arg("-L")
.arg("debug")
.arg(&file_to_watch)
.env("NO_COLOR", "1")
.piped_output()
.spawn()
.unwrap();
let (_stdout_lines, mut stderr_lines) = child_lines(&mut child);
wait_contains("Watching paths", &mut stderr_lines).await;
file_to_exclude.write("console.log(\"This file's content has been changed, but it's excluded from watch.\")");
wait_contains(
"Following file content changed, but excluded from watch:",
&mut stderr_lines,
)
.await;
check_alive_then_kill(child);
}

#[flaky_test(tokio)]
async fn run_hmr_server() {
let t = TempDir::new();
Expand Down
Loading