in packages/monorepo/src/utils/common.ts [71:113]
function mergeOne(target: any, source: any) {
for (const key of Object.keys(source)) {
const value = source[key];
if (isObject(value)) {
// if the value at the target is not an object, override it with an
// object so we can continue the recursion
if (typeof target[key] !== "object") {
target[key] = value;
}
if (Array.isArray(value)) {
if (Array.isArray(target[key])) {
target[key].push(...value);
} else {
target[key] = value;
}
}
mergeOne(target[key], value);
// if the result of the merge is an empty object, it's because the
// eventual value we assigned is `undefined`, and there are no
// sibling concrete values alongside, so we can delete this tree.
const output = target[key];
if (
typeof output === "object" &&
Object.keys(output).length === 0 &&
destructive
) {
delete target[key];
}
} else if (value === undefined && destructive) {
delete target[key];
} else if (Array.isArray(value)) {
if (Array.isArray(target[key])) {
// Append to existing array
target[key].push(...value);
} else {
// Override with array value
target[key] = value;
}
} else if (typeof value !== "undefined") {
target[key] = value;
}
}
}