Skip to content
Merged
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
6 changes: 6 additions & 0 deletions .changes/fix-taurignore-root.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri-cli": "patch:bug"
"@tauri-apps/cli": "patch:bug"
---

Fix `tauri dev` not watching the app at all when its `.taurignore` contains a pattern like `/*` that matches every entry at the top level, even if other entries are re-included with `!` negations. Watch folders are now always watched; ignore rules apply to their entries and to change events.
86 changes: 69 additions & 17 deletions crates/tauri-cli/src/interface/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,26 @@ fn lookup<F: FnMut(FileType, PathBuf)>(dir: &Path, mut f: F) {
}
}

/// The paths the dev watcher watches: the entries of every watch folder that the ignore files
/// don't exclude. Every folder is walked, even when a pattern such as `/*` matches the folder
/// itself; ignore rules apply to its entries here and to every change event.
fn watch_targets(watch_folders: &[PathBuf]) -> Vec<(PathBuf, RecursiveMode)> {
let mut targets = Vec::new();
for path in watch_folders {
lookup(path, |file_type, p| {
if p != *path {
let mode = if file_type.is_dir() {
RecursiveMode::Recursive
} else {
RecursiveMode::NonRecursive
};
targets.push((p, mode));
}
});
}
targets
}

fn dev_options(
mobile: bool,
args: &mut Vec<String>,
Expand Down Expand Up @@ -533,23 +553,12 @@ impl Rust {
}
})
.unwrap();
for path in watch_folders {
if !ignore_matcher.is_ignore(&path, true) {
log::info!("Watching {} for changes...", display_path(&path));
lookup(&path, |file_type, p| {
if p != path {
log::debug!("Watching {} for changes...", display_path(&p));
let _ = watcher.watch(
&p,
if file_type.is_dir() {
RecursiveMode::Recursive
} else {
RecursiveMode::NonRecursive
},
);
}
});
}
for path in &watch_folders {
log::info!("Watching {} for changes...", display_path(path));
}
for (path, mode) in watch_targets(&watch_folders) {
log::debug!("Watching {} for changes...", display_path(&path));
let _ = watcher.watch(&path, mode);
}

while let Ok(events) = rx.recv() {
Expand Down Expand Up @@ -1792,6 +1801,49 @@ mod tests {
);
}

fn taurignore_root_fixture() -> tempfile::TempDir {
let temp_dir = tempfile::tempdir().unwrap();
let dir = temp_dir.path();
fs::create_dir_all(dir.join("src")).unwrap();
fs::create_dir_all(dir.join("assets")).unwrap();
fs::write(dir.join("src/main.rs"), "").unwrap();
fs::write(dir.join("Cargo.toml"), "").unwrap();
fs::write(dir.join("README.md"), "").unwrap();
fs::write(dir.join(".taurignore"), "/*\n!/*.toml\n!/*.rs\n!/src\n").unwrap();
temp_dir
}

#[test]
fn watch_targets_watch_a_folder_whose_taurignore_matches_it() {
let temp_dir = taurignore_root_fixture();
let dir = temp_dir.path();

let mut watched: Vec<PathBuf> = watch_targets(&[dir.to_path_buf()])
.into_iter()
.map(|(path, _)| path.strip_prefix(dir).unwrap().to_path_buf())
.collect();
watched.sort();

assert_eq!(
watched,
vec![PathBuf::from("Cargo.toml"), PathBuf::from("src")]
);
}

#[test]
fn ignore_matcher_filters_events_under_a_root_wide_pattern() {
let temp_dir = taurignore_root_fixture();
let dir = temp_dir.path();

let ignore_matcher = build_ignore_matcher(dir);

assert!(!ignore_matcher.is_ignore(&dir.join("src"), true));
assert!(!ignore_matcher.is_ignore(&dir.join("src/main.rs"), false));
assert!(!ignore_matcher.is_ignore(&dir.join("Cargo.toml"), false));
assert!(ignore_matcher.is_ignore(&dir.join("README.md"), false));
assert!(ignore_matcher.is_ignore(&dir.join("assets"), true));
}

#[test]
fn parse_cargo_option() {
let args = [
Expand Down
Loading