diff --git a/docs/usage/configuration-options.md b/docs/usage/configuration-options.md index 18d9aa4cfcc51e2fd06c1001dbb1b9306fa81125..5e4077e9d60b86ae6b86ae157126b7f6793e81ed 100644 --- a/docs/usage/configuration-options.md +++ b/docs/usage/configuration-options.md @@ -2288,6 +2288,9 @@ See also `excludePackagePrefixes`. Like the earlier `matchPackagePatterns` example, the above will configure `rangeStrategy` to `replace` for any package starting with `angular`. +`matchPackagePrefixes` will match against `packageName` first, and then `depName`, however `depName` matching is deprecated and will be removed in a future major release. +If matching against `depName`, use `matchDepPatterns` instead. + ### matchSourceUrlPrefixes Here's an example of where you use this to group together all packages from the `renovatebot` GitHub org: diff --git a/lib/util/package-rules/package-prefixes.spec.ts b/lib/util/package-rules/package-prefixes.spec.ts index a5640d5e643c954e85f510415984bc05b4f35742..cd0cd5f2944f68cc856728bb0faefee414734889 100644 --- a/lib/util/package-rules/package-prefixes.spec.ts +++ b/lib/util/package-rules/package-prefixes.spec.ts @@ -15,6 +15,32 @@ describe('util/package-rules/package-prefixes', () => { ); expect(result).toBeFalse(); }); + + it('should return true if packageName matched', () => { + const result = packagePrefixesMatcher.matches( + { + depName: 'abc1', + packageName: 'def1', + }, + { + matchPackagePrefixes: ['def'], + } + ); + expect(result).toBeTrue(); + }); + + it('should return true but warn if depName matched', () => { + const result = packagePrefixesMatcher.matches( + { + depName: 'abc1', + packageName: 'def1', + }, + { + matchPackagePrefixes: ['abc'], + } + ); + expect(result).toBeTrue(); + }); }); describe('exclude', () => { diff --git a/lib/util/package-rules/package-prefixes.ts b/lib/util/package-rules/package-prefixes.ts index 2df3ce7daf36ba8de5a99a73f9d098d7729f7e50..0c1955d6f3e65e78a05ebd645b7cb73160f98a23 100644 --- a/lib/util/package-rules/package-prefixes.ts +++ b/lib/util/package-rules/package-prefixes.ts @@ -1,20 +1,36 @@ import is from '@sindresorhus/is'; import type { PackageRule, PackageRuleInputConfig } from '../../config/types'; +import { logger } from '../../logger'; import { Matcher } from './base'; export class PackagePrefixesMatcher extends Matcher { override matches( - { depName }: PackageRuleInputConfig, + { depName, packageName }: PackageRuleInputConfig, { matchPackagePrefixes }: PackageRule ): boolean | null { if (is.undefined(matchPackagePrefixes)) { return null; } + if (is.undefined(depName)) { return false; } - return matchPackagePrefixes.some((prefix) => depName.startsWith(prefix)); + if ( + is.string(packageName) && + matchPackagePrefixes.some((prefix) => packageName.startsWith(prefix)) + ) { + return true; + } + if (matchPackagePrefixes.some((prefix) => depName.startsWith(prefix))) { + logger.once.warn( + { packageName, depName }, + 'Use matchDepPatterns instead of matchPackagePrefixes' + ); + return true; + } + + return false; } override excludes(