From e49220fba0d158be0971989e26eb199ec02fa113 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Fri, 18 Mar 2022 13:43:26 +0100 Subject: [PATCH] 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. --- .../migrations/migration-collection.json | 5 ++ .../remove-default-project-option.ts | 17 +++++++ .../remove-default-project-option_spec.ts | 51 +++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 packages/schematics/angular/migrations/update-14/remove-default-project-option.ts create mode 100644 packages/schematics/angular/migrations/update-14/remove-default-project-option_spec.ts diff --git a/packages/schematics/angular/migrations/migration-collection.json b/packages/schematics/angular/migrations/migration-collection.json index e0ef67b80b39..747cfc8c74d8 100644 --- a/packages/schematics/angular/migrations/migration-collection.json +++ b/packages/schematics/angular/migrations/migration-collection.json @@ -14,6 +14,11 @@ "version": "14.0.0", "factory": "./update-14/remove-show-circular-dependencies-option", "description": "Remove 'showCircularDependencies' option from browser and server builders." + }, + "remove-default-project-option": { + "version": "14.0.0", + "factory": "./update-14/remove-default-project-option", + "description": "Remove 'defaultProject' option from workspace configuration. The project to use will be determined from the current working directory." } } } diff --git a/packages/schematics/angular/migrations/update-14/remove-default-project-option.ts b/packages/schematics/angular/migrations/update-14/remove-default-project-option.ts new file mode 100644 index 000000000000..2a7c04475e17 --- /dev/null +++ b/packages/schematics/angular/migrations/update-14/remove-default-project-option.ts @@ -0,0 +1,17 @@ +/** + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +import { Rule } from '@angular-devkit/schematics'; +import { updateWorkspace } from '../../utility/workspace'; + +/** Migration to remove 'defaultProject' option from angular.json. */ +export default function (): Rule { + return updateWorkspace((workspace) => { + delete workspace.extensions['defaultProject']; + }); +} diff --git a/packages/schematics/angular/migrations/update-14/remove-default-project-option_spec.ts b/packages/schematics/angular/migrations/update-14/remove-default-project-option_spec.ts new file mode 100644 index 000000000000..7b6eef0c4b30 --- /dev/null +++ b/packages/schematics/angular/migrations/update-14/remove-default-project-option_spec.ts @@ -0,0 +1,51 @@ +/** + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +import { EmptyTree } from '@angular-devkit/schematics'; +import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing'; +import { WorkspaceSchema } from '../../utility/workspace-models'; + +describe(`Migration to remove 'defaultProject' option.`, () => { + const schematicName = 'remove-default-project-option'; + const schematicRunner = new SchematicTestRunner( + 'migrations', + require.resolve('../migration-collection.json'), + ); + + let tree: UnitTestTree; + beforeEach(() => { + tree = new UnitTestTree(new EmptyTree()); + }); + + it(`should remove 'defaultProject'`, async () => { + const angularConfig: WorkspaceSchema = { + version: 1, + projects: {}, + defaultProject: 'foo', + }; + + tree.create('/angular.json', JSON.stringify(angularConfig, undefined, 2)); + const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise(); + const { defaultProject } = JSON.parse(newTree.readContent('/angular.json')); + + expect(defaultProject).toBeUndefined(); + }); + + it(`should not error when 'defaultProject' is not defined`, async () => { + const angularConfig: WorkspaceSchema = { + version: 1, + projects: {}, + }; + + tree.create('/angular.json', JSON.stringify(angularConfig, undefined, 2)); + const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise(); + const { defaultProject } = JSON.parse(newTree.readContent('/angular.json')); + + expect(defaultProject).toBeUndefined(); + }); +});