mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-26 07:20:39 +00:00
58771bb183
* refactor(oxlint): enable func-style Enable the built-in func-style rule as ["warn", "declaration"] so that named functions are written as function declarations instead of arrow or function expressions assigned to variables, matching the convention in docs/development/best-practices.md (Functions section). Inline arrow callbacks are unaffected; prefer-arrow-callback continues to cover the callback direction. Severity is "warn" instead of "error" as a fallback: a repo-wide run found 196 pre-existing violations (70 in spec files, 126 in production code), exceeding the 80-violation fix threshold for this change, so no violations were fixed here. Follow-up work can convert the offenders (largest clusters: lib/modules/versioning/ruby, lib/util/cache/package, lib/modules/versioning/maven, lib/modules/versioning/gradle) and then raise the rule to "error". Note oxlint 1.72 also supports an allowTypeAnnotation option if typed consts should remain arrows. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * ci(linter): enforce func-style at error * refactor(func-style): convert const-arrow functions to declarations in with-cache spec and ruby versioning * refactor(func-style): convert const-arrow functions to declarations in maven/gradle modules * refactor(func-style): convert const-arrow functions to declarations in remaining versioning modules * refactor(func-style): convert const-arrow functions to declarations in platform modules Discriminated-union closures (ensureCommentRemoval byTopic/byContent helpers in github, gitlab, bitbucket, bitbucket-server) needed the narrowed field passed explicitly as a parameter, since function declarations are hoisted and lose the outer if-narrowing that inline arrow-function closures previously relied on. * refactor(func-style): convert const-arrow functions to declarations across util/manager/datasource modules One case (logger/renovate-logger.ts logOnceFn) is kept as an arrow function with a documented oxlint-disable: it is stored on this.logger.once[level] and relies on lexically-bound this, which a hoisted function declaration would not preserve. * refactor(func-style): convert remaining const-arrow test helpers to declarations get-updated.spec.ts: hoisted expectPipCompilePackageAndLockFile to module scope (it only closes over the module-level pipCompile mock) and added a documented oxlint-disable for vitest/expect-expect on its caller test, since oxlint's expect-expect check does not trace assertions through an externally-defined helper function. --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
142 lines
3.9 KiB
TypeScript
142 lines
3.9 KiB
TypeScript
import type { MaybePromise, RangeStrategy } from '../../types/index.ts';
|
|
import managers from './api.ts';
|
|
import customManagers from './custom/api.ts';
|
|
import { customManagerList, isCustomManager } from './custom/index.ts';
|
|
import type {
|
|
ExtractConfig,
|
|
GlobalManagerConfig,
|
|
ManagerApi,
|
|
PackageFile,
|
|
PackageFileContent,
|
|
RangeConfig,
|
|
} from './types.ts';
|
|
|
|
export { hashMap } from './fingerprint.generated.ts';
|
|
|
|
const managerList = Array.from(managers.keys()); // does not include custom managers
|
|
export function getManagerList(): string[] {
|
|
return managerList;
|
|
}
|
|
export function getManagers(): Map<string, ManagerApi> {
|
|
return managers;
|
|
}
|
|
export const allManagersList = [...managerList, ...customManagerList];
|
|
|
|
export function get<T extends keyof ManagerApi>(
|
|
manager: string,
|
|
name: T,
|
|
): ManagerApi[T] | undefined {
|
|
return isCustomManager(manager)
|
|
? customManagers.get(manager)?.[name]
|
|
: managers.get(manager)?.[name];
|
|
}
|
|
|
|
export async function detectAllGlobalConfig(): Promise<GlobalManagerConfig> {
|
|
let config: GlobalManagerConfig = {};
|
|
for (const managerName of allManagersList) {
|
|
const manager =
|
|
managers.get(managerName)! ?? customManagers.get(managerName)!;
|
|
if (manager.detectGlobalConfig) {
|
|
// This should use mergeChildConfig once more than one manager is supported, but introduces a cyclic dependency
|
|
config = { ...config, ...(await manager.detectGlobalConfig()) };
|
|
}
|
|
}
|
|
return config;
|
|
}
|
|
|
|
export async function extractAllPackageFiles(
|
|
manager: string,
|
|
config: ExtractConfig,
|
|
files: string[],
|
|
): Promise<PackageFile[] | null> {
|
|
if (!managers.has(manager)) {
|
|
return null;
|
|
}
|
|
const m = managers.get(manager)!;
|
|
if (m.extractAllPackageFiles) {
|
|
const res = await m.extractAllPackageFiles(config, files);
|
|
// istanbul ignore if
|
|
if (!res) {
|
|
return null;
|
|
}
|
|
return res;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
export function extractPackageFile(
|
|
manager: string,
|
|
content: string,
|
|
fileName: string,
|
|
config: ExtractConfig,
|
|
): MaybePromise<PackageFileContent | null> {
|
|
const m = managers.get(manager)! ?? customManagers.get(manager)!;
|
|
if (!m) {
|
|
return null;
|
|
}
|
|
|
|
return m.extractPackageFile
|
|
? m.extractPackageFile(content, fileName, config)
|
|
: null;
|
|
}
|
|
|
|
export function getRangeStrategy(config: RangeConfig): RangeStrategy | null {
|
|
const { manager, rangeStrategy } = config;
|
|
if (!manager || !managers.has(manager)) {
|
|
return null;
|
|
}
|
|
const m = managers.get(manager)!;
|
|
if (m.getRangeStrategy) {
|
|
// Use manager's own function if it exists
|
|
const managerRangeStrategy = m.getRangeStrategy(config);
|
|
if (managerRangeStrategy === 'in-range-only') {
|
|
return 'update-lockfile';
|
|
}
|
|
return managerRangeStrategy;
|
|
}
|
|
if (rangeStrategy === 'auto') {
|
|
if (m.updateLockedDependency) {
|
|
return 'update-lockfile';
|
|
}
|
|
// default to 'replace' for auto
|
|
return 'replace';
|
|
}
|
|
if (rangeStrategy === 'in-range-only') {
|
|
return 'update-lockfile';
|
|
}
|
|
|
|
return config.rangeStrategy!;
|
|
}
|
|
|
|
export function getPrettyDepType(
|
|
manager: string,
|
|
depType: string,
|
|
): string | undefined {
|
|
const m = managers.get(manager) ?? customManagers.get(manager);
|
|
return m?.knownDepTypes?.find((meta) => meta.depType === depType)
|
|
?.prettyDepType;
|
|
}
|
|
|
|
export function isKnownManager(mgr: string): boolean {
|
|
return allManagersList.includes(mgr.replace('custom.', ''));
|
|
}
|
|
|
|
/**
|
|
* Filter a list of managers based on enabled managers.
|
|
*
|
|
* If enabledManagers is provided, this function returns a subset of allManagersList
|
|
* that matches the enabled manager names, including custom managers. If enabledManagers
|
|
* is not provided or is an empty array, it returns the full list of managers.
|
|
*/
|
|
export function getEnabledManagersList(enabledManagers?: string[]): string[] {
|
|
if (enabledManagers?.length) {
|
|
return allManagersList.filter(
|
|
(manager) =>
|
|
enabledManagers.includes(manager) ||
|
|
enabledManagers.includes(`custom.${manager}`),
|
|
);
|
|
}
|
|
|
|
return allManagersList;
|
|
}
|