Skip to content

Commit

Permalink
fix(core): do not mutate target defaults (#26941)
Browse files Browse the repository at this point in the history
## Current Behavior
<!-- This is the behavior we have today -->

Target defaults is mutated when the target is normalized. Subsequent
targets are normalized with the mutated version yielding the incorrect
projects configuration.

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

Target defaults is not mutated and all targets are correct.

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #

(cherry picked from commit f3fa705)
  • Loading branch information
FrozenPandaz committed Jul 16, 2024
1 parent cfe163c commit 8e92b21
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 @@ -1571,6 +1571,41 @@ describe('project-configuration-utils', () => {
}
`);
});
it('should not mutate the target', () => {
const config = {
name: 'project',
root: 'libs/project',
targets: {
foo: {
executor: 'nx:noop',
options: {
config: '{projectRoot}/config.json',
},
configurations: {
prod: {
config: '{projectRoot}/config.json',
},
},
},
bar: {
command: 'echo {projectRoot}',
options: {
config: '{projectRoot}/config.json',
},
configurations: {
prod: {
config: '{projectRoot}/config.json',
},
},
},
},
};
const originalConfig = JSON.stringify(config, null, 2);

normalizeTarget(config.targets.foo, config);
normalizeTarget(config.targets.bar, config);
expect(JSON.stringify(config, null, 2)).toEqual(originalConfig);
});
});

describe('createProjectConfigurations', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,13 @@ export function normalizeTarget(
target: TargetConfiguration,
project: ProjectConfiguration
) {
target = {
...target,
configurations: {
...target.configurations,
},
};

target = resolveCommandSyntacticSugar(target, project.root);

target.options = resolveNxTokensInOptions(
Expand All @@ -994,7 +1001,6 @@ export function normalizeTarget(
`${project.root}:${target}`
);

target.configurations ??= {};
for (const configuration in target.configurations) {
target.configurations[configuration] = resolveNxTokensInOptions(
target.configurations[configuration],
Expand Down

0 comments on commit 8e92b21

Please sign in to comment.