diff --git a/packages/nx/src/project-graph/utils/normalize-project-nodes.ts b/packages/nx/src/project-graph/utils/normalize-project-nodes.ts index 828aee0b6e09f..9ca4b67fe09fd 100644 --- a/packages/nx/src/project-graph/utils/normalize-project-nodes.ts +++ b/packages/nx/src/project-graph/utils/normalize-project-nodes.ts @@ -43,7 +43,7 @@ export async function normalizeProjectNodes( partialProjectGraphNodes ); - p.targets = normalizeProjectTargets(p, key); + p.targets ??= {}; // TODO: remove in v16 const projectType = @@ -80,25 +80,6 @@ export async function normalizeProjectNodes( }); } -/** - * Apply target defaults and normalization - */ -export function normalizeProjectTargets( - project: ProjectConfiguration, - projectName: string -): Record { - // Any node on the graph will have a targets object, it just may be empty - const targets = project.targets ?? {}; - - for (const target in targets) { - if (!targets[target].command && !targets[target].executor) { - delete targets[target]; - continue; - } - } - return targets; -} - export function normalizeImplicitDependencies( source: string, implicitDependencies: ProjectConfiguration['implicitDependencies'], 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 ded545b3a22a4..8fe55f76c5661 100644 --- a/packages/nx/src/project-graph/utils/project-configuration-utils.ts +++ b/packages/nx/src/project-graph/utils/project-configuration-utils.ts @@ -641,10 +641,21 @@ function validateAndNormalizeProjectRootMap( ); if ( + // If the target has no executor or command, it doesn't do anything !project.targets[targetName].executor && !project.targets[targetName].command ) { - delete project.targets[targetName]; + // But it may have dependencies that do something + if ( + project.targets[targetName].dependsOn && + project.targets[targetName].dependsOn.length > 0 + ) { + project.targets[targetName].executor = 'nx:noop'; + } else { + // If it does nothing, and has no depenencies, + // we can remove it. + delete project.targets[targetName]; + } } } }