From d58428d3dbdb7275e2e4f6d271fcc5fdda5c489e Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Fri, 17 Feb 2023 13:04:05 +0000 Subject: [PATCH] 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. --- .../cli/lib/config/workspace-schema.json | 5 -- .../schematics-command-module.ts | 15 ------ packages/angular/cli/src/utilities/config.ts | 16 ------ .../core/src/workspace/json/reader.ts | 7 +-- .../core/src/workspace/json/reader_spec.ts | 1 - .../core/src/workspace/json/test/angular.json | 5 +- .../json/test/cases/AddProject2.json | 5 +- .../json/test/cases/AddProject3.json | 3 +- .../json/test/cases/ProjectAddTarget.json | 5 +- .../json/test/cases/ProjectDeleteTarget.json | 5 +- .../test/cases/ProjectModifyProperties.json | 5 +- .../json/test/cases/ProjectSetProperties.json | 5 +- .../migrations/migration-collection.json | 6 ++- .../remove-default-project-option.ts | 17 +++++++ .../remove-default-project-option_spec.ts | 50 +++++++++++++++++++ .../angular/utility/workspace-models.ts | 1 - .../e2e/assets/13.0-project/angular.json | 4 +- 17 files changed, 87 insertions(+), 68 deletions(-) create mode 100644 packages/schematics/angular/migrations/update-16/remove-default-project-option.ts create mode 100644 packages/schematics/angular/migrations/update-16/remove-default-project-option_spec.ts diff --git a/packages/angular/cli/lib/config/workspace-schema.json b/packages/angular/cli/lib/config/workspace-schema.json index a50caa1bd33d..8e74184ade47 100644 --- a/packages/angular/cli/lib/config/workspace-schema.json +++ b/packages/angular/cli/lib/config/workspace-schema.json @@ -20,11 +20,6 @@ "type": "string", "description": "Path where new projects will be created." }, - "defaultProject": { - "type": "string", - "description": "Default project name used in commands.", - "x-deprecated": "The project to use will be determined from the current working directory." - }, "projects": { "type": "object", "patternProperties": { diff --git a/packages/angular/cli/src/command-builder/schematics-command-module.ts b/packages/angular/cli/src/command-builder/schematics-command-module.ts index 59f4b1cda89f..7368da0759cc 100644 --- a/packages/angular/cli/src/command-builder/schematics-command-module.ts +++ b/packages/angular/cli/src/command-builder/schematics-command-module.ts @@ -356,7 +356,6 @@ export abstract class SchematicsCommandModule return 0; } - private defaultProjectDeprecationWarningShown = false; private getProjectName(): string | undefined { const { workspace, logger } = this.context; if (!workspace) { @@ -368,20 +367,6 @@ export abstract class SchematicsCommandModule return projectName; } - const defaultProjectName = workspace.extensions['defaultProject']; - 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 undefined; } diff --git a/packages/angular/cli/src/utilities/config.ts b/packages/angular/cli/src/utilities/config.ts index 54576c8dc1ef..b4d3a99729ea 100644 --- a/packages/angular/cli/src/utilities/config.ts +++ b/packages/angular/cli/src/utilities/config.ts @@ -302,7 +302,6 @@ function findProjectByPath(workspace: AngularWorkspace, location: string): strin return projects[0][1]; } -let defaultProjectDeprecationWarningShown = false; export function getProjectByCwd(workspace: AngularWorkspace): string | null { if (workspace.projects.size === 1) { // If there is only one project, return that one. @@ -314,21 +313,6 @@ export function getProjectByCwd(workspace: AngularWorkspace): string | null { return project; } - const defaultProject = workspace.extensions['defaultProject']; - if (defaultProject && typeof defaultProject === 'string') { - // 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 null; } diff --git a/packages/angular_devkit/core/src/workspace/json/reader.ts b/packages/angular_devkit/core/src/workspace/json/reader.ts index 1b60ff10231a..3a0cb45fb4ca 100644 --- a/packages/angular_devkit/core/src/workspace/json/reader.ts +++ b/packages/angular_devkit/core/src/workspace/json/reader.ts @@ -20,12 +20,7 @@ import { WorkspaceHost } from '../host'; import { JsonWorkspaceMetadata, JsonWorkspaceSymbol } from './metadata'; import { createVirtualAstObject } from './utilities'; -const ANGULAR_WORKSPACE_EXTENSIONS = Object.freeze([ - 'cli', - 'defaultProject', - 'newProjectRoot', - 'schematics', -]); +const ANGULAR_WORKSPACE_EXTENSIONS = Object.freeze(['cli', 'newProjectRoot', 'schematics']); const ANGULAR_PROJECT_EXTENSIONS = Object.freeze(['cli', 'schematics', 'projectType', 'i18n']); interface ParserContext { diff --git a/packages/angular_devkit/core/src/workspace/json/reader_spec.ts b/packages/angular_devkit/core/src/workspace/json/reader_spec.ts index 5b80cc50d92b..8ad9f953ee80 100644 --- a/packages/angular_devkit/core/src/workspace/json/reader_spec.ts +++ b/packages/angular_devkit/core/src/workspace/json/reader_spec.ts @@ -77,7 +77,6 @@ describe('readJsonWorkpace Parsing', () => { expect(Array.from(workspace.projects.keys())).toEqual(['my-app', 'my-app-e2e']); expect(workspace.extensions['newProjectRoot']).toBe('projects'); - expect(workspace.extensions['defaultProject']).toBe('my-app'); expect(workspace.projects.get('my-app')!.extensions['schematics']).toEqual({ '@schematics/angular:component': { styleext: 'scss' }, }); diff --git a/packages/angular_devkit/core/src/workspace/json/test/angular.json b/packages/angular_devkit/core/src/workspace/json/test/angular.json index 91355ed28c64..f71726e4aba1 100644 --- a/packages/angular_devkit/core/src/workspace/json/test/angular.json +++ b/packages/angular_devkit/core/src/workspace/json/test/angular.json @@ -133,6 +133,5 @@ } } } - }, - "defaultProject": "my-app" -} \ No newline at end of file + } +} diff --git a/packages/angular_devkit/core/src/workspace/json/test/cases/AddProject2.json b/packages/angular_devkit/core/src/workspace/json/test/cases/AddProject2.json index 996aa07027b5..7c2dd6785183 100644 --- a/packages/angular_devkit/core/src/workspace/json/test/cases/AddProject2.json +++ b/packages/angular_devkit/core/src/workspace/json/test/cases/AddProject2.json @@ -136,6 +136,5 @@ "new": { "root": "src" } - }, - "defaultProject": "my-app" -} \ No newline at end of file + } +} diff --git a/packages/angular_devkit/core/src/workspace/json/test/cases/AddProject3.json b/packages/angular_devkit/core/src/workspace/json/test/cases/AddProject3.json index 1766edbd5fb3..f025b8ffc0bd 100644 --- a/packages/angular_devkit/core/src/workspace/json/test/cases/AddProject3.json +++ b/packages/angular_devkit/core/src/workspace/json/test/cases/AddProject3.json @@ -136,6 +136,5 @@ "1": { "root": "src" } - }, - "defaultProject": "my-app" + } } diff --git a/packages/angular_devkit/core/src/workspace/json/test/cases/ProjectAddTarget.json b/packages/angular_devkit/core/src/workspace/json/test/cases/ProjectAddTarget.json index 134b0d3e55f7..96cc5437c042 100644 --- a/packages/angular_devkit/core/src/workspace/json/test/cases/ProjectAddTarget.json +++ b/packages/angular_devkit/core/src/workspace/json/test/cases/ProjectAddTarget.json @@ -136,6 +136,5 @@ } } } - }, - "defaultProject": "my-app" -} \ No newline at end of file + } +} diff --git a/packages/angular_devkit/core/src/workspace/json/test/cases/ProjectDeleteTarget.json b/packages/angular_devkit/core/src/workspace/json/test/cases/ProjectDeleteTarget.json index 86c9abf09947..810ed7dc1f4e 100644 --- a/packages/angular_devkit/core/src/workspace/json/test/cases/ProjectDeleteTarget.json +++ b/packages/angular_devkit/core/src/workspace/json/test/cases/ProjectDeleteTarget.json @@ -127,6 +127,5 @@ } } } - }, - "defaultProject": "my-app" -} \ No newline at end of file + } +} diff --git a/packages/angular_devkit/core/src/workspace/json/test/cases/ProjectModifyProperties.json b/packages/angular_devkit/core/src/workspace/json/test/cases/ProjectModifyProperties.json index 1a5487dac5d9..a1628aafec9e 100644 --- a/packages/angular_devkit/core/src/workspace/json/test/cases/ProjectModifyProperties.json +++ b/packages/angular_devkit/core/src/workspace/json/test/cases/ProjectModifyProperties.json @@ -133,6 +133,5 @@ } } } - }, - "defaultProject": "my-app" -} \ No newline at end of file + } +} diff --git a/packages/angular_devkit/core/src/workspace/json/test/cases/ProjectSetProperties.json b/packages/angular_devkit/core/src/workspace/json/test/cases/ProjectSetProperties.json index b80273cdbb0a..21bf85ba9544 100644 --- a/packages/angular_devkit/core/src/workspace/json/test/cases/ProjectSetProperties.json +++ b/packages/angular_devkit/core/src/workspace/json/test/cases/ProjectSetProperties.json @@ -134,6 +134,5 @@ } } } - }, - "defaultProject": "my-app" -} \ No newline at end of file + } +} diff --git a/packages/schematics/angular/migrations/migration-collection.json b/packages/schematics/angular/migrations/migration-collection.json index 7daec3f27120..acee4359cfda 100644 --- a/packages/schematics/angular/migrations/migration-collection.json +++ b/packages/schematics/angular/migrations/migration-collection.json @@ -1,5 +1,9 @@ { "schematics": { - + "remove-default-project-option": { + "version": "16.0.0", + "factory": "./update-16/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-16/remove-default-project-option.ts b/packages/schematics/angular/migrations/update-16/remove-default-project-option.ts new file mode 100644 index 000000000000..2a7c04475e17 --- /dev/null +++ b/packages/schematics/angular/migrations/update-16/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-16/remove-default-project-option_spec.ts b/packages/schematics/angular/migrations/update-16/remove-default-project-option_spec.ts new file mode 100644 index 000000000000..6bec5773eead --- /dev/null +++ b/packages/schematics/angular/migrations/update-16/remove-default-project-option_spec.ts @@ -0,0 +1,50 @@ +/** + * @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'; + +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 = { + version: 1, + projects: {}, + defaultProject: 'foo', + }; + + tree.create('/angular.json', JSON.stringify(angularConfig, undefined, 2)); + const newTree = await schematicRunner.runSchematic(schematicName, {}, tree); + const { defaultProject } = JSON.parse(newTree.readContent('/angular.json')); + + expect(defaultProject).toBeUndefined(); + }); + + it(`should not error when 'defaultProject' is not defined`, async () => { + const angularConfig = { + version: 1, + projects: {}, + }; + + tree.create('/angular.json', JSON.stringify(angularConfig, undefined, 2)); + const newTree = await schematicRunner.runSchematic(schematicName, {}, tree); + const { defaultProject } = JSON.parse(newTree.readContent('/angular.json')); + + expect(defaultProject).toBeUndefined(); + }); +}); diff --git a/packages/schematics/angular/utility/workspace-models.ts b/packages/schematics/angular/utility/workspace-models.ts index fb7f18c3f7cd..fbb0ecc48abb 100644 --- a/packages/schematics/angular/utility/workspace-models.ts +++ b/packages/schematics/angular/utility/workspace-models.ts @@ -142,7 +142,6 @@ interface WorkspaceCLISchema { } export interface WorkspaceSchema { version: 1; - defaultProject?: string; cli?: WorkspaceCLISchema; projects: { [key: string]: WorkspaceProject; diff --git a/tests/legacy-cli/e2e/assets/13.0-project/angular.json b/tests/legacy-cli/e2e/assets/13.0-project/angular.json index c842d2bdf7c8..d17ec1cf724a 100644 --- a/tests/legacy-cli/e2e/assets/13.0-project/angular.json +++ b/tests/legacy-cli/e2e/assets/13.0-project/angular.json @@ -113,6 +113,4 @@ } } } - }, - "defaultProject": "thirteen-project" -} + }}