Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit88434d0

Browse files
authored
Merge pull requestmicrosoft#3300 from dmichon-msft/rush-tags
[rush-lib] Support tags in rush.json and selectors
2 parents6b0f361 +887b3a2 commit88434d0

File tree

12 files changed

+168
-6
lines changed

12 files changed

+168
-6
lines changed

‎apps/rush-lib/assets/rush-init/rush.json‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,13 @@
386386
*/
387387
/*[LINE "HYPOTHETICAL"]*/ "hotfixChangeEnabled": false,
388388

389+
/**
390+
* This is an optional, but recommended, list of available tags that can be applied
391+
* to projects. If this property is not specified, any tag is allowed. This
392+
* list is useful in preventing typos when specifying tags for projects.
393+
*/
394+
/*[LINE "HYPOTHETICAL"]*/ "allowedProjectTags": [ "apps", "Web", "tools" ],
395+
389396
/**
390397
* (Required) This is the inventory of projects to be managed by Rush.
391398
*
@@ -450,19 +457,28 @@
450457
* in "version-policies.json" file. See the "rush publish" documentation for more info.
451458
* NOTE: "versionPolicyName" and "shouldPublish" are alternatives; you cannot specify them both.
452459
*/
453-
/*[LINE "HYPOTHETICAL"]*/ "versionPolicyName": ""
460+
/*[LINE "HYPOTHETICAL"]*/ "versionPolicyName": "",
461+
462+
/**
463+
* An optional set of custom tags that can be used to select this project. For example,
464+
* adding "my-custom-tag" will allow this project to be selected by the
465+
* command "rush list --only tag:my-custom-tag"
466+
*/
467+
/*[LINE "HYPOTHETICAL"]*/ "tags": ["apps", "web"]
454468
},
455469

456470
{
457471
"packageName":"my-controls",
458472
"projectFolder":"libraries/my-controls",
459-
"reviewCategory":"production"
473+
"reviewCategory":"production",
474+
"tags": ["libraries","web"]
460475
},
461476

462477
{
463478
"packageName":"my-toolchain",
464479
"projectFolder":"tools/my-toolchain",
465-
"reviewCategory":"tools"
480+
"reviewCategory":"tools",
481+
"tags": ["tools"]
466482
}
467483
/*[END "DEMO"]*/
468484
]

‎apps/rush-lib/src/api/RushConfiguration.ts‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ export interface IRushConfigurationJson {
246246
approvedPackagesPolicy?:IApprovedPackagesPolicyJson;
247247
gitPolicy?:IRushGitPolicyJson;
248248
telemetryEnabled?:boolean;
249+
allowedProjectTags?:string[];
249250
projects:IRushConfigurationProjectJson[];
250251
eventHooks?:IEventHooksJson;
251252
hotfixChangeEnabled?:boolean;
@@ -494,6 +495,9 @@ export class RushConfiguration {
494495
// Lazily loaded when the projectsByName() getter is called.
495496
private_projectsByName:Map<string,RushConfigurationProject>|undefined;
496497

498+
// Lazily loaded when the projectsByTag() getter is called.
499+
private_projectsByTag:ReadonlyMap<string,ReadonlySet<RushConfigurationProject>>|undefined;
500+
497501
// variant -> common-versions configuration
498502
private_commonVersionsConfigurations:Map<string,CommonVersionsConfiguration>|undefined;
499503
// variant -> map of package name -> implicitly preferred version
@@ -768,6 +772,9 @@ export class RushConfiguration {
768772
a.packageName.localeCompare(b.packageName)
769773
);
770774

775+
constallowedProjectTags:Set<string>|undefined=this._rushConfigurationJson.allowedProjectTags
776+
?newSet(this._rushConfigurationJson.allowedProjectTags)
777+
:undefined;
771778
constusedTempNames:Set<string>=newSet();
772779
for(leti:number=0,len:number=sortedProjectJsons.length;i<len;i++){
773780
constprojectJson:IRushConfigurationProjectJson=sortedProjectJsons[i];
@@ -778,7 +785,8 @@ export class RushConfiguration {
778785
constproject:RushConfigurationProject=newRushConfigurationProject({
779786
projectJson,
780787
rushConfiguration:this,
781-
tempProjectName
788+
tempProjectName,
789+
allowedProjectTags
782790
});
783791

784792
this._projects.push(project);
@@ -1431,6 +1439,27 @@ export class RushConfiguration {
14311439
returnthis._projectsByName!;
14321440
}
14331441

1442+
/**
1443+
* Obtains the mapping from custom tags to projects.
1444+
*@beta
1445+
*/
1446+
publicgetprojectsByTag():ReadonlyMap<string,ReadonlySet<RushConfigurationProject>>{
1447+
if(!this._projectsByTag){
1448+
constprojectsByTag:Map<string,Set<RushConfigurationProject>>=newMap();
1449+
for(constprojectofthis.projects){
1450+
for(consttagofproject.tags){
1451+
letcollection:Set<RushConfigurationProject>|undefined=projectsByTag.get(tag);
1452+
if(!collection){
1453+
projectsByTag.set(tag,(collection=newSet()));
1454+
}
1455+
collection.add(project);
1456+
}
1457+
}
1458+
this._projectsByTag=projectsByTag;
1459+
}
1460+
returnthis._projectsByTag;
1461+
}
1462+
14341463
/**
14351464
* {@inheritDoc NpmOptionsConfiguration}
14361465
*/

‎apps/rush-lib/src/api/RushConfigurationProject.ts‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export interface IRushConfigurationProjectJson {
2424
shouldPublish?:boolean;
2525
skipRushCheck?:boolean;
2626
publishFolder?:string;
27+
tags?:string[];
2728
}
2829

2930
/**
@@ -42,6 +43,10 @@ export interface IRushConfigurationProjectOptions {
4243
* A unique string name for this project
4344
*/
4445
tempProjectName:string;
46+
/**
47+
* If specified, validate project tags against this list.
48+
*/
49+
allowedProjectTags:Set<string>|undefined;
4550
}
4651

4752
/**
@@ -66,14 +71,15 @@ export class RushConfigurationProject {
6671
privatereadonly_skipRushCheck:boolean;
6772
privatereadonly_publishFolder:string;
6873
privatereadonly_rushConfiguration:RushConfiguration;
74+
privatereadonly_tags:Set<string>;
6975

7076
private_versionPolicy:VersionPolicy|undefined=undefined;
7177
private_dependencyProjects:Set<RushConfigurationProject>|undefined=undefined;
7278
private_consumingProjects:Set<RushConfigurationProject>|undefined=undefined;
7379

7480
/**@internal */
7581
publicconstructor(options:IRushConfigurationProjectOptions){
76-
const{ projectJson, rushConfiguration, tempProjectName}=options;
82+
const{ projectJson, rushConfiguration, tempProjectName, allowedProjectTags}=options;
7783
this._rushConfiguration=rushConfiguration;
7884
this._packageName=projectJson.packageName;
7985
this._projectRelativeFolder=projectJson.projectFolder;
@@ -165,6 +171,22 @@ export class RushConfigurationProject {
165171
if(projectJson.publishFolder){
166172
this._publishFolder=path.join(this._publishFolder,projectJson.publishFolder);
167173
}
174+
175+
if(allowedProjectTags&&projectJson.tags){
176+
this._tags=newSet();
177+
for(consttagofprojectJson.tags){
178+
if(!allowedProjectTags.has(tag)){
179+
thrownewError(
180+
`The tag "${tag}" specified for project "${this._packageName}" is not listed in the `+
181+
`allowedProjectTags field in rush.json.`
182+
);
183+
}else{
184+
this._tags.add(tag);
185+
}
186+
}
187+
}else{
188+
this._tags=newSet(projectJson.tags);
189+
}
168190
}
169191

170192
/**
@@ -442,4 +464,12 @@ export class RushConfigurationProject {
442464
}
443465
returnisMain;
444466
}
467+
468+
/**
469+
* The set of tags applied to this project.
470+
*@beta
471+
*/
472+
publicgettags():ReadonlySet<string>{
473+
returnthis._tags;
474+
}
445475
}

‎apps/rush-lib/src/cli/SelectionParameterSet.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
IGitSelectorParserOptions
1919
}from'../logic/selectors/GitChangedProjectSelectorParser';
2020
import{NamedProjectSelectorParser}from'../logic/selectors/NamedProjectSelectorParser';
21+
import{TagProjectSelectorParser}from'../logic/selectors/TagProjectSelectorParser';
2122
import{VersionPolicyProjectSelectorParser}from'../logic/selectors/VersionPolicyProjectSelectorParser';
2223

2324
/**
@@ -53,9 +54,12 @@ export class SelectionParameterSet {
5354
ISelectorParser<RushConfigurationProject>
5455
>();
5556

56-
selectorParsers.set('name',newNamedProjectSelectorParser(rushConfiguration));
57+
constnameSelectorParser:NamedProjectSelectorParser=newNamedProjectSelectorParser(rushConfiguration);
58+
selectorParsers.set('name',nameSelectorParser);
5759
selectorParsers.set('git',newGitChangedProjectSelectorParser(rushConfiguration,gitOptions));
60+
selectorParsers.set('tag',newTagProjectSelectorParser(rushConfiguration));
5861
selectorParsers.set('version-policy',newVersionPolicyProjectSelectorParser(rushConfiguration));
62+
5963
this._selectorParserByScope=selectorParsers;
6064

6165
constgetSpecifierCompletions:()=>Promise<string[]>=async():Promise<string[]>=>{
@@ -66,6 +70,11 @@ export class SelectionParameterSet {
6670
}
6771
}
6872

73+
// Include completions from the name parser without a scope
74+
for(constcompletionofnameSelectorParser.getCompletions()){
75+
completions.push(completion);
76+
}
77+
6978
returncompletions;
7079
};
7180

‎apps/rush-lib/src/logic/selectors/GitChangedProjectSelectorParser.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
2+
// See LICENSE in the project root for license information.
3+
14
importtype{RushConfiguration}from'../../api/RushConfiguration';
25
importtype{RushConfigurationProject}from'../../api/RushConfigurationProject';
36
import{IEvaluateSelectorOptions,ISelectorParser}from'./ISelectorParser';

‎apps/rush-lib/src/logic/selectors/ISelectorParser.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
2+
// See LICENSE in the project root for license information.
3+
14
importtype{ITerminal}from'@rushstack/node-core-library';
25

36
exportinterfaceIEvaluateSelectorOptions{

‎apps/rush-lib/src/logic/selectors/NamedProjectSelectorParser.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
2+
// See LICENSE in the project root for license information.
3+
14
import{AlreadyReportedError,PackageName}from'@rushstack/node-core-library';
25

36
importtype{RushConfiguration}from'../../api/RushConfiguration';
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
2+
// See LICENSE in the project root for license information.
3+
4+
import{AlreadyReportedError}from'@rushstack/node-core-library';
5+
6+
importtype{RushConfiguration}from'../../api/RushConfiguration';
7+
importtype{RushConfigurationProject}from'../../api/RushConfigurationProject';
8+
importtype{IEvaluateSelectorOptions,ISelectorParser}from'./ISelectorParser';
9+
10+
exportclassTagProjectSelectorParserimplementsISelectorParser<RushConfigurationProject>{
11+
privatereadonly_rushConfiguration:RushConfiguration;
12+
13+
publicconstructor(rushConfiguration:RushConfiguration){
14+
this._rushConfiguration=rushConfiguration;
15+
}
16+
17+
publicasyncevaluateSelectorAsync({
18+
unscopedSelector,
19+
terminal,
20+
parameterName
21+
}:IEvaluateSelectorOptions):Promise<Iterable<RushConfigurationProject>>{
22+
constselection:ReadonlySet<RushConfigurationProject>|undefined=
23+
this._rushConfiguration.projectsByTag.get(unscopedSelector);
24+
if(!selection){
25+
terminal.writeErrorLine(
26+
`The tag "${unscopedSelector}" passed to "${parameterName}" is not specified for any projects in rush.json.`
27+
);
28+
thrownewAlreadyReportedError();
29+
}
30+
returnselection;
31+
}
32+
33+
publicgetCompletions():Iterable<string>{
34+
returnthis._rushConfiguration.projectsByTag.keys();
35+
}
36+
}

‎apps/rush-lib/src/logic/selectors/VersionPolicyProjectSelectorParser.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
2+
// See LICENSE in the project root for license information.
3+
14
import{AlreadyReportedError}from'@rushstack/node-core-library';
25

36
importtype{RushConfiguration}from'../../api/RushConfiguration';

‎apps/rush-lib/src/schemas/rush.schema.json‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,14 @@
236236
"description":"Indicates whether telemetry data should be collected and stored in the Rush temp folder during Rush runs.",
237237
"type":"boolean"
238238
},
239+
"allowedProjectTags": {
240+
"description":"This is an optional, but recommended, list of available tags that can be applied to projects. If this property is not specified, any tag is allowed. This list is useful in preventing typos when specifying tags for projects.",
241+
"type":"array",
242+
"items": {
243+
"type":"string",
244+
"pattern":"^[A-Za-z0-9_@/.$-]+$"
245+
}
246+
},
239247
"projects": {
240248
"description":"A list of projects managed by this tool.",
241249
"type":"array",
@@ -276,6 +284,14 @@
276284
"publishFolder": {
277285
"description":"Facilitates postprocessing of a project's files prior to publishing. If specified, the\"publishFolder\" is the relative path to a subfolder of the project folder. The\"rush publish\" command will publish the subfolder instead of the project folder. The subfolder must contain its own package.json file, which is typically a build output.",
278286
"type":"string"
287+
},
288+
"tags": {
289+
"description":"An optional set of custom tags that can be used to select this project. For example, adding\"my-custom-tag\" will allow this project to be selected by the command\"rush list --only tag:my-custom-tag\".",
290+
"type":"array",
291+
"items": {
292+
"type":"string",
293+
"pattern":"^[A-Za-z0-9_@/.$-]+$"
294+
}
279295
}
280296
},
281297
"additionalProperties":false,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp