feat: support using workspace root as a member

This commit is contained in:
daimond113 2024-12-08 12:15:30 +01:00
parent e30ec8a6cf
commit 0fa17a839f
No known key found for this signature in database
GPG key ID: 3A8ECE51328B513C
6 changed files with 25 additions and 5 deletions

View file

@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add improved CLI styling by @daimond113 - Add improved CLI styling by @daimond113
- Install pesde dependencies before Wally to support scripts packages by @daimond113 - Install pesde dependencies before Wally to support scripts packages by @daimond113
- Support packages exporting scripts by @daimond113 - Support packages exporting scripts by @daimond113
- Support using workspace root as a member by @daimond113
### Removed ### Removed
- Remove special scripts repo handling to favour standard packages by @daimond113 - Remove special scripts repo handling to favour standard packages by @daimond113

View file

@ -125,7 +125,7 @@ impl RunCommand {
.workspace_dir() .workspace_dir()
.unwrap_or_else(|| project.package_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(), Ok(members) => members.boxed(),
Err(pesde::errors::WorkspaceMembersError::ManifestMissing(e)) Err(pesde::errors::WorkspaceMembersError::ManifestMissing(e))
if e.kind() == std::io::ErrorKind::NotFound => if e.kind() == std::io::ErrorKind::NotFound =>

View file

@ -248,7 +248,9 @@ pub async fn run_on_workspace_members<F: Future<Output = anyhow::Result<()>>>(
return Ok(Default::default()); 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); pin!(members_future);
let mut results = BTreeMap::<PackageName, BTreeMap<TargetKind, RelativePathBuf>>::new(); let mut results = BTreeMap::<PackageName, BTreeMap<TargetKind, RelativePathBuf>>::new();
@ -257,7 +259,10 @@ pub async fn run_on_workspace_members<F: Future<Output = anyhow::Result<()>>>(
let relative_path = let relative_path =
RelativePathBuf::from_path(path.strip_prefix(project.package_dir()).unwrap()).unwrap(); RelativePathBuf::from_path(path.strip_prefix(project.package_dir()).unwrap()).unwrap();
// don't run on the current workspace root
if relative_path != "" {
f(shift_project_dir(project, path)).await?; f(shift_project_dir(project, path)).await?;
}
results results
.entry(manifest.name) .entry(manifest.name)

View file

@ -185,6 +185,7 @@ impl Project {
pub async fn workspace_members<P: AsRef<Path>>( pub async fn workspace_members<P: AsRef<Path>>(
&self, &self,
dir: P, dir: P,
can_ref_self: bool,
) -> Result< ) -> Result<
impl Stream<Item = Result<(PathBuf, Manifest), errors::WorkspaceMembersError>>, impl Stream<Item = Result<(PathBuf, Manifest), errors::WorkspaceMembersError>>,
errors::WorkspaceMembersError, errors::WorkspaceMembersError,
@ -201,6 +202,7 @@ impl Project {
dir, dir,
manifest.workspace_members.iter().map(|s| s.as_str()), manifest.workspace_members.iter().map(|s| s.as_str()),
false, false,
can_ref_self,
) )
.await?; .await?;
@ -295,10 +297,13 @@ pub async fn matching_globs<'a, P: AsRef<Path>, I: IntoIterator<Item = &'a str>>
dir: P, dir: P,
globs: I, globs: I,
relative: bool, relative: bool,
can_ref_self: bool,
) -> Result<HashSet<PathBuf>, errors::MatchingGlobsError> { ) -> Result<HashSet<PathBuf>, 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('!')); globs.into_iter().partition(|glob| glob.starts_with('!'));
let include_self = positive_globs.remove(".") && can_ref_self;
let negative_globs = wax::any( let negative_globs = wax::any(
negative_globs negative_globs
.into_iter() .into_iter()
@ -315,6 +320,14 @@ pub async fn matching_globs<'a, P: AsRef<Path>, I: IntoIterator<Item = &'a str>>
let mut read_dirs = vec![fs::read_dir(dir.as_ref().to_path_buf()).await?]; let mut read_dirs = vec![fs::read_dir(dir.as_ref().to_path_buf()).await?];
let mut paths = HashSet::new(); 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(mut read_dir) = read_dirs.pop() {
while let Some(entry) = read_dir.next_entry().await? { while let Some(entry) = read_dir.next_entry().await? {
let path = entry.path(); let path = entry.path();

View file

@ -149,6 +149,7 @@ async fn run() -> anyhow::Result<()> {
path, path,
manifest.workspace_members.iter().map(|s| s.as_str()), manifest.workspace_members.iter().map(|s| s.as_str()),
false, false,
false,
) )
.await .await
.context("failed to get workspace members") .context("failed to get workspace members")

View file

@ -49,7 +49,7 @@ impl PackageSource for WorkspacePackageSource {
.unwrap_or(&project.package_dir); .unwrap_or(&project.package_dir);
let target = specifier.target.unwrap_or(project_target); 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); pin!(members);
while let Some((path, manifest)) = members.next().await.transpose()? { while let Some((path, manifest)) = members.next().await.transpose()? {