mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-24 14:34:21 +00:00
2a300e8d08
* refactor(config): specify scopes for `enabled` and `managerFilePatterns` As part of #43020, the two options which name every manager - and in `enabled`'s case, every update type - can describe where they're valid through `scopes` instead, so they no longer need updating when a manager is added. This allows us to simplify the way that the parents are defined, and will now result in an improved error message i.e. ``` "managerFilePatterns" can't be used at the top level of a config, as it can only be used in a manager's config or in `customManagers`. ``` Co-authored-by: Claude Opus 5 <jamie.tanna+claude-code@mend.io> * fixup! refactor(config): specify scopes for `enabled` and `managerFilePatterns` getConfig() decides whether an option gets a top-level default by checking the raw option.parents for '.', which doesn't know about scopes. Giving `enabled` its top-level eligibility through `scopes` instead of a literal `parents: ['.']` entry meant getConfig() stopped giving it a default value at all, so `config.enabled` became undefined at the top level - breaking anything that reads it before a manager's own config is merged in, such as extract-fingerprint-config.ts. We can use getAllowedParents(), which already knows how to combine scopes and parents, instead of reading option.parents directly. Co-Authored-By: Claude Sonnet 5 <jamie.tanna+claude-code@mend.io> --------- Co-authored-by: Claude Opus 5 <jamie.tanna+claude-code@mend.io>
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import { clone } from '../util/clone.ts';
|
|
import { getOptions } from './options/index.ts';
|
|
import { getAllowedParents } from './options/scopes.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) => {
|
|
const parents = getAllowedParents(option);
|
|
if (!parents || parents.includes('.')) {
|
|
config[option.name as keyof AllConfig] = getDefault(option);
|
|
}
|
|
});
|
|
return config;
|
|
}
|