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

fix(packageRules/package*): consider packageNames for package* excludes #27047

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/util/package-rules/package-names.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
20 changes: 17 additions & 3 deletions lib/util/package-rules/package-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
13 changes: 13 additions & 0 deletions lib/util/package-rules/package-prefixes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});
21 changes: 18 additions & 3 deletions lib/util/package-rules/package-prefixes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,31 @@ 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;
}
if (is.undefined(depName)) {
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',
secustor marked this conversation as resolved.
Show resolved Hide resolved
);
return true;
}

return false;
}
}
Loading