fix(devkit): make parseTargetString more tolerant to bad graph shapes (#20170)

This commit is contained in:
Craigory Coppola 2023-11-09 21:13:46 -05:00 committed by GitHub
parent 7a62353454
commit 1bd95104cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View File

@ -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', () => {

View File

@ -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}`;
}