diff --git a/apps/lockfile-explorer/src/cli/lint/actions/CheckAction.ts b/apps/lockfile-explorer/src/cli/lint/actions/CheckAction.ts index e63bec03e7d..8ef80dd0674 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..34eeac0223b 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" }, + "exemptProjectList": { + "description": "Projects 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