Skip to content
New issue

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

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

Already on GitHub? # to your account

fix(cli): expand globs in workspace member paths #8439

Merged
merged 5 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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/dev-watcher-glob.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'tauri-cli': 'patch:bug'
'@tauri-apps/cli': 'patch:bug'
---

Expand glob patterns in workspace member paths.
1 change: 1 addition & 0 deletions tooling/cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tooling/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ] }
Expand Down
27 changes: 27 additions & 0 deletions tooling/cli/src/interface/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -334,6 +335,18 @@ fn lookup<F: FnMut(FileType, PathBuf)>(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<Vec<PathBuf>> {
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::<Result<Vec<_>, _>>()?;
Ok(res)
}

impl Rust {
fn run_dev<F: Fn(ExitStatus, ExitReason) + Send + Sync + 'static>(
&mut self,
Expand Down Expand Up @@ -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::<Vec<_>>();
let watch_folders = watch_folders.iter().map(Path::new).collect::<Vec<_>>();

let common_ancestor = common_path::common_path_all(watch_folders.clone()).unwrap();
let ignore_matcher = build_ignore_matcher(&common_ancestor);

Expand Down
Loading