Skip to content

Commit 0a2175e

Browse files
authored
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
1 parent 645e1dc commit 0a2175e

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

.changes/dev-watcher-glob.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'tauri-cli': 'patch:bug'
3+
'@tauri-apps/cli': 'patch:bug'
4+
---
5+
6+
Expand glob patterns in workspace member paths so the CLI would watch all matching pathhs.

tooling/cli/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tooling/cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ tokio = { version = "1", features = [ "macros", "sync" ] }
8282
common-path = "1"
8383
serde-value = "0.7.0"
8484
itertools = "0.11"
85+
glob = "0.3"
8586

8687
[target."cfg(windows)".dependencies]
8788
winapi = { version = "0.3", features = [ "handleapi", "processenv", "winbase", "wincon", "winnt" ] }

tooling/cli/src/interface/rust.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use std::{
1919
};
2020

2121
use anyhow::Context;
22+
use glob::glob;
2223
use heck::ToKebabCase;
2324
use ignore::gitignore::{Gitignore, GitignoreBuilder};
2425
use log::{debug, error, info};
@@ -334,6 +335,18 @@ fn lookup<F: FnMut(FileType, PathBuf)>(dir: &Path, mut f: F) {
334335
}
335336
}
336337

338+
// Copied from https://github.com/rust-lang/cargo/blob/69255bb10de7f74511b5cef900a9d102247b6029/src/cargo/core/workspace.rs#L665
339+
fn expand_member_path(path: &Path) -> crate::Result<Vec<PathBuf>> {
340+
let Some(path) = path.to_str() else {
341+
return Err(anyhow::anyhow!("path is not UTF-8 compatible"));
342+
};
343+
let res = glob(path).with_context(|| format!("could not parse pattern `{}`", &path))?;
344+
let res = res
345+
.map(|p| p.with_context(|| format!("unable to match path to pattern `{}`", &path)))
346+
.collect::<Result<Vec<_>, _>>()?;
347+
Ok(res)
348+
}
349+
337350
impl Rust {
338351
fn run_dev<F: Fn(ExitStatus, ExitReason) + Send + Sync + 'static>(
339352
&mut self,
@@ -420,7 +433,21 @@ impl Rust {
420433
.unwrap_or_else(|| vec![tauri_path])
421434
};
422435

436+
let watch_folders = watch_folders
437+
.into_iter()
438+
.flat_map(|p| {
439+
match expand_member_path(&p) {
440+
Ok(p) => p,
441+
Err(err) => {
442+
// If this fails cargo itself should fail too. But we still try to keep going with the unexpanded path.
443+
error!("Error watching {}: {}", p.display(), err.to_string());
444+
vec![p]
445+
}
446+
}
447+
})
448+
.collect::<Vec<_>>();
423449
let watch_folders = watch_folders.iter().map(Path::new).collect::<Vec<_>>();
450+
424451
let common_ancestor = common_path::common_path_all(watch_folders.clone()).unwrap();
425452
let ignore_matcher = build_ignore_matcher(&common_ancestor);
426453

0 commit comments

Comments
 (0)