Skip to content

Deprecate defaultProject #12394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/documentation/angular-workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

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

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

- **cli**: Workspace configuration options for Angular CLI.
- *defaultCollection* (`string`): The default schematics collection to use.
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/cli/lib/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"defaultProject": {
"type": "string",
"description": "Default project name used in commands."
"description": "(DEPRECATED) Default project name used in commands."
},
"projects": {
"type": "object",
Expand Down
9 changes: 5 additions & 4 deletions packages/angular/cli/models/architect-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { experimental, json, schema, tags } from '@angular-devkit/core';
import { NodeJsSyncHost, createConsoleLogger } from '@angular-devkit/core/node';
import { from } from 'rxjs';
import { concatMap, map, tap, toArray } from 'rxjs/operators';
import { getProjectByCwd } from '../utilities/config';
import { parseJsonSchemaToOptions } from '../utilities/json-schema';
import { BaseCommandOptions, Command } from './command';
import { Arguments } from './interface';
Expand Down Expand Up @@ -212,11 +213,11 @@ export abstract class ArchitectCommand<
// For multi target commands, we always list all projects that have the target.
return allProjectsForTargetName;
} else {
// For single target commands, we try the default project first,
// For single target commands, we try the current project first,
// then the full list if it has a single project, then error out.
const maybeDefaultProject = this._workspace.getDefaultProjectName();
if (maybeDefaultProject && allProjectsForTargetName.includes(maybeDefaultProject)) {
return [maybeDefaultProject];
const maybeCurrentProject = getProjectByCwd(this._workspace, this.logger);
if (maybeCurrentProject && allProjectsForTargetName.includes(maybeCurrentProject)) {
return [maybeCurrentProject];
}

if (allProjectsForTargetName.length === 1) {
Expand Down
16 changes: 1 addition & 15 deletions packages/angular/cli/models/schematic-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,21 +271,7 @@ export abstract class SchematicCommand<

workflow.registry.addSmartDefaultProvider('projectName', () => {
if (this._workspace) {
try {
return this._workspace.getProjectByPath(normalize(process.cwd()))
|| this._workspace.getDefaultProjectName();
} catch (e) {
if (e instanceof experimental.workspace.AmbiguousProjectPathException) {
this.logger.warn(tags.oneLine`
Two or more projects are using identical roots.
Unable to determine project using current working directory.
Using default workspace project instead.
`);

return this._workspace.getDefaultProjectName();
}
throw e;
}
return getProjectByCwd(this._workspace, this.logger);
}

return undefined;
Expand Down
14 changes: 13 additions & 1 deletion packages/angular/cli/utilities/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import {
JsonObject,
JsonParseMode,
experimental,
logging,
normalize,
parseJson,
parseJsonAst,
tags,
virtualFs,
} from '@angular-devkit/core';
import { NodeJsSyncHost } from '@angular-devkit/core/node';
Expand Down Expand Up @@ -140,11 +142,21 @@ export function validateWorkspace(json: JsonObject) {
return true;
}

export function getProjectByCwd(workspace: experimental.workspace.Workspace): string | null {
export function getProjectByCwd(
workspace: experimental.workspace.Workspace,
logger: logging.Logger = new logging.NullLogger(),
): string | null {
try {
return workspace.getProjectByPath(normalize(process.cwd()));
} catch (e) {
if (e instanceof experimental.workspace.AmbiguousProjectPathException) {
logger.warn(tags.oneLine`
Two or more projects are using identical roots.
Unable to determine project using current working directory.
Using default workspace project instead.
`);
logger.warn(`The defaultProject property is DEPRECATED and will be removed in CLI v8.`);

return workspace.getDefaultProjectName();
}
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"defaultProject": {
"type": "string",
"description": "The default project."
"description": "(DEPRECATED) The default project."
},
"cli": {
"$ref": "#/definitions/tool",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface WorkspaceSchema {
*/
newProjectRoot?: string;
/**
* @deprecated From 7.0.0
* The default project.
*/
defaultProject?: string;
Expand Down
3 changes: 3 additions & 0 deletions packages/angular_devkit/core/src/workspace/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ export class Workspace {
return workspaceProjectClone;
}

/**
* @deprecated From 7.0.0
*/
getDefaultProjectName(): string | null {
this._assertLoaded();

Expand Down