diff --git a/packages/nx/src/project-graph/utils/project-configuration-utils.spec.ts b/packages/nx/src/project-graph/utils/project-configuration-utils.spec.ts index ba16b50b938aef..d3ca5ecabca8b1 100644 --- a/packages/nx/src/project-graph/utils/project-configuration-utils.spec.ts +++ b/packages/nx/src/project-graph/utils/project-configuration-utils.spec.ts @@ -965,6 +965,47 @@ describe('project-configuration-utils', () => { sourceMap['libs/lib-a']['metadata.targetGroups.group1.1'] ).toEqual(['dummy', 'dummy.ts']); }); + + it('should not clobber targetGroups', () => { + const rootMap = new RootMapBuilder() + .addProject({ + root: 'libs/lib-a', + name: 'lib-a', + metadata: { + targetGroups: { + group2: ['target3'], + }, + }, + }) + .getRootMap(); + const sourceMap: ConfigurationSourceMaps = { + 'libs/lib-a': {}, + }; + + mergeProjectConfigurationIntoRootMap( + rootMap, + { + root: 'libs/lib-a', + name: 'lib-a', + metadata: { + technologies: ['technology'], + targetGroups: { + group1: ['target1', 'target2'], + }, + }, + }, + sourceMap, + ['dummy', 'dummy.ts'] + ); + + expect(rootMap['libs/lib-a'].metadata).toEqual({ + technologies: ['technology'], + targetGroups: { + group1: ['target1', 'target2'], + group2: ['target3'], + }, + }); + }); }); describe('source map', () => { diff --git a/packages/nx/src/project-graph/utils/project-configuration-utils.ts b/packages/nx/src/project-graph/utils/project-configuration-utils.ts index bb48f709c18fef..291e8fe93c1eff 100644 --- a/packages/nx/src/project-graph/utils/project-configuration-utils.ts +++ b/packages/nx/src/project-graph/utils/project-configuration-utils.ts @@ -252,7 +252,7 @@ export function mergeMetadata( } } } else { - result[metadataKey] = value; + result[metadataKey][key] = value[key]; if (sourceMap) { sourceMap[`${baseSourceMapPath}.${metadataKey}`] = sourceInformation;