mirror of
https://github.com/renovatebot/renovate.git
synced 2026-11-05 11:56:31 +00:00
64e6a4c71f
Enable the unicorn/prefer-at rule as error in .oxlintrc.json and fix all 43 pre-existing violations (arr[arr.length - 1] -> arr.at(-1)) via oxlint autofix. Where .at() widened the type to T | undefined, non-null assertions were added at sites where surrounding logic guarantees the element exists (length guards, split results), preserving the original runtime behavior and typing. Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
import { isEmptyObject, isString } from '@sindresorhus/is';
|
|
import type { PackageDependency } from '../../../types.ts';
|
|
import type { NpmManagerData } from '../../types.ts';
|
|
import { extractDependency } from './dependency.ts';
|
|
import { setNodeCommitTopic } from './node.ts';
|
|
|
|
/**
|
|
* Used when there is a json object as a value in overrides block.
|
|
* @param parents
|
|
* @param child
|
|
* @returns PackageDependency array
|
|
*/
|
|
export function extractOverrideDepsRec(
|
|
parents: string[],
|
|
child: NpmManagerData,
|
|
): PackageDependency[] {
|
|
const deps: PackageDependency[] = [];
|
|
if (!child || isEmptyObject(child)) {
|
|
return deps;
|
|
}
|
|
for (const [overrideName, versionValue] of Object.entries(child)) {
|
|
if (isString(versionValue)) {
|
|
// special handling for "." override dependency name
|
|
// "." means the constraint is applied to the parent dep
|
|
const currDepName = overrideName === '.' ? parents.at(-1)! : overrideName;
|
|
const dep: PackageDependency<NpmManagerData> = {
|
|
depName: currDepName,
|
|
depType: 'overrides',
|
|
managerData: { parents: parents.slice() }, // set parents for dependency
|
|
};
|
|
setNodeCommitTopic(dep);
|
|
deps.push({
|
|
...dep,
|
|
...extractDependency('overrides', currDepName, versionValue),
|
|
});
|
|
} else {
|
|
// versionValue is an object, run recursively.
|
|
parents.push(overrideName);
|
|
const depsOfObject = extractOverrideDepsRec(parents, versionValue);
|
|
deps.push(...depsOfObject);
|
|
}
|
|
}
|
|
parents.pop();
|
|
return deps;
|
|
}
|