Skip to content

Commit

Permalink
feat: Support exemption of a project when executing the restrict-vers…
Browse files Browse the repository at this point in the history
…ions check
  • Loading branch information
L-Qun committed Jul 17, 2024
1 parent 08cd264 commit d92eabf
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
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
4 changes: 4 additions & 0 deletions apps/lockfile-explorer/src/schemas/lockfile-lint.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
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"
}

0 comments on commit d92eabf

Please sign in to comment.