0
0
mirror of https://github.com/renovatebot/renovate.git synced 2024-12-22 05:28:35 +00:00
renovatebot_renovate/lib/config/defaults.ts
RahulGautamSingh d908ca3c2e
refactor: config option parent -> parents (#26609)
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
Co-authored-by: Rhys Arkins <rhys@arkins.net>
2024-01-22 08:23:59 +00:00

32 lines
998 B
TypeScript

import { getOptions } from './options';
import type { AllConfig, RenovateOptions } from './types';
// Use functions instead of direct values to avoid introducing global references.
// In particular, we want a new array instance every time we request a default array
// instead of sharing a single instance - mutation of this value could cause serious problems.
// See https://github.com/mend/renovate-on-prem/issues/290 for an example
const defaultValueFactories = {
boolean: () => true,
array: () => [],
string: () => null,
object: () => null,
integer: () => null,
} as const;
export function getDefault(option: RenovateOptions): any {
return option.default === undefined
? defaultValueFactories[option.type]()
: option.default;
}
export function getConfig(): AllConfig {
const options = getOptions();
const config: AllConfig = {};
options.forEach((option) => {
if (!option.parents) {
config[option.name] = getDefault(option);
}
});
return config;
}