2023-11-24 13:26:50 +05:45
|
|
|
import { allManagersList, isKnownManager } from '../../modules/manager';
|
2021-05-11 12:51:21 +02:00
|
|
|
import type { ValidationMessage } from '../types';
|
|
|
|
import type { CheckManagerArgs } from './types';
|
2019-08-23 15:46:31 +02:00
|
|
|
|
2019-02-20 23:29:38 +02:00
|
|
|
/**
|
|
|
|
* Only if type condition or context condition violated then errors array will be mutated to store metadata
|
|
|
|
*/
|
2019-08-23 15:46:31 +02:00
|
|
|
export function check({
|
|
|
|
resolvedRule,
|
|
|
|
currentPath,
|
|
|
|
}: CheckManagerArgs): ValidationMessage[] {
|
2022-04-20 12:22:23 +02:00
|
|
|
let managersErrMessage: string | undefined;
|
2021-01-29 14:43:42 +04:00
|
|
|
if (Array.isArray(resolvedRule.matchManagers)) {
|
2019-02-20 23:29:38 +02:00
|
|
|
if (
|
2021-01-29 14:43:42 +04:00
|
|
|
resolvedRule.matchManagers.find(
|
2023-11-24 13:26:50 +05:45
|
|
|
(confManager) => !isKnownManager(confManager),
|
2019-02-20 23:29:38 +02:00
|
|
|
)
|
|
|
|
) {
|
|
|
|
managersErrMessage = `${currentPath}:
|
2020-08-26 16:59:50 +04:00
|
|
|
You have included an unsupported manager in a package rule. Your list: ${String(
|
2023-11-07 12:50:29 -03:00
|
|
|
resolvedRule.matchManagers,
|
2020-08-26 16:59:50 +04:00
|
|
|
)}.
|
2023-08-15 22:57:54 +05:45
|
|
|
Supported managers are: (${allManagersList.join(', ')}).`;
|
2019-02-20 23:29:38 +02:00
|
|
|
}
|
2021-01-29 14:43:42 +04:00
|
|
|
} else if (typeof resolvedRule.matchManagers !== 'undefined') {
|
|
|
|
managersErrMessage = `${currentPath}: Managers should be type of List. You have included ${typeof resolvedRule.matchManagers}.`;
|
2020-03-17 12:15:22 +01:00
|
|
|
}
|
2019-02-20 23:29:38 +02:00
|
|
|
|
|
|
|
return managersErrMessage
|
|
|
|
? [
|
|
|
|
{
|
2021-04-01 15:50:17 +02:00
|
|
|
topic: 'Configuration Error',
|
2019-02-20 23:29:38 +02:00
|
|
|
message: managersErrMessage,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
: [];
|
2019-08-23 15:46:31 +02:00
|
|
|
}
|