Skip to content

Commit 0459c0b

Browse files
committed
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 angular#23291
1 parent 077ee8f commit 0459c0b

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-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/builder-project-by-cwd.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export default async function () {
88
const startCwd = process.cwd();
99

1010
try {
11+
await ng('build', '--project=second-app', '--configuration=development');
12+
1113
// When no project is provided it should favor the project that is located in the current working directory.
1214
process.chdir(join(startCwd, 'projects/second-app'));
1315
await ng('build', '--configuration=development');

0 commit comments

Comments
 (0)