Skip to content

chore: better logging for madge #6003

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
Jul 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
28 changes: 23 additions & 5 deletions tools/gulp/tasks/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import {task} from 'gulp';
import {execNodeTask} from '../util/task_helpers';
import {join} from 'path';
import {buildConfig} from 'material2-build-tools';
import {red} from 'chalk';

// These types lack of type definitions
const madge = require('madge');

/** Glob that matches all SCSS or CSS files that should be linted. */
const stylesGlob = '+(tools|src)/**/!(*.bundle).+(css|scss)';
Expand All @@ -17,11 +21,6 @@ const cdkOutPath = join(buildConfig.outputDir, 'packages', 'cdk');

task('lint', ['tslint', 'stylelint', 'madge']);

/** Task that runs madge to detect circular dependencies. */
task('madge', ['material:clean-build'], execNodeTask(
'madge', ['--circular', materialOutPath, cdkOutPath])
);

/** Task to lint Angular Material's scss stylesheets. */
task('stylelint', execNodeTask(
'stylelint', [stylesGlob, '--config', 'stylelint-config.json', '--syntax', 'scss']
Expand All @@ -32,3 +31,22 @@ task('tslint', execNodeTask('tslint', tsLintBaseFlags));

/** Task that automatically fixes TSLint warnings. */
task('tslint:fix', execNodeTask('tslint', [...tsLintBaseFlags, '--fix']));

/** Task that runs madge to detect circular dependencies. */
task('madge', ['material:clean-build'], () => {
madge([materialOutPath, cdkOutPath]).then((res: any) => {
const circularModules = res.circular();

if (circularModules.length) {
console.error();
console.error(red(`Madge found modules with circular dependencies.`));
console.error(formatMadgeCircularModules(circularModules));
console.error();
}
});
});

/** Returns a string that formats the graph of circular modules. */
function formatMadgeCircularModules(circularModules: string[][]): string {
return circularModules.map((modulePaths: string[]) => `\n - ${modulePaths.join(' > ')}`).join('');
}