From 0fa17a839f584e97415942625952b2c5842ce07b Mon Sep 17 00:00:00 2001 From: daimond113 <72147841+daimond113@users.noreply.github.com> Date: Sun, 8 Dec 2024 12:15:30 +0100 Subject: [PATCH] feat: support using workspace root as a member --- CHANGELOG.md | 1 + src/cli/commands/run.rs | 2 +- src/cli/mod.rs | 9 +++++++-- src/lib.rs | 15 ++++++++++++++- src/main.rs | 1 + src/source/workspace/mod.rs | 2 +- 6 files changed, 25 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b3c513d..c9cc037 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add improved CLI styling by @daimond113 - Install pesde dependencies before Wally to support scripts packages by @daimond113 - Support packages exporting scripts by @daimond113 +- Support using workspace root as a member by @daimond113 ### Removed - Remove special scripts repo handling to favour standard packages by @daimond113 diff --git a/src/cli/commands/run.rs b/src/cli/commands/run.rs index 615958d..916fe0f 100644 --- a/src/cli/commands/run.rs +++ b/src/cli/commands/run.rs @@ -125,7 +125,7 @@ impl RunCommand { .workspace_dir() .unwrap_or_else(|| project.package_dir()); - let members = match project.workspace_members(workspace_dir).await { + let members = match project.workspace_members(workspace_dir, false).await { Ok(members) => members.boxed(), Err(pesde::errors::WorkspaceMembersError::ManifestMissing(e)) if e.kind() == std::io::ErrorKind::NotFound => diff --git a/src/cli/mod.rs b/src/cli/mod.rs index beeaa7c..636aead 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -248,7 +248,9 @@ pub async fn run_on_workspace_members>>( return Ok(Default::default()); } - let members_future = project.workspace_members(project.package_dir()).await?; + let members_future = project + .workspace_members(project.package_dir(), true) + .await?; pin!(members_future); let mut results = BTreeMap::>::new(); @@ -257,7 +259,10 @@ pub async fn run_on_workspace_members>>( let relative_path = RelativePathBuf::from_path(path.strip_prefix(project.package_dir()).unwrap()).unwrap(); - f(shift_project_dir(project, path)).await?; + // don't run on the current workspace root + if relative_path != "" { + f(shift_project_dir(project, path)).await?; + } results .entry(manifest.name) diff --git a/src/lib.rs b/src/lib.rs index 99ad23e..d9bd14b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -185,6 +185,7 @@ impl Project { pub async fn workspace_members>( &self, dir: P, + can_ref_self: bool, ) -> Result< impl Stream>, errors::WorkspaceMembersError, @@ -201,6 +202,7 @@ impl Project { dir, manifest.workspace_members.iter().map(|s| s.as_str()), false, + can_ref_self, ) .await?; @@ -295,10 +297,13 @@ pub async fn matching_globs<'a, P: AsRef, I: IntoIterator> dir: P, globs: I, relative: bool, + can_ref_self: bool, ) -> Result, errors::MatchingGlobsError> { - let (negative_globs, positive_globs): (Vec<&str>, Vec<&str>) = + let (negative_globs, mut positive_globs): (HashSet<&str>, _) = globs.into_iter().partition(|glob| glob.starts_with('!')); + let include_self = positive_globs.remove(".") && can_ref_self; + let negative_globs = wax::any( negative_globs .into_iter() @@ -315,6 +320,14 @@ pub async fn matching_globs<'a, P: AsRef, I: IntoIterator> let mut read_dirs = vec![fs::read_dir(dir.as_ref().to_path_buf()).await?]; let mut paths = HashSet::new(); + if include_self { + paths.insert(if relative { + PathBuf::new() + } else { + dir.as_ref().to_path_buf() + }); + } + while let Some(mut read_dir) = read_dirs.pop() { while let Some(entry) = read_dir.next_entry().await? { let path = entry.path(); diff --git a/src/main.rs b/src/main.rs index f8eec30..8e67863 100644 --- a/src/main.rs +++ b/src/main.rs @@ -149,6 +149,7 @@ async fn run() -> anyhow::Result<()> { path, manifest.workspace_members.iter().map(|s| s.as_str()), false, + false, ) .await .context("failed to get workspace members") diff --git a/src/source/workspace/mod.rs b/src/source/workspace/mod.rs index 9fbf976..88040c7 100644 --- a/src/source/workspace/mod.rs +++ b/src/source/workspace/mod.rs @@ -49,7 +49,7 @@ impl PackageSource for WorkspacePackageSource { .unwrap_or(&project.package_dir); let target = specifier.target.unwrap_or(project_target); - let members = project.workspace_members(workspace_dir).await?; + let members = project.workspace_members(workspace_dir, true).await?; pin!(members); while let Some((path, manifest)) = members.next().await.transpose()? {