Skip to content

Commit

Permalink
fix(devkit): make parseTargetString more tolerant to bad graph shapes (
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed Nov 10, 2023
1 parent 7a62353 commit 1bd9510
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
21 changes: 21 additions & 0 deletions packages/devkit/src/executors/parse-target-string.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/devkit/src/executors/parse-target-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}
Expand Down

0 comments on commit 1bd9510

Please sign in to comment.