diff --git a/packages/nx/src/tasks-runner/utils.spec.ts b/packages/nx/src/tasks-runner/utils.spec.ts index 7743874d78a05..0a6d50331eed7 100644 --- a/packages/nx/src/tasks-runner/utils.spec.ts +++ b/packages/nx/src/tasks-runner/utils.spec.ts @@ -410,6 +410,25 @@ describe('utils', () => { }); }); + it('should assume target of self if simple target also matches project name', () => { + const result = expandDependencyConfigSyntaxSugar('build', { + dependencies: {}, + nodes: { + build: { + name: 'build', + type: 'lib', + data: { + root: 'libs/build', + files: [], + }, + }, + }, + }); + expect(result).toEqual({ + target: 'build', + }); + }); + it('should expand syntax for simple target names targetting dependencies', () => { const result = expandDependencyConfigSyntaxSugar('^build', { dependencies: {}, diff --git a/packages/nx/src/tasks-runner/utils.ts b/packages/nx/src/tasks-runner/utils.ts index a2127db4f8993..96bab4d1666ce 100644 --- a/packages/nx/src/tasks-runner/utils.ts +++ b/packages/nx/src/tasks-runner/utils.ts @@ -69,6 +69,13 @@ export function expandDependencyConfigSyntaxSugar( // Support for both `project:target` and `target:with:colons` syntax const [maybeProject, ...segments] = splitByColons(targetString); + + // if no additional segments are provided, then the string references + // a target of the same project + if (!segments.length) { + return { target: maybeProject }; + } + return { // Only the first segment could be a project. If it is, the rest is a target. // If its not, then the whole targetString was a target with colons in its name.