From 4e4b94d319d9445fdd509e425f5925f390b11a9c Mon Sep 17 00:00:00 2001 From: FabianLars Date: Tue, 19 Dec 2023 20:21:20 +0100 Subject: [PATCH 1/5] fix(cli): Expand globs in workspace member paths fixes #8403 --- .changes/dev-watcher-glob.md | 6 ++++++ tooling/cli/Cargo.lock | 1 + tooling/cli/Cargo.toml | 1 + tooling/cli/src/interface/rust.rs | 28 ++++++++++++++++++++++++++++ 4 files changed, 36 insertions(+) create mode 100644 .changes/dev-watcher-glob.md diff --git a/.changes/dev-watcher-glob.md b/.changes/dev-watcher-glob.md new file mode 100644 index 000000000000..e95c57c9ebe5 --- /dev/null +++ b/.changes/dev-watcher-glob.md @@ -0,0 +1,6 @@ +--- +'tauri-cli': 'patch:bug' +'@tauri-apps/cli': 'patch:bug' +--- + +Expand glob patterns in workspace member paths. diff --git a/tooling/cli/Cargo.lock b/tooling/cli/Cargo.lock index 16ebdd6c4837..2acf3345953a 100644 --- a/tooling/cli/Cargo.lock +++ b/tooling/cli/Cargo.lock @@ -3448,6 +3448,7 @@ dependencies = [ "ctrlc", "dialoguer", "env_logger", + "glob", "handlebars", "heck", "html5ever", diff --git a/tooling/cli/Cargo.toml b/tooling/cli/Cargo.toml index 875a44a4b71a..bbc830b072aa 100644 --- a/tooling/cli/Cargo.toml +++ b/tooling/cli/Cargo.toml @@ -82,6 +82,7 @@ tokio = { version = "1", features = [ "macros", "sync" ] } common-path = "1" serde-value = "0.7.0" itertools = "0.11" +glob = "0.3" [target."cfg(windows)".dependencies] winapi = { version = "0.3", features = [ "handleapi", "processenv", "winbase", "wincon", "winnt" ] } diff --git a/tooling/cli/src/interface/rust.rs b/tooling/cli/src/interface/rust.rs index 88c391a6cc7c..0beb55f780b1 100644 --- a/tooling/cli/src/interface/rust.rs +++ b/tooling/cli/src/interface/rust.rs @@ -19,8 +19,10 @@ use std::{ }; use anyhow::Context; +use glob::glob; use heck::ToKebabCase; use ignore::gitignore::{Gitignore, GitignoreBuilder}; +use itertools::Itertools; use log::{debug, error, info}; use notify::RecursiveMode; use notify_debouncer_mini::new_debouncer; @@ -334,6 +336,18 @@ fn lookup(dir: &Path, mut f: F) { } } +// Copied from https://github.com/rust-lang/cargo/blob/69255bb10de7f74511b5cef900a9d102247b6029/src/cargo/core/workspace.rs#L665 +fn expand_member_path(path: &Path) -> crate::Result> { + let Some(path) = path.to_str() else { + return Ok(Vec::new()); + }; + let res = glob(path).with_context(|| format!("could not parse pattern `{}`", &path))?; + let res = res + .map(|p| p.with_context(|| format!("unable to match path to pattern `{}`", &path))) + .collect::, _>>()?; + Ok(res) +} + impl Rust { fn run_dev( &mut self, @@ -420,7 +434,21 @@ impl Rust { .unwrap_or_else(|| vec![tauri_path]) }; + let watch_folders = watch_folders + .iter() + .flat_map(|p| { + match expand_member_path(p) { + Ok(p) => p, + Err(err) => { + // If this fails cargo itself should fail too. But we still try to keep going with the unexpanded path. + error!("Error watching {}: {}", p.display(), err.to_string()); + vec![p.to_owned()] + } + } + }) + .collect::>(); let watch_folders = watch_folders.iter().map(Path::new).collect::>(); + let common_ancestor = common_path::common_path_all(watch_folders.clone()).unwrap(); let ignore_matcher = build_ignore_matcher(&common_ancestor); From e92602de181ec281584d90828323d79061ba788d Mon Sep 17 00:00:00 2001 From: FabianLars Date: Tue, 19 Dec 2023 20:30:27 +0100 Subject: [PATCH 2/5] unusued import --- tooling/cli/src/interface/rust.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/tooling/cli/src/interface/rust.rs b/tooling/cli/src/interface/rust.rs index 0beb55f780b1..e66a79374d71 100644 --- a/tooling/cli/src/interface/rust.rs +++ b/tooling/cli/src/interface/rust.rs @@ -22,7 +22,6 @@ use anyhow::Context; use glob::glob; use heck::ToKebabCase; use ignore::gitignore::{Gitignore, GitignoreBuilder}; -use itertools::Itertools; use log::{debug, error, info}; use notify::RecursiveMode; use notify_debouncer_mini::new_debouncer; From 500a78825aa3e3bf1f665455f77030f42f5c5c3c Mon Sep 17 00:00:00 2001 From: FabianLars Date: Wed, 20 Dec 2023 12:19:47 +0100 Subject: [PATCH 3/5] into_iter --- tooling/cli/src/interface/rust.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tooling/cli/src/interface/rust.rs b/tooling/cli/src/interface/rust.rs index e66a79374d71..c796da93b881 100644 --- a/tooling/cli/src/interface/rust.rs +++ b/tooling/cli/src/interface/rust.rs @@ -434,14 +434,14 @@ impl Rust { }; let watch_folders = watch_folders - .iter() + .into_iter() .flat_map(|p| { - match expand_member_path(p) { + match expand_member_path(&p) { Ok(p) => p, Err(err) => { // If this fails cargo itself should fail too. But we still try to keep going with the unexpanded path. error!("Error watching {}: {}", p.display(), err.to_string()); - vec![p.to_owned()] + vec![p] } } }) From 18fea1f18691f19fd7302a33c09420439b0ec57d Mon Sep 17 00:00:00 2001 From: FabianLars Date: Wed, 20 Dec 2023 12:25:19 +0100 Subject: [PATCH 4/5] return error instead of of empty vec --- tooling/cli/src/interface/rust.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tooling/cli/src/interface/rust.rs b/tooling/cli/src/interface/rust.rs index c796da93b881..f015b9e9599e 100644 --- a/tooling/cli/src/interface/rust.rs +++ b/tooling/cli/src/interface/rust.rs @@ -338,7 +338,7 @@ fn lookup(dir: &Path, mut f: F) { // Copied from https://github.com/rust-lang/cargo/blob/69255bb10de7f74511b5cef900a9d102247b6029/src/cargo/core/workspace.rs#L665 fn expand_member_path(path: &Path) -> crate::Result> { let Some(path) = path.to_str() else { - return Ok(Vec::new()); + return Err(anyhow::anyhow!("path is not UTF-8 compatible")); }; let res = glob(path).with_context(|| format!("could not parse pattern `{}`", &path))?; let res = res From dccc43be0563b5bb37e7c5d7447009fed2bb1347 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Wed, 20 Dec 2023 15:56:51 +0200 Subject: [PATCH 5/5] Update dev-watcher-glob.md --- .changes/dev-watcher-glob.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changes/dev-watcher-glob.md b/.changes/dev-watcher-glob.md index e95c57c9ebe5..86f323beee14 100644 --- a/.changes/dev-watcher-glob.md +++ b/.changes/dev-watcher-glob.md @@ -3,4 +3,4 @@ '@tauri-apps/cli': 'patch:bug' --- -Expand glob patterns in workspace member paths. +Expand glob patterns in workspace member paths so the CLI would watch all matching pathhs.