Skip to content

Commit e49220f

Browse files
alan-agius4dgp1130
authored andcommitted
feat(@schematics/angular): add migratiom to remove defaultProject in workspace config
This option is deprecated in Angular CLI and will be removed in a future major version.
1 parent 4cbfb87 commit e49220f

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

packages/schematics/angular/migrations/migration-collection.json

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
"version": "14.0.0",
1515
"factory": "./update-14/remove-show-circular-dependencies-option",
1616
"description": "Remove 'showCircularDependencies' option from browser and server builders."
17+
},
18+
"remove-default-project-option": {
19+
"version": "14.0.0",
20+
"factory": "./update-14/remove-default-project-option",
21+
"description": "Remove 'defaultProject' option from workspace configuration. The project to use will be determined from the current working directory."
1722
}
1823
}
1924
}
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,51 @@
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+
import { WorkspaceSchema } from '../../utility/workspace-models';
12+
13+
describe(`Migration to remove 'defaultProject' option.`, () => {
14+
const schematicName = 'remove-default-project-option';
15+
const schematicRunner = new SchematicTestRunner(
16+
'migrations',
17+
require.resolve('../migration-collection.json'),
18+
);
19+
20+
let tree: UnitTestTree;
21+
beforeEach(() => {
22+
tree = new UnitTestTree(new EmptyTree());
23+
});
24+
25+
it(`should remove 'defaultProject'`, async () => {
26+
const angularConfig: WorkspaceSchema = {
27+
version: 1,
28+
projects: {},
29+
defaultProject: 'foo',
30+
};
31+
32+
tree.create('/angular.json', JSON.stringify(angularConfig, undefined, 2));
33+
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
34+
const { defaultProject } = JSON.parse(newTree.readContent('/angular.json'));
35+
36+
expect(defaultProject).toBeUndefined();
37+
});
38+
39+
it(`should not error when 'defaultProject' is not defined`, async () => {
40+
const angularConfig: WorkspaceSchema = {
41+
version: 1,
42+
projects: {},
43+
};
44+
45+
tree.create('/angular.json', JSON.stringify(angularConfig, undefined, 2));
46+
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
47+
const { defaultProject } = JSON.parse(newTree.readContent('/angular.json'));
48+
49+
expect(defaultProject).toBeUndefined();
50+
});
51+
});

0 commit comments

Comments
 (0)