From 0a2175eabb736b2a4cd01ab682e08be0b5ebb2b9 Mon Sep 17 00:00:00 2001 From: Fabian-Lars Date: Wed, 20 Dec 2023 14:57:10 +0100 Subject: [PATCH] fix(cli): expand globs in workspace member paths (#8439) * fix(cli): Expand globs in workspace member paths fixes #8403 * unusued import * into_iter * return error instead of of empty vec * Update dev-watcher-glob.md --- .changes/dev-watcher-glob.md | 6 ++++++ tooling/cli/Cargo.lock | 1 + tooling/cli/Cargo.toml | 1 + tooling/cli/src/interface/rust.rs | 27 +++++++++++++++++++++++++++ 4 files changed, 35 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 00000000000..86f323beee1 --- /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 so the CLI would watch all matching pathhs. diff --git a/tooling/cli/Cargo.lock b/tooling/cli/Cargo.lock index 16ebdd6c483..2acf3345953 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 875a44a4b71..bbc830b072a 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 88c391a6cc7..f015b9e9599 100644 --- a/tooling/cli/src/interface/rust.rs +++ b/tooling/cli/src/interface/rust.rs @@ -19,6 +19,7 @@ use std::{ }; use anyhow::Context; +use glob::glob; use heck::ToKebabCase; use ignore::gitignore::{Gitignore, GitignoreBuilder}; use log::{debug, error, info}; @@ -334,6 +335,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 Err(anyhow::anyhow!("path is not UTF-8 compatible")); + }; + 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 +433,21 @@ impl Rust { .unwrap_or_else(|| vec![tauri_path]) }; + let watch_folders = watch_folders + .into_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] + } + } + }) + .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);