Skip to content

Commit 036327e

Browse files
alan-agius4dgp1130
authored andcommitted
feat(@angular/cli): deprecated defaultProject option
With this change we deprecate the angular.json `defaultProject` option. DEPRECATED: The `defaultProject` workspace option has been deprecated. The project to use will be determined from the current working directory. Closes #20661
1 parent e49220f commit 036327e

6 files changed

Lines changed: 27 additions & 13 deletions

File tree

‎packages/angular/cli/lib/config/workspace-schema.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
},
2323
"defaultProject": {
2424
"type": "string",
25-
"description": "Default project name used in commands."
25+
"description": "Default project name used in commands.",
26+
"x-deprecated": "The project to use will be determined from the current working directory."
2627
},
2728
"projects": {
2829
"type": "object",

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,14 @@ export abstract class ArchitectCommandModule
128128
// For multi target commands, we always list all projects that have the target.
129129
return allProjectsForTargetName;
130130
} else {
131+
if (allProjectsForTargetName.length === 1) {
132+
return allProjectsForTargetName;
133+
}
134+
131135
const maybeProject = getProjectByCwd(workspace);
132136
if (maybeProject && allProjectsForTargetName.includes(maybeProject)) {
133137
return [maybeProject];
134138
}
135-
136-
if (allProjectsForTargetName.length === 1) {
137-
return allProjectsForTargetName;
138-
}
139139
}
140140

141141
return undefined;

‎packages/angular/cli/src/command-builder/schematics-command-module.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ export abstract class SchematicsCommandModule
333333
return 0;
334334
}
335335

336+
private defaultProjectDeprecationWarningShown = false;
336337
private getProjectName(): string | undefined {
337338
const { workspace, logger } = this.context;
338339
if (!workspace) {
@@ -354,6 +355,15 @@ export abstract class SchematicsCommandModule
354355

355356
const defaultProjectName = workspace.extensions['defaultProject'];
356357
if (typeof defaultProjectName === 'string' && defaultProjectName) {
358+
if (!this.defaultProjectDeprecationWarningShown) {
359+
logger.warn(tags.oneLine`
360+
DEPRECATED: The 'defaultProject' workspace option has been deprecated.
361+
The project to use will be determined from the current working directory.
362+
`);
363+
364+
this.defaultProjectDeprecationWarningShown = true;
365+
}
366+
357367
return defaultProjectName;
358368
}
359369
}
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
Adds the npm package for a published library to your workspace, and configures
2-
the project in the current working directory (or the default project if you are
3-
not in a project directory) to use that library, as specified by the library's schematic.
2+
the project in the current working directory to use that library, as specified by the library's schematic.
43
For example, adding `@angular/pwa` configures your project for PWA support:
54

65
```bash
76
ng add @angular/pwa
87
```
9-
10-
The default project is the value of `defaultProject` in `angular.json`.

‎packages/angular/cli/src/utilities/config.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ function findProjectByPath(workspace: AngularWorkspace, location: string): strin
263263
return projects[0][1];
264264
}
265265

266+
let defaultProjectDeprecationWarningShown = false;
266267
export function getProjectByCwd(workspace: AngularWorkspace): string | null {
267268
if (workspace.projects.size === 1) {
268269
// If there is only one project, return that one.
@@ -277,6 +278,15 @@ export function getProjectByCwd(workspace: AngularWorkspace): string | null {
277278
const defaultProject = workspace.extensions['defaultProject'];
278279
if (defaultProject && typeof defaultProject === 'string') {
279280
// If there is a default project name, return it.
281+
if (!defaultProjectDeprecationWarningShown) {
282+
console.warn(
283+
`DEPRECATED: The 'defaultProject' workspace option has been deprecated. ` +
284+
`The project to use will be determined from the current working directory.`,
285+
);
286+
287+
defaultProjectDeprecationWarningShown = true;
288+
}
289+
280290
return defaultProject;
281291
}
282292

‎tests/legacy-cli/e2e/tests/misc/multiple-targets.ts‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ import { updateJsonFile } from '../../utils/project';
55
export default async function () {
66
await ng('generate', 'app', 'secondary-app');
77

8-
await updateJsonFile('angular.json', workspaceJson => {
9-
workspaceJson.defaultProject = undefined;
10-
});
11-
128
await ng('build', 'secondary-app', '--configuration=development');
139

1410
expectFileToExist('dist/secondary-app/index.html');

0 commit comments

Comments
 (0)