diff --git a/packages/cli/src/utils/commentJson.test.ts b/packages/cli/src/utils/commentJson.test.ts index 4957b7497..fcf2501cd 100644 --- a/packages/cli/src/utils/commentJson.test.ts +++ b/packages/cli/src/utils/commentJson.test.ts @@ -8,7 +8,10 @@ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'; import * as fs from 'node:fs'; import * as path from 'node:path'; import * as os from 'node:os'; -import { updateSettingsFilePreservingFormat } from './commentJson.js'; +import { + updateSettingsFilePreservingFormat, + applyUpdates, +} from './commentJson.js'; describe('commentJson', () => { let tempDir: string; @@ -180,3 +183,18 @@ describe('commentJson', () => { }); }); }); + +describe('applyUpdates', () => { + it('should apply updates correctly', () => { + const original = { a: 1, b: { c: 2 } }; + const updates = { b: { c: 3 } }; + const result = applyUpdates(original, updates); + expect(result).toEqual({ a: 1, b: { c: 3 } }); + }); + it('should apply updates correctly when empty', () => { + const original = { a: 1, b: { c: 2 } }; + const updates = { b: {} }; + const result = applyUpdates(original, updates); + expect(result).toEqual({ a: 1, b: {} }); + }); +}); diff --git a/packages/cli/src/utils/commentJson.ts b/packages/cli/src/utils/commentJson.ts index 9ea4d3f80..bf325d9af 100644 --- a/packages/cli/src/utils/commentJson.ts +++ b/packages/cli/src/utils/commentJson.ts @@ -38,7 +38,7 @@ export function updateSettingsFilePreservingFormat( fs.writeFileSync(filePath, updatedContent, 'utf-8'); } -function applyUpdates( +export function applyUpdates( current: Record, updates: Record, ): Record { @@ -50,6 +50,7 @@ function applyUpdates( typeof value === 'object' && value !== null && !Array.isArray(value) && + Object.keys(value).length > 0 && typeof result[key] === 'object' && result[key] !== null && !Array.isArray(result[key])