Skip to content
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

[lockfile-explorer] Support exemption of a project when executing the restrict-vers… #4837

Open
wants to merge 3 commits 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
30 changes: 21 additions & 9 deletions apps/lockfile-explorer/src/cli/lint/actions/CheckAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface ILintRule {
rule: 'restrict-versions';
project: string;
requiredVersions: Record<string, string>;
exemptProjectList?: string[];
}

export interface ILockfileLint {
Expand Down Expand Up @@ -96,7 +97,8 @@ export class CheckAction extends CommandLineAction {

private async _searchAndValidateDependenciesAsync(
project: RushConfigurationProject,
requiredVersions: Record<string, string>
requiredVersions: Record<string, string>,
exemptProjectList: string[]
): Promise<void> {
this._terminal.writeLine(`Checking project "${project.packageName}"`);

Expand All @@ -116,9 +118,9 @@ export class CheckAction extends CommandLineAction {
const checkedDependencyPaths: Set<string> = new Set<string>();

await Promise.all(
Object.entries(importers).map(async ([relativePath, { dependencies }]) => {
Object.entries(importers).map(async ([relativePath, { dependencies, devDependencies }]) => {
if (path.resolve(projectFolder, relativePath) === projectFolder) {
const dependenciesEntries = Object.entries(dependencies ?? {});
const dependenciesEntries = Object.entries({ ...dependencies, ...devDependencies } ?? {});
for (const [dependencyName, dependencyValue] of dependenciesEntries) {
const fullDependencyPath = splicePackageWithVersion(
shrinkwrapFileMajorVersion,
Expand All @@ -135,9 +137,17 @@ export class CheckAction extends CommandLineAction {
if (fullDependencyPath.includes('link:')) {
const dependencyProject: RushConfigurationProject | undefined =
this._rushConfiguration.getProjectByName(dependencyName);
if (dependencyProject && !this._checkedProjects?.has(dependencyProject)) {
if (
dependencyProject &&
!this._checkedProjects?.has(dependencyProject) &&
!exemptProjectList.includes(dependencyName)
) {
this._checkedProjects!.add(project);
await this._searchAndValidateDependenciesAsync(dependencyProject, requiredVersions);
await this._searchAndValidateDependenciesAsync(
dependencyProject,
requiredVersions,
exemptProjectList
);
}
} else {
await this._checkVersionCompatibilityAsync(
Expand All @@ -156,7 +166,8 @@ export class CheckAction extends CommandLineAction {

private async _performVersionRestrictionCheckAsync(
requiredVersions: Record<string, string>,
projectName: string
projectName: string,
exemptProjectList: string[]
): Promise<string | undefined> {
try {
const project: RushConfigurationProject | undefined =
Expand All @@ -167,7 +178,7 @@ export class CheckAction extends CommandLineAction {
);
}
this._checkedProjects.add(project);
await this._searchAndValidateDependenciesAsync(project, requiredVersions);
await this._searchAndValidateDependenciesAsync(project, requiredVersions, exemptProjectList);
return undefined;
} catch (e) {
return e.message;
Expand Down Expand Up @@ -196,12 +207,13 @@ export class CheckAction extends CommandLineAction {
const issues: ILintIssue[] = [];
await Async.forEachAsync(
rules,
async ({ requiredVersions, project, rule }) => {
async ({ requiredVersions, project, rule, exemptProjectList }) => {
switch (rule) {
case 'restrict-versions': {
const message: string | undefined = await this._performVersionRestrictionCheckAsync(
requiredVersions,
project
project,
exemptProjectList ?? []
);
if (message) {
issues.push({ project, rule, message });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
"description": "Project name.",
"type": "string"
},
"exemptProjectList": {
"description": "Projects that you would like to exempt.",
"type": "string"
},
"requiredVersions": {
"description": "List of restrict dependency version.",
"type": "object",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@rushstack/lockfile-explorer",
"comment": "Support exemption of a project when executing the restrict-versions check.",
"type": "patch"
}
],
"packageName": "@rushstack/lockfile-explorer"
}
Loading