From d3d87687e2ec0f701ecbe4a7d2d7bdab7cc1d221 Mon Sep 17 00:00:00 2001 From: secustor Date: Sun, 4 Feb 2024 11:12:37 +0100 Subject: [PATCH] fix(packageRules/package-patterns): consider depName for exclude --- .../package-rules/package-patterns.spec.ts | 15 ++++++++++ lib/util/package-rules/package-patterns.ts | 28 ++++++++++++------- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/lib/util/package-rules/package-patterns.spec.ts b/lib/util/package-rules/package-patterns.spec.ts index 467191ae45f35f..fcb614a2d21858 100644 --- a/lib/util/package-rules/package-patterns.spec.ts +++ b/lib/util/package-rules/package-patterns.spec.ts @@ -42,4 +42,19 @@ describe('util/package-rules/package-patterns', () => { expect(result).toBeTrue(); }); }); + + describe('exclude', () => { + it('should exclude packageName', () => { + const result = packageNameMatcher.excludes( + { + depName: 'abc', + packageName: 'def', + }, + { + excludePackagePatterns: ['def'], + }, + ); + expect(result).toBeTrue(); + }); + }); }); diff --git a/lib/util/package-rules/package-patterns.ts b/lib/util/package-rules/package-patterns.ts index 1823d9c888b589..bc4f4029ed788b 100644 --- a/lib/util/package-rules/package-patterns.ts +++ b/lib/util/package-rules/package-patterns.ts @@ -50,9 +50,10 @@ export class PackagePatternsMatcher extends Matcher { } override excludes( - { depName }: PackageRuleInputConfig, - { excludePackagePatterns }: PackageRule, + { depName, packageName }: PackageRuleInputConfig, + packageRule: PackageRule, ): boolean | null { + const { excludePackagePatterns } = packageRule; // ignore lockFileMaintenance for backwards compatibility if (is.undefined(excludePackagePatterns)) { return null; @@ -61,15 +62,22 @@ export class PackagePatternsMatcher extends Matcher { return false; } - let isMatch = false; - for (const pattern of excludePackagePatterns) { - const packageRegex = regEx(massagePattern(pattern)); - if (packageRegex.test(depName)) { - logger.trace(`${depName} matches against ${String(packageRegex)}`); - isMatch = true; - } + if ( + is.string(packageName) && + matchPatternsAgainstName(excludePackagePatterns, packageName) + ) { + return true; + } + + if (matchPatternsAgainstName(excludePackagePatterns, depName)) { + logger.once.info( + { packageRule, packageName, depName }, + 'Use excludeDepPatterns instead of excludePackagePatterns', + ); + return true; } - return isMatch; + + return false; } }