Skip to content

Commit

Permalink
fix(@angular/cli): handle project being passed as a flag
Browse files Browse the repository at this point in the history
Yargs allows passing using positional arguments as flags. This we should handle this when retrieving the project.

Closes #23291

(cherry picked from commit f6e8ce2)
  • Loading branch information
alan-agius4 authored and clydin committed Jun 8, 2022
1 parent 17fec13 commit 0cca363
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Expand Up @@ -94,16 +94,18 @@ export abstract class ArchitectCommandModule
}

private getArchitectProject(): string | undefined {
const workspace = this.context.workspace;
if (!workspace) {
return undefined;
}

const [, projectName] = this.context.args.positional;
const { options, positional } = this.context.args;
const [, projectName] = positional;

if (projectName) {
return workspace.projects.has(projectName) ? projectName : undefined;
return projectName;
}

// Yargs allows positional args to be used as flags.
if (typeof options['project'] === 'string') {
return options['project'];
}

const target = this.getArchitectTarget();
const projectFromTarget = this.getProjectNamesByTarget(target);

Expand Down
@@ -1,4 +1,5 @@
import { join } from 'path';
import { expectFileNotToExist, expectFileToExist } from '../../utils/fs';
import { execAndWaitForOutputToMatch, ng } from '../../utils/process';
import { updateJsonFile } from '../../utils/project';
import { expectToFail } from '../../utils/utils';
Expand Down Expand Up @@ -27,6 +28,9 @@ export default async function () {
// Help should still work
execAndWaitForOutputToMatch('ng', ['build', '--help'], /--configuration/);

// Yargs allows positional args to be passed as flags. Verify that in this case the project can be determined.
await ng('build', '--project=third-app', '--configuration=development');

process.chdir(join(startCwd, 'projects/second-app'));
await ng('build', '--configuration=development');
} finally {
Expand Down

0 comments on commit 0cca363

Please sign in to comment.