Skip to content

Commit

Permalink
fix(core): fixing target groups not merging (#28280)
Browse files Browse the repository at this point in the history
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

<!-- This is the behavior we have today -->
When multiple plugins touch the `project > metadata` (note NOT `project
> target > metadata`), only the last plugin to run has their
`metadata.targetGroups` data present, meaning currently `targetGroups`
is clobbering instead of merging.

<!-- This is the behavior we should expect with the changes in this PR
-->
When multiple plugins write to `metadata.targetGroups`, that data is
merged together, so data written by all plugins is present.

<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #

(cherry picked from commit 7ff387d)
  • Loading branch information
ZackDeRose authored and FrozenPandaz committed Oct 3, 2024
1 parent 9dc91ba commit aa88814
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export function mergeMetadata<T = ProjectMetadata | TargetMetadata>(
}
}
} else {
result[metadataKey] = value;
result[metadataKey][key] = value[key];
if (sourceMap) {
sourceMap[`${baseSourceMapPath}.${metadataKey}`] =
sourceInformation;
Expand Down

0 comments on commit aa88814

Please sign in to comment.