From 94bd1b22767d4a9d2c9ffe5485cc7661c4db606c Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Sun, 30 Jul 2023 22:48:00 -0700 Subject: [PATCH] new: Rework project name/alias querying. (#986) * Update code. * Update changelog. --- nextgen/project-expander/src/tasks_expander.rs | 13 ++++--------- nextgen/project/src/project.rs | 11 ++++++++++- nextgen/query/src/builder.rs | 1 + packages/cli/CHANGELOG.md | 3 +++ website/docs/concepts/query-lang.mdx | 10 +++++++++- 5 files changed, 27 insertions(+), 11 deletions(-) diff --git a/nextgen/project-expander/src/tasks_expander.rs b/nextgen/project-expander/src/tasks_expander.rs index 07dc760e095..e13c6c5cafe 100644 --- a/nextgen/project-expander/src/tasks_expander.rs +++ b/nextgen/project-expander/src/tasks_expander.rs @@ -128,12 +128,9 @@ impl<'graph, 'query> TasksExpander<'graph, 'query> { dep_ids.sort(); let input = if dep_ids.len() == 1 { - format!("project={id} || projectAlias={id}", id = dep_ids[0]) + format!("project={id}", id = dep_ids[0]) } else { - format!( - "project=[{ids}] || projectAlias=[{ids}]", - ids = dep_ids.join(",") - ) + format!("project=[{ids}]", ids = dep_ids.join(",")) }; for dep_project in (self.context.query)(input)? { @@ -158,10 +155,8 @@ impl<'graph, 'query> TasksExpander<'graph, 'query> { check_and_push_dep(project, &dep_target.task_id, false)?; } } else { - let results = (self.context.query)(format!( - "project={id} || projectAlias={id}", - id = project_id - ))?; + let results = + (self.context.query)(format!("project={id}", id = project_id))?; if results.is_empty() { return Err(TasksExpanderError::UnknownTarget { diff --git a/nextgen/project/src/project.rs b/nextgen/project/src/project.rs index 89fe51a6eed..41f7533152d 100644 --- a/nextgen/project/src/project.rs +++ b/nextgen/project/src/project.rs @@ -93,7 +93,15 @@ impl Queryable for Project { Condition::Field { field, .. } => { let result = match field { Field::Language(langs) => condition.matches_enum(langs, &self.language), - Field::Project(ids) => condition.matches(ids, &self.id), + Field::Project(ids) => { + if condition.matches(ids, &self.id)? { + Ok(true) + } else if let Some(alias) = &self.alias { + condition.matches(ids, alias) + } else { + Ok(false) + } + } Field::ProjectAlias(aliases) => { if let Some(alias) = &self.alias { condition.matches(aliases, alias) @@ -101,6 +109,7 @@ impl Queryable for Project { Ok(false) } } + Field::ProjectName(ids) => condition.matches(ids, &self.id), Field::ProjectSource(sources) => { condition.matches(sources, &self.source.to_string()) } diff --git a/nextgen/query/src/builder.rs b/nextgen/query/src/builder.rs index eb823820c48..3a0250aa593 100644 --- a/nextgen/query/src/builder.rs +++ b/nextgen/query/src/builder.rs @@ -10,6 +10,7 @@ pub enum Field { Language(Vec), Project(Vec), ProjectAlias(Vec), + ProjectName(Vec), ProjectSource(Vec), ProjectType(Vec), Tag(Vec), diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index e03c398117d..7a2926d7775 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -23,6 +23,9 @@ - **Codegen** - Templates can be used as-is without rendering with [Tera](https://tera.netlify.app) by appending a `.raw` extension. +- **Query language** + - Updated `project` to query both project name AND alias. + - Added `projectName` for only querying by name #### 🐞 Fixes diff --git a/website/docs/concepts/query-lang.mdx b/website/docs/concepts/query-lang.mdx index 7785dc0cc74..71f608103fd 100644 --- a/website/docs/concepts/query-lang.mdx +++ b/website/docs/concepts/query-lang.mdx @@ -88,7 +88,7 @@ language=rust ### `project` -ID/name of the project, as defined in [`.moon/workspace.yml`](../config/workspace). +Name OR alias of the project. ``` project=server @@ -102,6 +102,14 @@ Alias of the project. For example, the `package.json` name. projectAlias~@scope/* ``` +### `projectName` + +Name of the project, as defined in [`.moon/workspace.yml`](../config/workspace). + +``` +project=server +``` + ### `projectSource` Relative file path from the workspace root to the project root, as defined in