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
This commit is contained in:
Alan Agius 2022-03-21 18:53:58 +01:00 committed by Douglas Parker
parent e49220fba0
commit 036327e9ca
6 changed files with 27 additions and 13 deletions

View File

@ -22,7 +22,8 @@
},
"defaultProject": {
"type": "string",
"description": "Default project name used in commands."
"description": "Default project name used in commands.",
"x-deprecated": "The project to use will be determined from the current working directory."
},
"projects": {
"type": "object",

View File

@ -128,14 +128,14 @@ export abstract class ArchitectCommandModule
// For multi target commands, we always list all projects that have the target.
return allProjectsForTargetName;
} else {
if (allProjectsForTargetName.length === 1) {
return allProjectsForTargetName;
}
const maybeProject = getProjectByCwd(workspace);
if (maybeProject && allProjectsForTargetName.includes(maybeProject)) {
return [maybeProject];
}
if (allProjectsForTargetName.length === 1) {
return allProjectsForTargetName;
}
}
return undefined;

View File

@ -333,6 +333,7 @@ export abstract class SchematicsCommandModule
return 0;
}
private defaultProjectDeprecationWarningShown = false;
private getProjectName(): string | undefined {
const { workspace, logger } = this.context;
if (!workspace) {
@ -354,6 +355,15 @@ export abstract class SchematicsCommandModule
const defaultProjectName = workspace.extensions['defaultProject'];
if (typeof defaultProjectName === 'string' && defaultProjectName) {
if (!this.defaultProjectDeprecationWarningShown) {
logger.warn(tags.oneLine`
DEPRECATED: The 'defaultProject' workspace option has been deprecated.
The project to use will be determined from the current working directory.
`);
this.defaultProjectDeprecationWarningShown = true;
}
return defaultProjectName;
}
}

View File

@ -1,10 +1,7 @@
Adds the npm package for a published library to your workspace, and configures
the project in the current working directory (or the default project if you are
not in a project directory) to use that library, as specified by the library's schematic.
the project in the current working directory to use that library, as specified by the library's schematic.
For example, adding `@angular/pwa` configures your project for PWA support:
```bash
ng add @angular/pwa
```
The default project is the value of `defaultProject` in `angular.json`.

View File

@ -263,6 +263,7 @@ function findProjectByPath(workspace: AngularWorkspace, location: string): strin
return projects[0][1];
}
let defaultProjectDeprecationWarningShown = false;
export function getProjectByCwd(workspace: AngularWorkspace): string | null {
if (workspace.projects.size === 1) {
// If there is only one project, return that one.
@ -277,6 +278,15 @@ export function getProjectByCwd(workspace: AngularWorkspace): string | null {
const defaultProject = workspace.extensions['defaultProject'];
if (defaultProject && typeof defaultProject === 'string') {
// If there is a default project name, return it.
if (!defaultProjectDeprecationWarningShown) {
console.warn(
`DEPRECATED: The 'defaultProject' workspace option has been deprecated. ` +
`The project to use will be determined from the current working directory.`,
);
defaultProjectDeprecationWarningShown = true;
}
return defaultProject;
}

View File

@ -5,10 +5,6 @@ import { updateJsonFile } from '../../utils/project';
export default async function () {
await ng('generate', 'app', 'secondary-app');
await updateJsonFile('angular.json', workspaceJson => {
workspaceJson.defaultProject = undefined;
});
await ng('build', 'secondary-app', '--configuration=development');
expectFileToExist('dist/secondary-app/index.html');