Skip to content

[rush-lib] Support access parameter for each project configuration #5100

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft/rush",
"comment": "provides access parameter to restrict packages to be installed",
"type": "none"
}
],
"packageName": "@microsoft/rush"
}
3 changes: 3 additions & 0 deletions common/reviews/api/rush-lib.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,8 @@ export class RushConfigurationProject {
//
// @internal
constructor(options: IRushConfigurationProjectOptions);
// Warning: (ae-forgotten-export) The symbol "PackageAccessType" needs to be exported by the entry point index.d.ts
readonly access: PackageAccessType;
// @beta
readonly configuredSubspaceName: string | undefined;
get consumingProjects(): ReadonlySet<RushConfigurationProject>;
Expand Down Expand Up @@ -1335,6 +1337,7 @@ export class RushConfigurationProject {
readonly tags: ReadonlySet<string>;
readonly tempProjectName: string;
readonly unscopedTempProjectName: string;
validateAccess(): void;
// @beta
get versionPolicy(): VersionPolicy | undefined;
// @beta
Expand Down
5 changes: 4 additions & 1 deletion libraries/rush-lib/src/api/RushConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -960,8 +960,11 @@ export class RushConfiguration {
allowedProjectTags,
subspace
});
subspace._addProject(project);

// Validates project according to its access restrictions
project.validateAccess();

subspace._addProject(project);
this._projects.push(project);
if (this._projectsByName.has(project.packageName)) {
throw new Error(
Expand Down
47 changes: 46 additions & 1 deletion libraries/rush-lib/src/api/RushConfigurationProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ export interface IRushConfigurationProjectJson {
publishFolder?: string;
tags?: string[];
subspaceName?: string;
access?: PackageAccessType;
}

/**
* The type of package access restrictions
*/
export enum PackageAccessType {
Private = 'private',
Protected = 'protected',
Public = 'public'
}

/**
Expand Down Expand Up @@ -206,13 +216,23 @@ export class RushConfigurationProject {
*/
public readonly configuredSubspaceName: string | undefined;

/**
* Access restrictions
*/
public readonly access: PackageAccessType;

/** @internal */
public constructor(options: IRushConfigurationProjectOptions) {
const { projectJson, rushConfiguration, tempProjectName, allowedProjectTags } = options;
const { packageName, projectFolder: projectRelativeFolder } = projectJson;
const {
packageName,
projectFolder: projectRelativeFolder,
access = PackageAccessType.Public
} = projectJson;
this.rushConfiguration = rushConfiguration;
this.packageName = packageName;
this.projectRelativeFolder = projectRelativeFolder;
this.access = access;

validateRelativePathField(projectRelativeFolder, 'projectFolder', rushConfiguration.rushJsonFile);

Expand Down Expand Up @@ -514,6 +534,31 @@ export class RushConfigurationProject {
}
return isMain;
}

/**
* Validates if this project can access its local dependencies.
*
*/
public validateAccess(): void {
const invalidDeps: string[] = [];
for (const project of this.dependencyProjects) {
if (project.access === PackageAccessType.Public) {
continue;
} else if (project.access === PackageAccessType.Private) {
invalidDeps.push(project.packageName);
} else if (this.subspace.subspaceName !== project.subspace.subspaceName) {
invalidDeps.push(project.packageName);
}
}

if (invalidDeps.length > 0) {
throw new Error(
`${this.packageName} doesn't have permissions to access ${invalidDeps.join(
', '
)}.\nPlease remove this dependency or update the ${RushConstants.rushJsonFilename} access rights.`
);
}
}
}

export function validateRelativePathField(relativePath: string, field: string, file: string): void {
Expand Down
6 changes: 6 additions & 0 deletions libraries/rush-lib/src/schemas/rush.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,12 @@
"subspaceName": {
"description": "(EXPERIMENTAL) An optional entry for specifying which subspace this project belongs to if the subspaces feature is enabled.",
"type": "string"
},
"access": {
"description": "Restricts the project to be accessed by others. There are three possible values:\n\n\"public\" - any package can install this project.\n\"protected\" - only packages from the same subspace can install this project.\n\"private\" - no packages can install this project.\n\nThe default value is \"public\".",
"enum": ["public", "private", "protected"],
"type": "string",
"default": "public"
}
},
"additionalProperties": false,
Expand Down
Loading