From ecab6b5ad8dbd285324f06dd2ae90976bb66a778 Mon Sep 17 00:00:00 2001
From: Filipe Silva <filipematossilva@gmail.com>
Date: Thu, 29 Jun 2017 15:36:57 +0100
Subject: [PATCH] feat(@angular/cli): followup changes to circular dependency
 detection

Flag is now positive instead of negative and shorter, and can now be set on commands as well (`--show-circular-dependencies`).

Dependency was also added to eject as per https://github.com/angular/angular-cli/pull/6813#issuecomment-311567074.
---
 docs/documentation/angular-cli.md                      |  2 +-
 docs/documentation/build.md                            | 10 ++++++++++
 packages/@angular/cli/commands/build.ts                |  7 +++++++
 packages/@angular/cli/lib/config/schema.json           |  6 +++---
 packages/@angular/cli/models/build-options.ts          |  1 +
 packages/@angular/cli/models/webpack-configs/common.ts |  2 +-
 packages/@angular/cli/tasks/eject.ts                   |  1 +
 tests/e2e/tests/misc/circular-dependency.ts            |  4 ++--
 8 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/docs/documentation/angular-cli.md b/docs/documentation/angular-cli.md
index cd8adcfe5a56..738c60607b2f 100644
--- a/docs/documentation/angular-cli.md
+++ b/docs/documentation/angular-cli.md
@@ -23,7 +23,7 @@
   - *testTsconfig* (`string`): The name of the TypeScript configuration file for unit tests.
   - *prefix* (`string`): The prefix to apply to generated selectors.
   - *serviceWorker* (`boolean`): Experimental support for a service worker from @angular/service-worker. Default is `false`.
-  - *hideCircularDependencyWarnings* (`boolean`): Hide circular dependency warnings on builds. Default is `false`.
+  - *showCircularDependencies* (`boolean`): Show circular dependency warnings on builds. Default is `true`.
   - *styles* (`string|array`): Global styles to be included in the build.
   - *stylePreprocessorOptions* : Options to pass to style preprocessors.
     - *includePaths* (`array`): Paths to include. Paths will be resolved to project root.
diff --git a/docs/documentation/build.md b/docs/documentation/build.md
index 08be6df04579..3bcd49be66af 100644
--- a/docs/documentation/build.md
+++ b/docs/documentation/build.md
@@ -312,3 +312,13 @@ Note: service worker support is experimental and subject to change.
     Run build when files change.
   </p>
 </details>
+
+<details>
+  <summary>show-circular-dependencies</summary>
+  <p>
+    <code>--show-circular-dependencies</code> (aliases: <code>-scd</code>)
+  </p>
+  <p>
+    Show circular dependency warnings on builds.
+  </p>
+</details>
diff --git a/packages/@angular/cli/commands/build.ts b/packages/@angular/cli/commands/build.ts
index 5431d72fb7a0..d0afaf018bb3 100644
--- a/packages/@angular/cli/commands/build.ts
+++ b/packages/@angular/cli/commands/build.ts
@@ -138,6 +138,13 @@ export const baseBuildCommandOptions: any = [
     type: Boolean,
     default: true,
     description: 'Extract all licenses in a separate file, in the case of production builds only.'
+  },
+  {
+    name: 'show-circular-dependencies',
+    type: Boolean,
+    default: true,
+    aliases: ['scd'],
+    description: 'Show circular dependency warnings on builds.'
   }
 ];
 
diff --git a/packages/@angular/cli/lib/config/schema.json b/packages/@angular/cli/lib/config/schema.json
index a5a956a93e00..52816b29b484 100644
--- a/packages/@angular/cli/lib/config/schema.json
+++ b/packages/@angular/cli/lib/config/schema.json
@@ -118,10 +118,10 @@
             "type": "boolean",
             "default": false
           },
-          "hideCircularDependencyWarnings": {
-            "description": "Hide circular dependency warnings on builds.",
+          "showCircularDependencies": {
+            "description": "Show circular dependency warnings on builds.",
             "type": "boolean",
-            "default": false
+            "default": true
           },
           "styles": {
             "description": "Global styles to be included in the build.",
diff --git a/packages/@angular/cli/models/build-options.ts b/packages/@angular/cli/models/build-options.ts
index bea9436e1826..12c61595d79c 100644
--- a/packages/@angular/cli/models/build-options.ts
+++ b/packages/@angular/cli/models/build-options.ts
@@ -20,4 +20,5 @@ export interface BuildOptions {
   deleteOutputPath?: boolean;
   preserveSymlinks?: boolean;
   extractLicenses?: boolean;
+  showCircularDependencies?: boolean;
 }
diff --git a/packages/@angular/cli/models/webpack-configs/common.ts b/packages/@angular/cli/models/webpack-configs/common.ts
index 0d54cd52361a..99052f62a930 100644
--- a/packages/@angular/cli/models/webpack-configs/common.ts
+++ b/packages/@angular/cli/models/webpack-configs/common.ts
@@ -73,7 +73,7 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
     }));
   }
 
-  if (!appConfig.hideCircularDependencyWarnings) {
+  if (buildOptions.showCircularDependencies) {
     extraPlugins.push(new CircularDependencyPlugin({
       exclude: /(\\|\/)node_modules(\\|\/)/
     }));
diff --git a/packages/@angular/cli/tasks/eject.ts b/packages/@angular/cli/tasks/eject.ts
index 35598b270f21..5427fb204b37 100644
--- a/packages/@angular/cli/tasks/eject.ts
+++ b/packages/@angular/cli/tasks/eject.ts
@@ -513,6 +513,7 @@ export default Task.extend({
           'style-loader',
           'stylus-loader',
           'url-loader',
+          'circular-dependency-plugin',
         ].forEach((packageName: string) => {
           packageJson['devDependencies'][packageName] = ourPackageJson['dependencies'][packageName];
         });
diff --git a/tests/e2e/tests/misc/circular-dependency.ts b/tests/e2e/tests/misc/circular-dependency.ts
index 5b9a0363f5b2..01d2e23ac1c8 100644
--- a/tests/e2e/tests/misc/circular-dependency.ts
+++ b/tests/e2e/tests/misc/circular-dependency.ts
@@ -5,12 +5,12 @@ import { ng } from '../../utils/process';
 export default async function () {
   await prependToFile('src/app/app.component.ts',
     `import { AppModule } from './app.module'; console.log(AppModule);`);
-  let output = await ng('build');
+  let output = await ng('build', '--show-circular-dependencies');
   if (!output.stdout.match(/WARNING in Circular dependency detected/)) {
     throw new Error('Expected to have circular dependency warning in output.');
   }
 
-  await ng('set', 'apps.0.hideCircularDependencyWarnings=true');
+  await ng('set', 'apps.0.showCircularDependencies=false');
   output = await ng('build');
   if (output.stdout.match(/WARNING in Circular dependency detected/)) {
     throw new Error('Expected to not have circular dependency warning in output.');