added cli-covarage tool and fixed more tests

This commit is contained in:
Boki 2025-06-26 14:23:01 -04:00
parent b63e58784c
commit b845a8eade
57 changed files with 11917 additions and 295 deletions

View file

@ -213,28 +213,47 @@ export class ConfigManager<T = Record<string, unknown>> {
}
private deepMerge(...objects: Record<string, unknown>[]): Record<string, unknown> {
const result: Record<string, unknown> = {};
const seen = new WeakSet();
const merge = (...objs: Record<string, unknown>[]): Record<string, unknown> => {
const result: Record<string, unknown> = {};
for (const obj of objects) {
for (const [key, value] of Object.entries(obj)) {
if (value === null || value === undefined) {
result[key] = value;
} else if (
typeof value === 'object' &&
!Array.isArray(value) &&
!(value instanceof Date) &&
!(value instanceof RegExp)
) {
result[key] = this.deepMerge(
(result[key] as Record<string, unknown>) || ({} as Record<string, unknown>),
value as Record<string, unknown>
);
} else {
result[key] = value;
for (const obj of objs) {
if (seen.has(obj)) {
// Skip circular reference instead of throwing
return result;
}
seen.add(obj);
for (const [key, value] of Object.entries(obj)) {
if (value === null || value === undefined) {
result[key] = value;
} else if (
typeof value === 'object' &&
!Array.isArray(value) &&
!(value instanceof Date) &&
!(value instanceof RegExp)
) {
if (seen.has(value)) {
// Skip circular reference - don't merge this value
continue;
}
result[key] = merge(
(result[key] as Record<string, unknown>) || ({} as Record<string, unknown>),
value as Record<string, unknown>
);
} else {
result[key] = value;
}
}
seen.delete(obj);
}
}
return result;
return result;
};
return merge(...objects);
}
}