From 0e6a353b33fc57c468fb207f62b10266c1fbc722 Mon Sep 17 00:00:00 2001 From: Jason Jean Date: Wed, 16 Aug 2023 13:04:04 -0400 Subject: [PATCH] fix(core): apply target defaults properly for executors defaults (#18655) (cherry picked from commit f670e7469f3c4f2a8934a4bbe6c4ad9d155b94d7) --- .../build-nodes/workspace-projects.spec.ts | 26 +++++++++++++++++++ .../build-nodes/workspace-projects.ts | 5 ++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/packages/nx/src/project-graph/build-nodes/workspace-projects.spec.ts b/packages/nx/src/project-graph/build-nodes/workspace-projects.spec.ts index 8687e8df7621c..94f1bf2f3f843 100644 --- a/packages/nx/src/project-graph/build-nodes/workspace-projects.spec.ts +++ b/packages/nx/src/project-graph/build-nodes/workspace-projects.spec.ts @@ -312,6 +312,32 @@ describe('workspace-projects', () => { ).toEqual({ a: 'a', b: 'my/project' }); }); + it('should merge options when targets use executors with defaults', () => { + expect( + normalizeProjectTargets( + { + root: 'my/project', + targets: { + build: { + executor: '@nx/jest:jest', + options: { + a: 'a', + }, + }, + }, + }, + { + '@nx/jest:jest': { + options: { + b: 'b', + }, + }, + }, + 'build' + ).build.options + ).toEqual({ a: 'a', b: 'b' }); + }); + it('should not merge options when targets use different executors', () => { expect( normalizeProjectTargets( diff --git a/packages/nx/src/project-graph/build-nodes/workspace-projects.ts b/packages/nx/src/project-graph/build-nodes/workspace-projects.ts index 62f4a92389a4c..5b6f7cff71b1f 100644 --- a/packages/nx/src/project-graph/build-nodes/workspace-projects.ts +++ b/packages/nx/src/project-graph/build-nodes/workspace-projects.ts @@ -134,9 +134,8 @@ export function normalizeProjectTargets( // We need to know the executor for use in readTargetDefaultsForTarget, // but we haven't resolved the `command` syntactic sugar yet. const executor = - targets[target].executor ?? targets[target].command - ? 'nx:run-commands' - : null; + targets[target].executor ?? + (targets[target].command ? 'nx:run-commands' : null); // Allows things like { targetDefaults: { build: { command: tsc } } } const defaults = resolveCommandSyntacticSugar(