Skip to content

Commit

Permalink
fix(packageRules/package*): consider packageNames for package* exclud…
Browse files Browse the repository at this point in the history
…es (#27047)
  • Loading branch information
secustor authored Feb 4, 2024
1 parent 12a9022 commit 044f643
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 6 deletions.
13 changes: 13 additions & 0 deletions lib/util/package-rules/package-names.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,17 @@ describe('util/package-rules/package-names', () => {
expect(result).toBeFalse();
});
});

it('should excludePackageName', () => {
const result = packageNameMatcher.excludes(
{
depName: 'abc',
packageName: 'def',
},
{
excludePackageNames: ['def'],
},
);
expect(result).toBeTrue();
});
});
20 changes: 17 additions & 3 deletions lib/util/package-rules/package-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,29 @@ export class PackageNameMatcher extends Matcher {
}

override excludes(
{ depName }: PackageRuleInputConfig,
{ excludePackageNames }: PackageRule,
{ depName, packageName }: PackageRuleInputConfig,
packageRule: PackageRule,
): boolean | null {
const { excludePackageNames } = packageRule;
if (is.undefined(excludePackageNames)) {
return null;
}
if (is.undefined(depName)) {
return false;
}
return excludePackageNames.includes(depName);

if (is.string(packageName) && excludePackageNames.includes(packageName)) {
return true;
}

if (excludePackageNames.includes(depName)) {
logger.once.info(
{ packageRule, packageName, depName },
'Use excludeDepNames instead of excludePackageNames',
);
return true;
}

return false;
}
}
13 changes: 13 additions & 0 deletions lib/util/package-rules/package-prefixes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,18 @@ describe('util/package-rules/package-prefixes', () => {
);
expect(result).toBeFalse();
});

it('should return true if packageName matched', () => {
const result = packagePrefixesMatcher.excludes(
{
depName: 'abc1',
packageName: 'def1',
},
{
excludePackagePrefixes: ['def'],
},
);
expect(result).toBeTrue();
});
});
});
21 changes: 18 additions & 3 deletions lib/util/package-rules/package-prefixes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,31 @@ export class PackagePrefixesMatcher extends Matcher {
}

override excludes(
{ depName }: PackageRuleInputConfig,
{ excludePackagePrefixes }: PackageRule,
{ depName, packageName }: PackageRuleInputConfig,
packageRule: PackageRule,
): boolean | null {
const { excludePackagePrefixes } = packageRule;
if (is.undefined(excludePackagePrefixes)) {
return null;
}
if (is.undefined(depName)) {
return false;
}

return excludePackagePrefixes.some((prefix) => depName.startsWith(prefix));
if (
is.string(packageName) &&
excludePackagePrefixes.some((prefix) => packageName.startsWith(prefix))
) {
return true;
}
if (excludePackagePrefixes.some((prefix) => depName.startsWith(prefix))) {
logger.once.info(
{ packageName, depName },
'Use excludeDepPatterns instead of excludePackagePrefixes',
);
return true;
}

return false;
}
}

0 comments on commit 044f643

Please sign in to comment.