From d92eabfd138d681c44e3ee1e39dab3b7fea08399 Mon Sep 17 00:00:00 2001 From: qun Date: Wed, 17 Jul 2024 08:20:28 +0000 Subject: [PATCH 1/3] feat: Support exemption of a project when executing the restrict-versions check --- .../src/cli/lint/actions/CheckAction.ts | 30 +++++++++++++------ .../src/schemas/lockfile-lint.schema.json | 4 +++ .../fix-lfx_2024-07-17-08-11.json | 10 +++++++ 3 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 common/changes/@rushstack/lockfile-explorer/fix-lfx_2024-07-17-08-11.json diff --git a/apps/lockfile-explorer/src/cli/lint/actions/CheckAction.ts b/apps/lockfile-explorer/src/cli/lint/actions/CheckAction.ts index e63bec03e7d..b95b734e741 100644 --- a/apps/lockfile-explorer/src/cli/lint/actions/CheckAction.ts +++ b/apps/lockfile-explorer/src/cli/lint/actions/CheckAction.ts @@ -23,6 +23,7 @@ export interface ILintRule { rule: 'restrict-versions'; project: string; requiredVersions: Record; + exemptProjectList: string[]; } export interface ILockfileLint { @@ -96,7 +97,8 @@ export class CheckAction extends CommandLineAction { private async _searchAndValidateDependenciesAsync( project: RushConfigurationProject, - requiredVersions: Record + requiredVersions: Record, + exemptProjectList: string[] ): Promise { this._terminal.writeLine(`Checking project "${project.packageName}"`); @@ -116,9 +118,9 @@ export class CheckAction extends CommandLineAction { const checkedDependencyPaths: Set = new Set(); 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, @@ -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( @@ -156,7 +166,8 @@ export class CheckAction extends CommandLineAction { private async _performVersionRestrictionCheckAsync( requiredVersions: Record, - projectName: string + projectName: string, + exemptProjectList: string[] ): Promise { try { const project: RushConfigurationProject | undefined = @@ -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; @@ -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 }); diff --git a/apps/lockfile-explorer/src/schemas/lockfile-lint.schema.json b/apps/lockfile-explorer/src/schemas/lockfile-lint.schema.json index 0e383a91bd1..c1c77ce9c16 100644 --- a/apps/lockfile-explorer/src/schemas/lockfile-lint.schema.json +++ b/apps/lockfile-explorer/src/schemas/lockfile-lint.schema.json @@ -27,6 +27,10 @@ "description": "Project name.", "type": "string" }, + "exemptProject": { + "description": "A project that you would like to exempt.", + "type": "string" + }, "requiredVersions": { "description": "List of restrict dependency version.", "type": "object", diff --git a/common/changes/@rushstack/lockfile-explorer/fix-lfx_2024-07-17-08-11.json b/common/changes/@rushstack/lockfile-explorer/fix-lfx_2024-07-17-08-11.json new file mode 100644 index 00000000000..0f3cf2f34f8 --- /dev/null +++ b/common/changes/@rushstack/lockfile-explorer/fix-lfx_2024-07-17-08-11.json @@ -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" +} \ No newline at end of file From fed63b4d8a96df705f11882ff9fb1ee9bdeca958 Mon Sep 17 00:00:00 2001 From: qun Date: Wed, 17 Jul 2024 08:33:33 +0000 Subject: [PATCH 2/3] fix: schema --- apps/lockfile-explorer/src/schemas/lockfile-lint.schema.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/lockfile-explorer/src/schemas/lockfile-lint.schema.json b/apps/lockfile-explorer/src/schemas/lockfile-lint.schema.json index c1c77ce9c16..34eeac0223b 100644 --- a/apps/lockfile-explorer/src/schemas/lockfile-lint.schema.json +++ b/apps/lockfile-explorer/src/schemas/lockfile-lint.schema.json @@ -27,8 +27,8 @@ "description": "Project name.", "type": "string" }, - "exemptProject": { - "description": "A project that you would like to exempt.", + "exemptProjectList": { + "description": "Projects that you would like to exempt.", "type": "string" }, "requiredVersions": { From 5dced4c96855ef49465f14a4d1b02b6113cf88b1 Mon Sep 17 00:00:00 2001 From: qun Date: Wed, 17 Jul 2024 08:46:21 +0000 Subject: [PATCH 3/3] feat: Support exemption of a project when executing the restrict-versions check --- apps/lockfile-explorer/src/cli/lint/actions/CheckAction.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/lockfile-explorer/src/cli/lint/actions/CheckAction.ts b/apps/lockfile-explorer/src/cli/lint/actions/CheckAction.ts index b95b734e741..8ef80dd0674 100644 --- a/apps/lockfile-explorer/src/cli/lint/actions/CheckAction.ts +++ b/apps/lockfile-explorer/src/cli/lint/actions/CheckAction.ts @@ -23,7 +23,7 @@ export interface ILintRule { rule: 'restrict-versions'; project: string; requiredVersions: Record; - exemptProjectList: string[]; + exemptProjectList?: string[]; } export interface ILockfileLint { @@ -213,7 +213,7 @@ export class CheckAction extends CommandLineAction { const message: string | undefined = await this._performVersionRestrictionCheckAsync( requiredVersions, project, - exemptProjectList + exemptProjectList ?? [] ); if (message) { issues.push({ project, rule, message });