Skip to content

Commit 1132b97

Browse files
committed
feat(@angular/cli): deprecate defaultProject
1 parent 8150838 commit 1132b97

File tree

5 files changed

+21
-22
lines changed

5 files changed

+21
-22
lines changed

docs/documentation/angular-workspace.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
- **version** (`integer`): File format version. This is currently `"1"`.
88

9-
- **newProjectRoot** (`string`): Path where new projects will be created.
9+
- **newProjectRoot** (`string`): (**DEPRECATED**) Path where new projects will be created.
1010

1111
- **defaultProject** (`string`): Default project name used in commands.
1212

packages/angular/cli/lib/config/schema.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
},
2323
"defaultProject": {
2424
"type": "string",
25-
"description": "Default project name used in commands."
25+
"description": "(DEPRECATED) Default project name used in commands."
2626
},
2727
"projects": {
2828
"type": "object",

packages/angular/cli/models/architect-command.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { experimental, json, schema, tags } from '@angular-devkit/core';
1515
import { NodeJsSyncHost, createConsoleLogger } from '@angular-devkit/core/node';
1616
import { from } from 'rxjs';
1717
import { concatMap, map, tap, toArray } from 'rxjs/operators';
18+
import { getProjectByCwd } from '../utilities/config';
1819
import { parseJsonSchemaToOptions } from '../utilities/json-schema';
1920
import { BaseCommandOptions, Command } from './command';
2021
import { Arguments } from './interface';
@@ -212,11 +213,11 @@ export abstract class ArchitectCommand<
212213
// For multi target commands, we always list all projects that have the target.
213214
return allProjectsForTargetName;
214215
} else {
215-
// For single target commands, we try the default project first,
216+
// For single target commands, we try the current project first,
216217
// then the full list if it has a single project, then error out.
217-
const maybeDefaultProject = this._workspace.getDefaultProjectName();
218-
if (maybeDefaultProject && allProjectsForTargetName.includes(maybeDefaultProject)) {
219-
return [maybeDefaultProject];
218+
const maybeCurrentProject = getProjectByCwd(this._workspace, this.logger);
219+
if (maybeCurrentProject && allProjectsForTargetName.includes(maybeCurrentProject)) {
220+
return [maybeCurrentProject];
220221
}
221222

222223
if (allProjectsForTargetName.length === 1) {

packages/angular/cli/models/schematic-command.ts

+1-15
Original file line numberDiff line numberDiff line change
@@ -271,21 +271,7 @@ export abstract class SchematicCommand<
271271

272272
workflow.registry.addSmartDefaultProvider('projectName', () => {
273273
if (this._workspace) {
274-
try {
275-
return this._workspace.getProjectByPath(normalize(process.cwd()))
276-
|| this._workspace.getDefaultProjectName();
277-
} catch (e) {
278-
if (e instanceof experimental.workspace.AmbiguousProjectPathException) {
279-
this.logger.warn(tags.oneLine`
280-
Two or more projects are using identical roots.
281-
Unable to determine project using current working directory.
282-
Using default workspace project instead.
283-
`);
284-
285-
return this._workspace.getDefaultProjectName();
286-
}
287-
throw e;
288-
}
274+
return getProjectByCwd(this._workspace, this.logger);
289275
}
290276

291277
return undefined;

packages/angular/cli/utilities/config.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ import {
1111
JsonObject,
1212
JsonParseMode,
1313
experimental,
14+
logging,
1415
normalize,
1516
parseJson,
1617
parseJsonAst,
18+
tags,
1719
virtualFs,
1820
} from '@angular-devkit/core';
1921
import { NodeJsSyncHost } from '@angular-devkit/core/node';
@@ -140,11 +142,21 @@ export function validateWorkspace(json: JsonObject) {
140142
return true;
141143
}
142144

143-
export function getProjectByCwd(workspace: experimental.workspace.Workspace): string | null {
145+
export function getProjectByCwd(
146+
workspace: experimental.workspace.Workspace,
147+
logger: logging.Logger = new logging.NullLogger(),
148+
): string | null {
144149
try {
145150
return workspace.getProjectByPath(normalize(process.cwd()));
146151
} catch (e) {
147152
if (e instanceof experimental.workspace.AmbiguousProjectPathException) {
153+
logger.warn(tags.oneLine`
154+
Two or more projects are using identical roots.
155+
Unable to determine project using current working directory.
156+
Using default workspace project instead.
157+
`);
158+
logger.warn(`The defaultProject property is DEPRECATED and will be removed in CLI v8.`);
159+
148160
return workspace.getDefaultProjectName();
149161
}
150162
throw e;

0 commit comments

Comments
 (0)