From 0a1cd584d8ed00889b177f4284baec7e5427caf2 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Fri, 28 Jan 2022 14:02:30 +0100 Subject: [PATCH] refactor(@angular-devkit/build-angular): remove deprecated `showCircularDependencies` browser and server builder option BREAKING CHANGE: The deprecated `showCircularDependencies` browser and server builder option has been removed. The recommended method to detect circular dependencies in project code is to use either a lint rule or other external tools. --- .../angular_devkit/build_angular/src/index.md | 4 - package.json | 1 - .../angular_devkit/build_angular/BUILD.bazel | 1 - .../angular_devkit/build_angular/package.json | 1 - .../src/builders/browser/schema.json | 6 -- .../show-circular-dependencies_spec.ts | 70 ---------------- .../src/builders/server/schema.json | 6 -- .../build_angular/src/utils/build-options.ts | 1 - .../src/webpack/configs/common.ts | 9 -- .../migrations/migration-collection.json | 5 ++ ...emove-show-circular-dependencies-option.ts | 28 +++++++ ...-show-circular-dependencies-option_spec.ts | 82 +++++++++++++++++++ .../e2e/tests/misc/circular-dependency.ts | 14 ---- 13 files changed, 115 insertions(+), 113 deletions(-) delete mode 100644 packages/angular_devkit/build_angular/src/builders/browser/tests/options/show-circular-dependencies_spec.ts create mode 100644 packages/schematics/angular/migrations/update-14/remove-show-circular-dependencies-option.ts create mode 100644 packages/schematics/angular/migrations/update-14/remove-show-circular-dependencies-option_spec.ts delete mode 100644 tests/legacy-cli/e2e/tests/misc/circular-dependency.ts diff --git a/goldens/public-api/angular_devkit/build_angular/src/index.md b/goldens/public-api/angular_devkit/build_angular/src/index.md index d9223abf1a..a8e8037a21 100644 --- a/goldens/public-api/angular_devkit/build_angular/src/index.md +++ b/goldens/public-api/angular_devkit/build_angular/src/index.md @@ -61,8 +61,6 @@ export interface BrowserBuilderOptions { resourcesOutputPath?: string; scripts?: ScriptElement[]; serviceWorker?: boolean; - // @deprecated - showCircularDependencies?: boolean; sourceMap?: SourceMapUnion; statsJson?: boolean; stylePreprocessorOptions?: StylePreprocessorOptions; @@ -263,8 +261,6 @@ export interface ServerBuilderOptions { preserveSymlinks?: boolean; progress?: boolean; resourcesOutputPath?: string; - // @deprecated - showCircularDependencies?: boolean; sourceMap?: SourceMapUnion_3; statsJson?: boolean; stylePreprocessorOptions?: StylePreprocessorOptions_3; diff --git a/package.json b/package.json index 7e1e48e8f7..eaa69ec67f 100644 --- a/package.json +++ b/package.json @@ -128,7 +128,6 @@ "browserslist": "^4.9.1", "cacache": "15.3.0", "chokidar": "^3.5.2", - "circular-dependency-plugin": "5.2.2", "common-tags": "^1.8.0", "conventional-commits-parser": "^3.0.0", "copy-webpack-plugin": "10.2.1", diff --git a/packages/angular_devkit/build_angular/BUILD.bazel b/packages/angular_devkit/build_angular/BUILD.bazel index 1318fa9175..748dde42e8 100644 --- a/packages/angular_devkit/build_angular/BUILD.bazel +++ b/packages/angular_devkit/build_angular/BUILD.bazel @@ -130,7 +130,6 @@ ts_library( "@npm//babel-plugin-istanbul", "@npm//browserslist", "@npm//cacache", - "@npm//circular-dependency-plugin", "@npm//copy-webpack-plugin", "@npm//core-js", "@npm//critters", diff --git a/packages/angular_devkit/build_angular/package.json b/packages/angular_devkit/build_angular/package.json index b90a3fb569..bb72e0dcfc 100644 --- a/packages/angular_devkit/build_angular/package.json +++ b/packages/angular_devkit/build_angular/package.json @@ -26,7 +26,6 @@ "babel-plugin-istanbul": "6.1.1", "browserslist": "^4.9.1", "cacache": "15.3.0", - "circular-dependency-plugin": "5.2.2", "copy-webpack-plugin": "10.2.1", "core-js": "3.20.3", "critters": "0.0.16", diff --git a/packages/angular_devkit/build_angular/src/builders/browser/schema.json b/packages/angular_devkit/build_angular/src/builders/browser/schema.json index 6281b1b2c8..6fb2c20b91 100644 --- a/packages/angular_devkit/build_angular/src/builders/browser/schema.json +++ b/packages/angular_devkit/build_angular/src/builders/browser/schema.json @@ -329,12 +329,6 @@ "description": "Extract all licenses in a separate file.", "default": true }, - "showCircularDependencies": { - "type": "boolean", - "description": "Show circular dependency warnings on builds.", - "default": false, - "x-deprecated": "The recommended method to detect circular dependencies in project code is to use either a lint rule or other external tooling." - }, "buildOptimizer": { "type": "boolean", "description": "Enables advanced build optimizations when using the 'aot' option.", diff --git a/packages/angular_devkit/build_angular/src/builders/browser/tests/options/show-circular-dependencies_spec.ts b/packages/angular_devkit/build_angular/src/builders/browser/tests/options/show-circular-dependencies_spec.ts deleted file mode 100644 index 491df3956c..0000000000 --- a/packages/angular_devkit/build_angular/src/builders/browser/tests/options/show-circular-dependencies_spec.ts +++ /dev/null @@ -1,70 +0,0 @@ -/** - * @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 { logging } from '@angular-devkit/core'; -import { buildWebpackBrowser } from '../../index'; -import { BASE_OPTIONS, BROWSER_BUILDER_INFO, describeBuilder } from '../setup'; - -describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => { - describe('Option: "showCircularDependencies"', () => { - beforeEach(async () => { - // Add circular dependency - await harness.appendToFile( - 'src/app/app.component.ts', - `import { AppModule } from './app.module'; console.log(AppModule);`, - ); - }); - - it('should show cyclic dependency warning when option is set to true', async () => { - harness.useTarget('build', { - ...BASE_OPTIONS, - showCircularDependencies: true, - }); - - const { result, logs } = await harness.executeOnce(); - - expect(result?.success).toBe(true); - expect(logs).toContain( - jasmine.objectContaining({ - message: jasmine.stringMatching(/Circular dependency detected/), - }), - ); - }); - - it('should not show cyclic dependency warning when option is set to false', async () => { - harness.useTarget('build', { - ...BASE_OPTIONS, - showCircularDependencies: false, - }); - - const { result, logs } = await harness.executeOnce(); - - expect(result?.success).toBe(true); - expect(logs).not.toContain( - jasmine.objectContaining({ - message: jasmine.stringMatching(/Circular dependency detected/), - }), - ); - }); - - it('should not show cyclic dependency warning when option is not present', async () => { - harness.useTarget('build', { - ...BASE_OPTIONS, - }); - - const { result, logs } = await harness.executeOnce(); - - expect(result?.success).toBe(true); - expect(logs).not.toContain( - jasmine.objectContaining({ - message: jasmine.stringMatching(/Circular dependency detected/), - }), - ); - }); - }); -}); diff --git a/packages/angular_devkit/build_angular/src/builders/server/schema.json b/packages/angular_devkit/build_angular/src/builders/server/schema.json index d4c68ecf16..17754d0718 100644 --- a/packages/angular_devkit/build_angular/src/builders/server/schema.json +++ b/packages/angular_devkit/build_angular/src/builders/server/schema.json @@ -177,12 +177,6 @@ "description": "Extract all licenses in a separate file, in the case of production builds only.", "default": true }, - "showCircularDependencies": { - "type": "boolean", - "description": "Show circular dependency warnings on builds.", - "default": false, - "x-deprecated": "The recommended method to detect circular dependencies in project code is to use either a lint rule or other external tooling." - }, "namedChunks": { "type": "boolean", "description": "Use file name for lazy loaded chunks.", diff --git a/packages/angular_devkit/build_angular/src/utils/build-options.ts b/packages/angular_devkit/build_angular/src/utils/build-options.ts index a3789254ff..2a4e99cee6 100644 --- a/packages/angular_devkit/build_angular/src/utils/build-options.ts +++ b/packages/angular_devkit/build_angular/src/utils/build-options.ts @@ -49,7 +49,6 @@ export interface BuildOptions { deleteOutputPath?: boolean; preserveSymlinks?: boolean; extractLicenses?: boolean; - showCircularDependencies?: boolean; buildOptimizer?: boolean; namedChunks?: boolean; crossOrigin?: CrossOrigin; diff --git a/packages/angular_devkit/build_angular/src/webpack/configs/common.ts b/packages/angular_devkit/build_angular/src/webpack/configs/common.ts index e19db3fb4c..6ae34fe394 100644 --- a/packages/angular_devkit/build_angular/src/webpack/configs/common.ts +++ b/packages/angular_devkit/build_angular/src/webpack/configs/common.ts @@ -173,15 +173,6 @@ export async function getCommonConfig(wco: WebpackConfigOptions): Promise { + for (const project of workspace.projects.values()) { + for (const target of project.targets.values()) { + if ( + target.builder === '@angular-devkit/build-angular:server' || + target.builder === '@angular-devkit/build-angular:browser' + ) { + for (const [, options] of allTargetOptions(target)) { + delete options.showCircularDependencies; + } + } + } + } + }); +} diff --git a/packages/schematics/angular/migrations/update-14/remove-show-circular-dependencies-option_spec.ts b/packages/schematics/angular/migrations/update-14/remove-show-circular-dependencies-option_spec.ts new file mode 100644 index 0000000000..e8b05dd05c --- /dev/null +++ b/packages/schematics/angular/migrations/update-14/remove-show-circular-dependencies-option_spec.ts @@ -0,0 +1,82 @@ +/** + * @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 { JsonObject } from '@angular-devkit/core'; +import { EmptyTree } from '@angular-devkit/schematics'; +import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing'; +import { + BuilderTarget, + Builders, + ProjectType, + WorkspaceSchema, +} from '../../utility/workspace-models'; + +function getBuildTarget(tree: UnitTestTree): BuilderTarget { + return JSON.parse(tree.readContent('/angular.json')).projects.app.architect.build; +} + +function createWorkSpaceConfig(tree: UnitTestTree) { + const angularConfig: WorkspaceSchema = { + version: 1, + projects: { + app: { + root: '', + sourceRoot: 'src', + projectType: ProjectType.Application, + prefix: 'app', + architect: { + build: { + builder: Builders.Browser, + options: { + extractCss: false, + showCircularDependencies: true, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + } as any, + configurations: { + one: { + showCircularDependencies: false, + aot: true, + }, + two: { + showCircularDependencies: false, + aot: true, + }, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + } as any, + }, + }, + }, + }, + }; + + tree.create('/angular.json', JSON.stringify(angularConfig, undefined, 2)); +} + +describe(`Migration to remove 'showCircularDependencies' option.`, () => { + const schematicName = 'remove-show-circular-dependencies-option'; + const schematicRunner = new SchematicTestRunner( + 'migrations', + require.resolve('../migration-collection.json'), + ); + + let tree: UnitTestTree; + beforeEach(() => { + tree = new UnitTestTree(new EmptyTree()); + createWorkSpaceConfig(tree); + }); + + it(`should remove 'showCircularDependencies'`, async () => { + const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise(); + const { options, configurations } = getBuildTarget(newTree); + + expect(options.showCircularDependencies).toBeUndefined(); + expect(configurations).toBeDefined(); + expect(configurations?.one.showCircularDependencies).toBeUndefined(); + expect(configurations?.two.showCircularDependencies).toBeUndefined(); + }); +}); diff --git a/tests/legacy-cli/e2e/tests/misc/circular-dependency.ts b/tests/legacy-cli/e2e/tests/misc/circular-dependency.ts deleted file mode 100644 index 0b1e4c8e49..0000000000 --- a/tests/legacy-cli/e2e/tests/misc/circular-dependency.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { prependToFile } from '../../utils/fs'; -import { ng } from '../../utils/process'; - - -export default async function () { - // TODO(architect): Delete this test. It is now in devkit/build-angular. - - await prependToFile('src/app/app.component.ts', - `import { AppModule } from './app.module'; console.log(AppModule);`); - const { stderr } = await ng('build', '--show-circular-dependencies', '--configuration=development'); - if (!stderr.match(/Warning: Circular dependency detected/)) { - throw new Error('Expected to have circular dependency warning in output.'); - } -}