Skip to content

Commit c083e61

Browse files
committed
Preserve root node fields when merging additional IDLs
1 parent 7acb813 commit c083e61

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

packages/cli/src/parsedConfig.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getAllPrograms, type RootNode,rootNode } from '@codama/nodes';
1+
import { getAllPrograms, type RootNode } from '@codama/nodes';
22
import { Command } from 'commander';
33

44
import { Config, getConfig, ScriptName, ScriptsConfig, VisitorConfig, VisitorPath } from './config';
@@ -71,7 +71,8 @@ async function mergeAdditionalIdls(
7171
additionalPrograms.push(...getAllPrograms(additionalRootNode));
7272
}
7373

74-
return rootNode(mainRootNode.program, additionalPrograms);
74+
// Preserve the main root node's other fields (e.g. `standard`, `version`).
75+
return { ...mainRootNode, additionalPrograms };
7576
}
7677

7778
function parseIdlPath(

packages/cli/test/parsedConfig.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,17 @@ beforeEach(() => {
4545
test('merges additionalIdls programs into the root node additionalPrograms', async () => {
4646
getConfigMock.mockResolvedValue([{ additionalIdls: ['a.json', 'b.json'], idl: 'main.json' }, '/root/codama.json']);
4747
getRootNodeFromIdlMock
48-
.mockResolvedValueOnce(rootNodeWith('main'))
48+
.mockResolvedValueOnce({ ...rootNodeWith('main'), version: '9.9.9' } as RootNode)
4949
.mockResolvedValueOnce(rootNodeWith('a'))
5050
.mockResolvedValueOnce(rootNodeWith('b'));
5151

5252
const parsed = await getParsedConfig({});
5353

5454
expect(parsed.rootNode.program.name).toBe('main');
5555
expect(parsed.rootNode.additionalPrograms.map(p => p.name)).toEqual(['a', 'b']);
56+
// The main root node's other fields are preserved by the merge.
57+
expect(parsed.rootNode.standard).toBe('codama');
58+
expect(parsed.rootNode.version).toBe('9.9.9');
5659
});
5760

5861
test('leaves the root node unchanged when no additionalIdls are provided', async () => {

0 commit comments

Comments
 (0)