8000 Add an allowedProjectTags field to rush.json. · psy-repos-typescript/rushstack@887b3a2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 887b3a2

Browse files
committed
Add an allowedProjectTags field to rush.json.
1 parent 636b4e4 commit 887b3a2

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

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

Lines changed: 7 additions & 0 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
*

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

Lines changed: 6 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;
@@ -771,6 +772,9 @@ export class RushConfiguration {
771772
a.packageName.localeCompare(b.packageName)
772773
);
773774

775+
const allowedProjectTags: Set<string> | undefined = this._rushConfigurationJson.allowedProjectTags
776+
? new Set(this._rushConfigurationJson.allowedProjectTags)
777+
: undefined;
774778
const usedTempNames: Set<string> = new Set();
775779
for (let i: number = 0, len: number = sortedProjectJsons.length; i < len; i++) {
776780
const projectJson: IRushConfigurationProjectJson = sortedProjectJsons[i];
@@ -781,7 +785,8 @@ export class RushConfiguration {
781785
const project: RushConfigurationProject = new RushConfigurationProject({
782786
projectJson,
783787
rushConfiguration: this,
784-
tempProjectName
788+
tempProjectName,
789+
allowedProjectTags
785790
});
786791

787792
this._projects.push(project);

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ export interface IRushConfigurationProjectOptions {
4343
* A unique string name for this project
4444
*/
4545
tempProjectName: string;
46+
/**
47+
* If specified, validate project tags against this list.
48+
*/
49+
allowedProjectTags: Set<string> | undefined;
4650
}
4751

4852
/**
@@ -75,7 +79,7 @@ export class RushConfigurationProject {
7579

7680
/** @internal */
7781
public constructor(options: IRushConfigurationProjectOptions) {
78-
const { projectJson, rushConfiguration, tempProjectName } = options;
82+
const { projectJson, rushConfiguration, tempProjectName, allowedProjectTags } = options;
7983
this._rushConfiguration = rushConfiguration;
8084
this._packageName = projectJson.packageName;
8185
this._projectRelativeFolder = projectJson.projectFolder;
@@ -168,7 +172,21 @@ export class RushConfigurationProject {
168172
this._publishFolder = path.join(this._publishFolder, projectJson.publishFolder);
169173
}
170174

171-
this._tags = new Set(projectJson.tags);
175+
if (allowedProjectTags && projectJson.tags) {
176+
this._tags = new Set();
177+
for (const tag of projectJson.tags) {
178+
if (!allowedProjectTags.has(tag)) {
179+
throw new Error(
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 = new Set(projectJson.tags);
189+
}
172190
}
173191

174192
/**

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

Lines changed: 8 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",

0 commit comments

Comments
 (0)
0