mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-19 04:26:01 +08:00
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:
parent
e49220fba0
commit
036327e9ca
@ -22,7 +22,8 @@
|
|||||||
},
|
},
|
||||||
"defaultProject": {
|
"defaultProject": {
|
||||||
"type": "string",
|
"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": {
|
"projects": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
@ -128,14 +128,14 @@ export abstract class ArchitectCommandModule
|
|||||||
// For multi target commands, we always list all projects that have the target.
|
// For multi target commands, we always list all projects that have the target.
|
||||||
return allProjectsForTargetName;
|
return allProjectsForTargetName;
|
||||||
} else {
|
} else {
|
||||||
|
if (allProjectsForTargetName.length === 1) {
|
||||||
|
return allProjectsForTargetName;
|
||||||
|
}
|
||||||
|
|
||||||
const maybeProject = getProjectByCwd(workspace);
|
const maybeProject = getProjectByCwd(workspace);
|
||||||
if (maybeProject && allProjectsForTargetName.includes(maybeProject)) {
|
if (maybeProject && allProjectsForTargetName.includes(maybeProject)) {
|
||||||
return [maybeProject];
|
return [maybeProject];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (allProjectsForTargetName.length === 1) {
|
|
||||||
return allProjectsForTargetName;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
|
@ -333,6 +333,7 @@ export abstract class SchematicsCommandModule
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private defaultProjectDeprecationWarningShown = false;
|
||||||
private getProjectName(): string | undefined {
|
private getProjectName(): string | undefined {
|
||||||
const { workspace, logger } = this.context;
|
const { workspace, logger } = this.context;
|
||||||
if (!workspace) {
|
if (!workspace) {
|
||||||
@ -354,6 +355,15 @@ export abstract class SchematicsCommandModule
|
|||||||
|
|
||||||
const defaultProjectName = workspace.extensions['defaultProject'];
|
const defaultProjectName = workspace.extensions['defaultProject'];
|
||||||
if (typeof defaultProjectName === 'string' && defaultProjectName) {
|
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;
|
return defaultProjectName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
Adds the npm package for a published library to your workspace, and configures
|
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
|
the project in the current working directory to use that library, as specified by the library's schematic.
|
||||||
not in a project directory) to use that library, as specified by the library's schematic.
|
|
||||||
For example, adding `@angular/pwa` configures your project for PWA support:
|
For example, adding `@angular/pwa` configures your project for PWA support:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
ng add @angular/pwa
|
ng add @angular/pwa
|
||||||
```
|
```
|
||||||
|
|
||||||
The default project is the value of `defaultProject` in `angular.json`.
|
|
||||||
|
@ -263,6 +263,7 @@ function findProjectByPath(workspace: AngularWorkspace, location: string): strin
|
|||||||
return projects[0][1];
|
return projects[0][1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let defaultProjectDeprecationWarningShown = false;
|
||||||
export function getProjectByCwd(workspace: AngularWorkspace): string | null {
|
export function getProjectByCwd(workspace: AngularWorkspace): string | null {
|
||||||
if (workspace.projects.size === 1) {
|
if (workspace.projects.size === 1) {
|
||||||
// If there is only one project, return that one.
|
// 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'];
|
const defaultProject = workspace.extensions['defaultProject'];
|
||||||
if (defaultProject && typeof defaultProject === 'string') {
|
if (defaultProject && typeof defaultProject === 'string') {
|
||||||
// If there is a default project name, return it.
|
// 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;
|
return defaultProject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,10 +5,6 @@ import { updateJsonFile } from '../../utils/project';
|
|||||||
export default async function () {
|
export default async function () {
|
||||||
await ng('generate', 'app', 'secondary-app');
|
await ng('generate', 'app', 'secondary-app');
|
||||||
|
|
||||||
await updateJsonFile('angular.json', workspaceJson => {
|
|
||||||
workspaceJson.defaultProject = undefined;
|
|
||||||
});
|
|
||||||
|
|
||||||
await ng('build', 'secondary-app', '--configuration=development');
|
await ng('build', 'secondary-app', '--configuration=development');
|
||||||
|
|
||||||
expectFileToExist('dist/secondary-app/index.html');
|
expectFileToExist('dist/secondary-app/index.html');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user