Skip to content

Commit 054ae02

Browse files
alan-agius4clydin
authored andcommitted
fix(@angular/cli): favor project in cwd when running architect commands
When running architect command such as `ng build`, `ng test`, `ng lint`... and no project is provided as a positional argument. The project in the current working directory is favored instead of the configured as default project.
1 parent ca40125 commit 054ae02

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
import { Argv } from 'yargs';
10+
import { getProjectByCwd } from '../utilities/config';
1011
import { ArchitectBaseCommandModule } from './architect-base-command-module';
1112
import {
1213
CommandModuleError,
@@ -127,14 +128,9 @@ export abstract class ArchitectCommandModule
127128
// For multi target commands, we always list all projects that have the target.
128129
return allProjectsForTargetName;
129130
} else {
130-
// For single target commands, we try the default project first,
131-
// then the full list if it has a single project, then error out.
132-
const maybeDefaultProject = workspace.extensions['defaultProject'];
133-
if (
134-
typeof maybeDefaultProject === 'string' &&
135-
allProjectsForTargetName.includes(maybeDefaultProject)
136-
) {
137-
return [maybeDefaultProject];
131+
const maybeProject = getProjectByCwd(workspace);
132+
if (maybeProject && allProjectsForTargetName.includes(maybeProject)) {
133+
return [maybeProject];
138134
}
139135

140136
if (allProjectsForTargetName.length === 1) {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { join } from 'path';
2+
import { expectFileToExist } from '../../utils/fs';
3+
import { ng } from '../../utils/process';
4+
5+
export default async function () {
6+
await ng('generate', 'app', 'second-app', '--skip-install');
7+
await ng('generate', 'app', 'third-app', '--skip-install');
8+
const startCwd = process.cwd();
9+
10+
try {
11+
// When no project is provided it should favor the project that is located in the current working directory.
12+
process.chdir(join(startCwd, 'projects/second-app'));
13+
await ng('build', '--configuration=development');
14+
15+
process.chdir(startCwd);
16+
await expectFileToExist('dist/second-app');
17+
} finally {
18+
// restore path
19+
process.chdir(startCwd);
20+
}
21+
}

0 commit comments

Comments
 (0)