-
Notifications
You must be signed in to change notification settings - Fork 203
Support '*' wildcards in --actions selectors as documented (#2224) #2234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -26,10 +26,33 @@ type actionsWithDependencies = | |||||||||||||
| export const nativeRequire = | ||||||||||||||
| typeof __webpack_require__ === "function" ? __non_webpack_require__ : require; | ||||||||||||||
|
|
||||||||||||||
| // Turn a selector pattern containing '*' wildcards into an anchored RegExp. | ||||||||||||||
| // Every character except '*' is matched literally (regex metacharacters are | ||||||||||||||
| // escaped); each '*' matches any run of characters, so "mrd*" -> /^mrd.*$/ and | ||||||||||||||
| // "*features*" -> /^.*features.*$/. | ||||||||||||||
| function globToRegExp(pattern: string): RegExp { | ||||||||||||||
| const escaped = pattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/\\\*/g, ".*"); | ||||||||||||||
| return new RegExp(`^${escaped}$`); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| export function matchPatterns(patterns: string[], values: string[]) { | ||||||||||||||
| const fullyQualifiedActions: string[] = []; | ||||||||||||||
| patterns.forEach(pattern => { | ||||||||||||||
| if (pattern.includes(".")) { | ||||||||||||||
| if (pattern.includes("*")) { | ||||||||||||||
| // Wildcard selector. A pattern that contains "." matches against the | ||||||||||||||
| // fully-qualified action name; otherwise it matches against the unqualified | ||||||||||||||
| // name (last segment), mirroring the exact-match branches below. Wildcards | ||||||||||||||
| // are expected to select many actions, so no ambiguity error applies here. | ||||||||||||||
| const regExp = globToRegExp(pattern); | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't you first to split by components and then apply regexes?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||
| const scope = pattern.includes(".") | ||||||||||||||
| ? values | ||||||||||||||
| : values.map(value => value.split(".").slice(-1)[0]); | ||||||||||||||
| values.forEach((value, i) => { | ||||||||||||||
| if (regExp.test(scope[i])) { | ||||||||||||||
| fullyQualifiedActions.push(value); | ||||||||||||||
| } | ||||||||||||||
| }); | ||||||||||||||
| } else if (pattern.includes(".")) { | ||||||||||||||
| if (values.includes(pattern)) { | ||||||||||||||
| fullyQualifiedActions.push(pattern); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you simplify this logic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, that was doing too much at once — escaping every metacharacter including
*, thenun-escaping
\*back into.*. You had to read both replaces together to see what it did.Rewritten to split on the wildcards, escape the literal parts, and rejoin:
Behaviour is unchanged — the existing
matchPatternstests pass, and I diffed the twoimplementations exhaustively over patterns covering every regex metacharacter plus
**anda**b.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(note that this change isn't pushed yet, awaiting response)