[rush] Initial SelectorExpressionParser implementation #4250
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR is related to #3327 (but maybe doesn't close it).
Details
Introduction
Today, we select projects with a command like
rush build --to rush-lib --from tag:App
.name:
andtag:
.to
andfrom
.The idea behind selector expressions is to combine these selectors, filters, and operators in a more formal way that allows more complex selection sets.
Selector Expression JSON
The JSON for expressions come in small blocks, 3 flavors, one for each type above:
{ scope: 'git', value: 'origin/main' }
is a selector, the equivalent ofgit:origin/main
{ filter: 'to', arg: <expr> }
is a filter which operates on sub-expression, the equivalent of--to
{ op: 'and', args: [<expr>, <expr>] }
is an operator, which takes one or more sub-expression operands (args)We can now express a concept like "the set of all projects impacted by project XYZ and tagged
sdk
", like so:This JSON syntax could be generated on the fly and passed in via a file param, or it could even be used for more permanent arrangements, such as saved in Rush configuration files to filter certain future features by project in a configurable way.
Selector Expression Strings
For ad-hoc project selection on the command line, it would be convenient to express the JSON structure above in a standardized string format as well. This PR proposes a simple parser for such a string, with the following rules:
[and]
.Thus, the JSON expression in the section above would be expressed as
to XYZ and tag:sdk
. On the command line:API Layer
Because the new objects are built at API layer, they should be equally usable outside of the Rush CLI context, e.g.:
Future extensions
@dmichon-msft originally suggested that the concept of "selector expressions" could be a plugin for the selector types (essentially making it a complex selector type). I am proposing a different approach, which would be instead to make the concept of a selector expression a core feature of Rush, that is not extendable -- for example, there is no way to introduce new core keywords like "and".
However, future Rush plugin types could introduce new selector scopes (e.g. "tag"). Or, they could introduce new selector filters (e.g. "to"). The implementation proposed in this PR would support new scopes and filters, but not new operators or changes to the JSON syntax overall.
How it was tested
A few unit tests added for documentation.
Impacted documentation
--select
parameter