Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): properly handle reading target defaults #26959

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -1057,7 +1056,7 @@ export function readTargetDefaultsForTarget(
return targetDefaults[matchingTargetDefaultKey];
}

return {};
return null;
}

function createRootMap(projectRootMap: Record<string, ProjectConfiguration>) {
Expand Down