Skip to content
Snippets Groups Projects
Unverified Commit 7db49b39 authored by Rhys Arkins's avatar Rhys Arkins Committed by GitHub
Browse files

feat: matchPackagePrefixes include packageName (#23186)

parent c89eeb89
No related merge requests found
...@@ -2288,6 +2288,9 @@ See also `excludePackagePrefixes`. ...@@ -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`. 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 ### matchSourceUrlPrefixes
Here's an example of where you use this to group together all packages from the `renovatebot` GitHub org: Here's an example of where you use this to group together all packages from the `renovatebot` GitHub org:
......
...@@ -15,6 +15,32 @@ describe('util/package-rules/package-prefixes', () => { ...@@ -15,6 +15,32 @@ describe('util/package-rules/package-prefixes', () => {
); );
expect(result).toBeFalse(); 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', () => { describe('exclude', () => {
......
import is from '@sindresorhus/is'; import is from '@sindresorhus/is';
import type { PackageRule, PackageRuleInputConfig } from '../../config/types'; import type { PackageRule, PackageRuleInputConfig } from '../../config/types';
import { logger } from '../../logger';
import { Matcher } from './base'; import { Matcher } from './base';
export class PackagePrefixesMatcher extends Matcher { export class PackagePrefixesMatcher extends Matcher {
override matches( override matches(
{ depName }: PackageRuleInputConfig, { depName, packageName }: PackageRuleInputConfig,
{ matchPackagePrefixes }: PackageRule { matchPackagePrefixes }: PackageRule
): boolean | null { ): boolean | null {
if (is.undefined(matchPackagePrefixes)) { if (is.undefined(matchPackagePrefixes)) {
return null; return null;
} }
if (is.undefined(depName)) { if (is.undefined(depName)) {
return false; 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( override excludes(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment