0
0
mirror of https://github.com/renovatebot/renovate.git synced 2024-12-23 05:58:05 +00:00
renovatebot_renovate/lib/modules/manager/npm/extract/common/overrides.ts
timesince dcf214f36b
chore: fix some comments (#30697)
Signed-off-by: timesince <seekseat@icloud.com>
2024-08-12 06:32:08 +00:00

47 lines
1.5 KiB
TypeScript

import is from '@sindresorhus/is';
import type { PackageDependency } from '../../../types';
import type { NpmManagerData } from '../../types';
import { extractDependency } from './dependency';
import { setNodeCommitTopic } from './node';
/**
* 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 || is.emptyObject(child)) {
return deps;
}
for (const [overrideName, versionValue] of Object.entries(child)) {
if (is.string(versionValue)) {
// special handling for "." override dependency name
// "." means the constraint is applied to the parent dep
const currDepName =
overrideName === '.' ? parents[parents.length - 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;
}