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 7da77446b5418..6e008bca2a7e0 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 @@ -79,6 +79,18 @@ describe('project-configuration-utils', () => { ).toEqual('default-value-for-e2e-ci-file'); }); + it('should return longest matching target even if executor is passed', () => { + expect( + // This uses an executor which does not have settings in target defaults + // thus the target name pattern target defaults are used + readTargetDefaultsForTarget( + 'e2e-ci--file-foo', + targetDefaults, + 'other-executor' + ).options['key'] + ).toEqual('default-value-for-e2e-ci-file'); + }); + it('should not merge top level properties for incompatible targets', () => { expect( mergeTargetConfigurations( 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 5bc1ca103155c..db54257ac33e6 100644 --- a/packages/nx/src/project-graph/utils/project-configuration-utils.ts +++ b/packages/nx/src/project-graph/utils/project-configuration-utils.ts @@ -1029,14 +1029,13 @@ export function readTargetDefaultsForTarget( targetDefaults: TargetDefaults, executor?: string ): TargetDefaults[string] { - if (executor) { + if (executor && targetDefaults?.[executor]) { // If an executor is defined in project.json, defaults should be read // from the most specific key that matches that executor. // e.g. If executor === run-commands, and the target is named build: // Use, use nx:run-commands if it is present // If not, use build if it is present. - const key = [executor, targetName].find((x) => targetDefaults?.[x]); - return key ? targetDefaults?.[key] : null; + return targetDefaults?.[executor]; } else if (targetDefaults?.[targetName]) { // If the executor is not defined, the only key we have is the target name. return targetDefaults?.[targetName]; @@ -1057,7 +1056,7 @@ export function readTargetDefaultsForTarget( return targetDefaults[matchingTargetDefaultKey]; } - return {}; + return null; } function createRootMap(projectRootMap: Record) {