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 2807e854a3a90..20a656142bfb8 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 @@ -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', () => { 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 e79037787116b..b843f40878aad 100644 --- a/packages/nx/src/project-graph/utils/project-configuration-utils.ts +++ b/packages/nx/src/project-graph/utils/project-configuration-utils.ts @@ -986,6 +986,13 @@ export function normalizeTarget( target: TargetConfiguration, project: ProjectConfiguration ) { + target = { + ...target, + configurations: { + ...target.configurations, + }, + }; + target = resolveCommandSyntacticSugar(target, project.root); target.options = resolveNxTokensInOptions( @@ -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],