mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-13 07:26:26 +00:00
feat: implement custom.<customMgrName>
syntax for matchManagers
(#24112)
This commit is contained in:
parent
b2c6cbe0c8
commit
9c322cdcee
6 changed files with 63 additions and 2 deletions
|
@ -0,0 +1,26 @@
|
||||||
|
import { MatchManagersMigration } from './match-managers-migration';
|
||||||
|
|
||||||
|
describe('config/migrations/custom/match-managers-migration', () => {
|
||||||
|
it('migrates old custom manager syntax to new one', () => {
|
||||||
|
expect(MatchManagersMigration).toMigrate(
|
||||||
|
{
|
||||||
|
matchManagers: ['npm', 'regex', 'custom.someMgr'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
matchManagers: ['npm', 'custom.regex', 'custom.someMgr'],
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
// coverage
|
||||||
|
it('only migrates when necessary', () => {
|
||||||
|
expect(MatchManagersMigration).not.toMigrate(
|
||||||
|
{
|
||||||
|
matchManagers: undefined,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
matchManagers: undefined,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
18
lib/config/migrations/custom/match-managers-migration.ts
Normal file
18
lib/config/migrations/custom/match-managers-migration.ts
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
import is from '@sindresorhus/is';
|
||||||
|
import { isCustomManager } from '../../../modules/manager/custom';
|
||||||
|
import { AbstractMigration } from '../base/abstract-migration';
|
||||||
|
|
||||||
|
export class MatchManagersMigration extends AbstractMigration {
|
||||||
|
override readonly propertyName = 'matchManagers';
|
||||||
|
|
||||||
|
override run(value: unknown): void {
|
||||||
|
if (!is.array<string>(value, is.string)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const newValue = value.map((manager) =>
|
||||||
|
isCustomManager(manager) ? `custom.${manager}` : manager
|
||||||
|
);
|
||||||
|
this.rewrite(newValue);
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,7 +3,7 @@ import { check } from './managers';
|
||||||
describe('config/validation-helpers/managers', () => {
|
describe('config/validation-helpers/managers', () => {
|
||||||
it('should have no errors', () => {
|
it('should have no errors', () => {
|
||||||
const res = check({
|
const res = check({
|
||||||
resolvedRule: { matchManagers: ['npm', 'regex'] },
|
resolvedRule: { matchManagers: ['npm', 'regex', 'custom.regex'] },
|
||||||
currentPath: '',
|
currentPath: '',
|
||||||
});
|
});
|
||||||
expect(res).toEqual([]);
|
expect(res).toEqual([]);
|
||||||
|
|
|
@ -13,7 +13,8 @@ export function check({
|
||||||
if (Array.isArray(resolvedRule.matchManagers)) {
|
if (Array.isArray(resolvedRule.matchManagers)) {
|
||||||
if (
|
if (
|
||||||
resolvedRule.matchManagers.find(
|
resolvedRule.matchManagers.find(
|
||||||
(confManager) => !allManagersList.includes(confManager)
|
(confManager) =>
|
||||||
|
!allManagersList.includes(confManager.replace('custom.', ''))
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
managersErrMessage = `${currentPath}:
|
managersErrMessage = `${currentPath}:
|
||||||
|
|
|
@ -47,5 +47,17 @@ describe('util/package-rules/managers', () => {
|
||||||
);
|
);
|
||||||
expect(result).toBeFalse();
|
expect(result).toBeFalse();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should match custom managers', () => {
|
||||||
|
const result = managersMatcher.matches(
|
||||||
|
{
|
||||||
|
manager: 'regex',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
matchManagers: ['custom.regex'],
|
||||||
|
}
|
||||||
|
);
|
||||||
|
expect(result).toBeTrue();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
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 { isCustomManager } from '../../modules/manager/custom';
|
||||||
import { Matcher } from './base';
|
import { Matcher } from './base';
|
||||||
|
|
||||||
export class ManagersMatcher extends Matcher {
|
export class ManagersMatcher extends Matcher {
|
||||||
|
@ -13,6 +14,9 @@ export class ManagersMatcher extends Matcher {
|
||||||
if (is.undefined(manager) || !manager) {
|
if (is.undefined(manager) || !manager) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (isCustomManager(manager)) {
|
||||||
|
return matchManagers.includes(`custom.${manager}`);
|
||||||
|
}
|
||||||
return matchManagers.includes(manager);
|
return matchManagers.includes(manager);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue