Skip to content

Commit d58428d

Browse files
alan-agius4angular-robot[bot]
authored andcommitted
feat(@angular/cli): remove deprecated defaultProject from workspace configuration
The deprecated 'defaultProject' workspace option has been removed BREAKING CHANGE: The deprecated `defaultProject` workspace option has been removed. The project to use will be determined from the current working directory.
1 parent ada4d69 commit d58428d

File tree

17 files changed

+87
-68
lines changed

17 files changed

+87
-68
lines changed

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

-5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@
2020
"type": "string",
2121
"description": "Path where new projects will be created."
2222
},
23-
"defaultProject": {
24-
"type": "string",
25-
"description": "Default project name used in commands.",
26-
"x-deprecated": "The project to use will be determined from the current working directory."
27-
},
2823
"projects": {
2924
"type": "object",
3025
"patternProperties": {

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

-15
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,6 @@ export abstract class SchematicsCommandModule
356356
return 0;
357357
}
358358

359-
private defaultProjectDeprecationWarningShown = false;
360359
private getProjectName(): string | undefined {
361360
const { workspace, logger } = this.context;
362361
if (!workspace) {
@@ -368,20 +367,6 @@ export abstract class SchematicsCommandModule
368367
return projectName;
369368
}
370369

371-
const defaultProjectName = workspace.extensions['defaultProject'];
372-
if (typeof defaultProjectName === 'string' && defaultProjectName) {
373-
if (!this.defaultProjectDeprecationWarningShown) {
374-
logger.warn(tags.oneLine`
375-
DEPRECATED: The 'defaultProject' workspace option has been deprecated.
376-
The project to use will be determined from the current working directory.
377-
`);
378-
379-
this.defaultProjectDeprecationWarningShown = true;
380-
}
381-
382-
return defaultProjectName;
383-
}
384-
385370
return undefined;
386371
}
387372

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

-16
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,6 @@ function findProjectByPath(workspace: AngularWorkspace, location: string): strin
302302
return projects[0][1];
303303
}
304304

305-
let defaultProjectDeprecationWarningShown = false;
306305
export function getProjectByCwd(workspace: AngularWorkspace): string | null {
307306
if (workspace.projects.size === 1) {
308307
// If there is only one project, return that one.
@@ -314,21 +313,6 @@ export function getProjectByCwd(workspace: AngularWorkspace): string | null {
314313
return project;
315314
}
316315

317-
const defaultProject = workspace.extensions['defaultProject'];
318-
if (defaultProject && typeof defaultProject === 'string') {
319-
// If there is a default project name, return it.
320-
if (!defaultProjectDeprecationWarningShown) {
321-
console.warn(
322-
`DEPRECATED: The 'defaultProject' workspace option has been deprecated. ` +
323-
`The project to use will be determined from the current working directory.`,
324-
);
325-
326-
defaultProjectDeprecationWarningShown = true;
327-
}
328-
329-
return defaultProject;
330-
}
331-
332316
return null;
333317
}
334318

packages/angular_devkit/core/src/workspace/json/reader.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@ import { WorkspaceHost } from '../host';
2020
import { JsonWorkspaceMetadata, JsonWorkspaceSymbol } from './metadata';
2121
import { createVirtualAstObject } from './utilities';
2222

23-
const ANGULAR_WORKSPACE_EXTENSIONS = Object.freeze([
24-
'cli',
25-
'defaultProject',
26-
'newProjectRoot',
27-
'schematics',
28-
]);
23+
const ANGULAR_WORKSPACE_EXTENSIONS = Object.freeze(['cli', 'newProjectRoot', 'schematics']);
2924
const ANGULAR_PROJECT_EXTENSIONS = Object.freeze(['cli', 'schematics', 'projectType', 'i18n']);
3025

3126
interface ParserContext {

packages/angular_devkit/core/src/workspace/json/reader_spec.ts

-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ describe('readJsonWorkpace Parsing', () => {
7777

7878
expect(Array.from(workspace.projects.keys())).toEqual(['my-app', 'my-app-e2e']);
7979
expect(workspace.extensions['newProjectRoot']).toBe('projects');
80-
expect(workspace.extensions['defaultProject']).toBe('my-app');
8180
expect(workspace.projects.get('my-app')!.extensions['schematics']).toEqual({
8281
'@schematics/angular:component': { styleext: 'scss' },
8382
});

packages/angular_devkit/core/src/workspace/json/test/angular.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,5 @@
133133
}
134134
}
135135
}
136-
},
137-
"defaultProject": "my-app"
138-
}
136+
}
137+
}

packages/angular_devkit/core/src/workspace/json/test/cases/AddProject2.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,5 @@
136136
"new": {
137137
"root": "src"
138138
}
139-
},
140-
"defaultProject": "my-app"
141-
}
139+
}
140+
}

packages/angular_devkit/core/src/workspace/json/test/cases/AddProject3.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,5 @@
136136
"1": {
137137
"root": "src"
138138
}
139-
},
140-
"defaultProject": "my-app"
139+
}
141140
}

packages/angular_devkit/core/src/workspace/json/test/cases/ProjectAddTarget.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,5 @@
136136
}
137137
}
138138
}
139-
},
140-
"defaultProject": "my-app"
141-
}
139+
}
140+
}

packages/angular_devkit/core/src/workspace/json/test/cases/ProjectDeleteTarget.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,5 @@
127127
}
128128
}
129129
}
130-
},
131-
"defaultProject": "my-app"
132-
}
130+
}
131+
}

packages/angular_devkit/core/src/workspace/json/test/cases/ProjectModifyProperties.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,5 @@
133133
}
134134
}
135135
}
136-
},
137-
"defaultProject": "my-app"
138-
}
136+
}
137+
}

packages/angular_devkit/core/src/workspace/json/test/cases/ProjectSetProperties.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,5 @@
134134
}
135135
}
136136
}
137-
},
138-
"defaultProject": "my-app"
139-
}
137+
}
138+
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
22
"schematics": {
3-
3+
"remove-default-project-option": {
4+
"version": "16.0.0",
5+
"factory": "./update-16/remove-default-project-option",
6+
"description": "Remove 'defaultProject' option from workspace configuration. The project to use will be determined from the current working directory."
7+
}
48
}
59
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import { Rule } from '@angular-devkit/schematics';
10+
import { updateWorkspace } from '../../utility/workspace';
11+
12+
/** Migration to remove 'defaultProject' option from angular.json. */
13+
export default function (): Rule {
14+
return updateWorkspace((workspace) => {
15+
delete workspace.extensions['defaultProject'];
16+
});
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import { EmptyTree } from '@angular-devkit/schematics';
10+
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
11+
12+
describe(`Migration to remove 'defaultProject' option.`, () => {
13+
const schematicName = 'remove-default-project-option';
14+
const schematicRunner = new SchematicTestRunner(
15+
'migrations',
16+
require.resolve('../migration-collection.json'),
17+
);
18+
19+
let tree: UnitTestTree;
20+
beforeEach(() => {
21+
tree = new UnitTestTree(new EmptyTree());
22+
});
23+
24+
it(`should remove 'defaultProject'`, async () => {
25+
const angularConfig = {
26+
version: 1,
27+
projects: {},
28+
defaultProject: 'foo',
29+
};
30+
31+
tree.create('/angular.json', JSON.stringify(angularConfig, undefined, 2));
32+
const newTree = await schematicRunner.runSchematic(schematicName, {}, tree);
33+
const { defaultProject } = JSON.parse(newTree.readContent('/angular.json'));
34+
35+
expect(defaultProject).toBeUndefined();
36+
});
37+
38+
it(`should not error when 'defaultProject' is not defined`, async () => {
39+
const angularConfig = {
40+
version: 1,
41+
projects: {},
42+
};
43+
44+
tree.create('/angular.json', JSON.stringify(angularConfig, undefined, 2));
45+
const newTree = await schematicRunner.runSchematic(schematicName, {}, tree);
46+
const { defaultProject } = JSON.parse(newTree.readContent('/angular.json'));
47+
48+
expect(defaultProject).toBeUndefined();
49+
});
50+
});

packages/schematics/angular/utility/workspace-models.ts

-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ interface WorkspaceCLISchema {
142142
}
143143
export interface WorkspaceSchema {
144144
version: 1;
145-
defaultProject?: string;
146145
cli?: WorkspaceCLISchema;
147146
projects: {
148147
[key: string]: WorkspaceProject<ProjectType.Application | ProjectType.Library>;

tests/legacy-cli/e2e/assets/13.0-project/angular.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,4 @@
113113
}
114114
}
115115
}
116-
},
117-
"defaultProject": "thirteen-project"
118-
}
116+
}}

0 commit comments

Comments
 (0)