diff --git a/lib/util/package-rules/package-names.spec.ts b/lib/util/package-rules/package-names.spec.ts index 83552a798f915f..f33b00c7e117d2 100644 --- a/lib/util/package-rules/package-names.spec.ts +++ b/lib/util/package-rules/package-names.spec.ts @@ -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(); + }); }); diff --git a/lib/util/package-rules/package-names.ts b/lib/util/package-rules/package-names.ts index a6476d2877cd55..7af49f4beb979b 100644 --- a/lib/util/package-rules/package-names.ts +++ b/lib/util/package-rules/package-names.ts @@ -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; } } diff --git a/lib/util/package-rules/package-prefixes.spec.ts b/lib/util/package-rules/package-prefixes.spec.ts index 424a5f84421fea..b68aa0a65cfdcc 100644 --- a/lib/util/package-rules/package-prefixes.spec.ts +++ b/lib/util/package-rules/package-prefixes.spec.ts @@ -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(); + }); }); }); diff --git a/lib/util/package-rules/package-prefixes.ts b/lib/util/package-rules/package-prefixes.ts index 74eb59c7f4d7e7..bb9b015b2ecaf4 100644 --- a/lib/util/package-rules/package-prefixes.ts +++ b/lib/util/package-rules/package-prefixes.ts @@ -34,9 +34,10 @@ 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; } @@ -44,6 +45,20 @@ export class PackagePrefixesMatcher extends Matcher { 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; } }