Skip to content

Commit 0cca363

Browse files
alan-agius4clydin
authored andcommitted
fix(@angular/cli): handle project being passed as a flag
Yargs allows passing using positional arguments as flags. This we should handle this when retrieving the project. Closes #23291 (cherry picked from commit f6e8ce2)
1 parent 17fec13 commit 0cca363

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

packages/angular/cli/src/command-builder/architect-command-module.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,18 @@ export abstract class ArchitectCommandModule
9494
}
9595

9696
private getArchitectProject(): string | undefined {
97-
const workspace = this.context.workspace;
98-
if (!workspace) {
99-
return undefined;
100-
}
101-
102-
const [, projectName] = this.context.args.positional;
97+
const { options, positional } = this.context.args;
98+
const [, projectName] = positional;
10399

104100
if (projectName) {
105-
return workspace.projects.has(projectName) ? projectName : undefined;
101+
return projectName;
106102
}
103+
104+
// Yargs allows positional args to be used as flags.
105+
if (typeof options['project'] === 'string') {
106+
return options['project'];
107+
}
108+
107109
const target = this.getArchitectTarget();
108110
const projectFromTarget = this.getProjectNamesByTarget(target);
109111

tests/legacy-cli/e2e/tests/commands/project-cannot-be-determined-by-cwd.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { join } from 'path';
2+
import { expectFileNotToExist, expectFileToExist } from '../../utils/fs';
23
import { execAndWaitForOutputToMatch, ng } from '../../utils/process';
34
import { updateJsonFile } from '../../utils/project';
45
import { expectToFail } from '../../utils/utils';
@@ -27,6 +28,9 @@ export default async function () {
2728
// Help should still work
2829
execAndWaitForOutputToMatch('ng', ['build', '--help'], /--configuration/);
2930

31+
// Yargs allows positional args to be passed as flags. Verify that in this case the project can be determined.
32+
await ng('build', '--project=third-app', '--configuration=development');
33+
3034
process.chdir(join(startCwd, 'projects/second-app'));
3135
await ng('build', '--configuration=development');
3236
} finally {

0 commit comments

Comments
 (0)