diff --git a/packages/devkit/src/executors/parse-target-string.spec.ts b/packages/devkit/src/executors/parse-target-string.spec.ts index 3ce6fd0b48182..dc8193a0eb6e7 100644 --- a/packages/devkit/src/executors/parse-target-string.spec.ts +++ b/packages/devkit/src/executors/parse-target-string.spec.ts @@ -62,6 +62,27 @@ describe('parseTargetString', () => { target: 'build', }); }); + + // When running a converted executor, its possible that the context has a project name that + // isn't present within the project graph. In these cases, this function should still behave predictably. + it('should produce accurate results if the project graph doesnt contain the project', () => { + expect( + parseTargetString('foo:build', { ...mockContext, projectName: 'foo' }) + ).toEqual({ + project: 'foo', + target: 'build', + }); + expect( + parseTargetString('foo:build:production', { + ...mockContext, + projectName: 'foo', + }) + ).toEqual({ + project: 'foo', + target: 'build', + configuration: 'production', + }); + }); }); describe('targetToTargetString', () => { diff --git a/packages/devkit/src/executors/parse-target-string.ts b/packages/devkit/src/executors/parse-target-string.ts index 44c0955dd7790..ff63c393485c6 100644 --- a/packages/devkit/src/executors/parse-target-string.ts +++ b/packages/devkit/src/executors/parse-target-string.ts @@ -66,7 +66,8 @@ export function parseTargetString( if ( !projectGraph.nodes[maybeProject] && projectGraphOrCtx && - 'projectName' in projectGraphOrCtx + 'projectName' in projectGraphOrCtx && + maybeProject !== projectGraphOrCtx.projectName ) { targetString = `${projectGraphOrCtx.projectName}:${targetString}`; }