Skip to content

feat(@angular/cli): add circular dependency detection #6813

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 27, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/documentation/angular-cli.md
Original file line number Diff line number Diff line change
@@ -23,6 +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`.
- *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.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -42,6 +42,7 @@
"dependencies": {
"autoprefixer": "^6.5.3",
"chalk": "^1.1.3",
"circular-dependency-plugin": "^3.0.0",
"common-tags": "^1.3.1",
"css-loader": "^0.28.1",
"cssnano": "^3.10.0",
5 changes: 5 additions & 0 deletions packages/@angular/cli/lib/config/schema.json
Original file line number Diff line number Diff line change
@@ -118,6 +118,11 @@
"type": "boolean",
"default": false
},
"hideCircularDependencyWarnings": {
"description": "Hide circular dependency warnings on builds.",
"type": "boolean",
"default": false
},
"styles": {
"description": "Global styles to be included in the build.",
"type": "array",
7 changes: 7 additions & 0 deletions packages/@angular/cli/models/webpack-configs/common.ts
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import { extraEntryParser, getOutputHashFormat } from './utils';
import { WebpackConfigOptions } from '../webpack-config';

const ProgressPlugin = require('webpack/lib/ProgressPlugin');
const CircularDependencyPlugin = require('circular-dependency-plugin');


/**
@@ -72,6 +73,12 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
}));
}

if (!appConfig.hideCircularDependencyWarnings) {
extraPlugins.push(new CircularDependencyPlugin({
exclude: /(\\|\/)node_modules(\\|\/)/
}));
}

return {
resolve: {
extensions: ['.ts', '.js'],
1 change: 1 addition & 0 deletions packages/@angular/cli/package.json
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@
"@ngtools/webpack": "1.5.0-rc.1",
"autoprefixer": "^6.5.3",
"chalk": "^1.1.3",
"circular-dependency-plugin": "^3.0.0",
"common-tags": "^1.3.1",
"css-loader": "^0.28.1",
"cssnano": "^3.10.0",
4 changes: 4 additions & 0 deletions packages/@angular/cli/tasks/eject.ts
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const SilentError = require('silent-error');
const licensePlugin = require('license-webpack-plugin');
const CircularDependencyPlugin = require('circular-dependency-plugin');
const Task = require('../ember-cli/lib/models/task');

const ProgressPlugin = require('webpack/lib/ProgressPlugin');
@@ -178,6 +179,9 @@ class JsonWebpackSerializer {
args = this._extractTextPluginSerialize(plugin);
this.variableImports['extract-text-webpack-plugin'] = 'ExtractTextPlugin';
break;
case CircularDependencyPlugin:
this.variableImports['circular-dependency-plugin'] = 'CircularDependencyPlugin';
break;
case AotPlugin:
args = this._aotPluginSerialize(plugin);
this._addImport('@ngtools/webpack', 'AotPlugin');
18 changes: 18 additions & 0 deletions tests/e2e/tests/misc/circular-dependency.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { prependToFile } from '../../utils/fs';
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');
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');
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.');
}
}