From e13cb52ed569ea3d5cc3411cc27dd050a60a1a82 Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@arkins.net> Date: Sun, 16 Feb 2020 06:49:09 +0100 Subject: [PATCH] feat: validate managers --- lib/manager/index.ts | 21 ++++++++++++++++++++- lib/util/modules.ts | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/manager/index.ts b/lib/manager/index.ts index c76274c740..fad24b290f 100644 --- a/lib/manager/index.ts +++ b/lib/manager/index.ts @@ -22,8 +22,27 @@ import { LANGUAGE_RUST, } from '../constants/languages'; import { loadModules } from '../util/modules'; +import { logger } from '../logger'; -const managers = loadModules<ManagerApi>(__dirname); +// istanbul ignore next +function validateManager(manager): boolean { + if (!manager.defaultConfig) { + logger.fatal(`manager is missing defaultConfig`); + return false; + } + if (!manager.updateDependency) { + logger.fatal(`manager is missing updateDependency`); + return false; + } + if (!manager.extractPackageFile && !manager.extractAllPackageFiles) { + logger.fatal( + `manager must support extractPackageFile or extractAllPackageFiles` + ); + } + return true; +} + +const managers = loadModules<ManagerApi>(__dirname, validateManager); const managerList = Object.keys(managers); diff --git a/lib/util/modules.ts b/lib/util/modules.ts index f61deada35..5cb6440c9c 100644 --- a/lib/util/modules.ts +++ b/lib/util/modules.ts @@ -22,7 +22,7 @@ function relatePath(here: string, there: string): string { export function loadModules<T>( dirname: string, - validate?: (x: unknown) => x is T + validate?: (x: unknown) => boolean ): Record<string, T> { const result: Record<string, T> = {}; -- GitLab