Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: matchPackagePrefixes include packageName #23186

Merged
merged 2 commits into from Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/usage/configuration-options.md
Expand Up @@ -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:
Expand Down
26 changes: 26 additions & 0 deletions lib/util/package-rules/package-prefixes.spec.ts
Expand Up @@ -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', () => {
Expand Down
20 changes: 18 additions & 2 deletions 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(
Expand Down