mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-27 07:50:47 +00:00
930cf6633c
fix: Additional vi.mock path corrections and prettier formatting
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import { clone } from '../util/clone.ts';
|
|
import { getOptions } from './options/index.ts';
|
|
import type { AllConfig, RenovateOptions } from './types.ts';
|
|
|
|
// 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]()
|
|
: clone(option.default);
|
|
}
|
|
|
|
export function getConfig(): AllConfig {
|
|
const options = getOptions();
|
|
const config: AllConfig = {};
|
|
options.forEach((option) => {
|
|
if (!option.parents || option.parents.includes('.')) {
|
|
config[option.name as keyof AllConfig] = getDefault(option);
|
|
}
|
|
});
|
|
return config;
|
|
}
|