Skip to content

Commit 6a18c5d

Browse files
devversionandrewseguin
authored andcommitted
chore: better logging for madge (#6003)
* Switches madge to the programmatic API usage which also allows us to ignore warnings about the dependency on `@angular/cdk` which could not be found by Madge (since it's not a node module) * This also allows us to reduce the amount of messages that Madge prints. Currently the CI output is not readable because the spinner of the Madge CLI spams everything.
1 parent 0e95c89 commit 6a18c5d

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

tools/gulp/tasks/lint.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import {task} from 'gulp';
22
import {execNodeTask} from '../util/task_helpers';
33
import {join} from 'path';
44
import {buildConfig} from 'material2-build-tools';
5+
import {red} from 'chalk';
6+
7+
// These types lack of type definitions
8+
const madge = require('madge');
59

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

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

20-
/** Task that runs madge to detect circular dependencies. */
21-
task('madge', ['material:clean-build'], execNodeTask(
22-
'madge', ['--circular', materialOutPath, cdkOutPath])
23-
);
24-
2524
/** Task to lint Angular Material's scss stylesheets. */
2625
task('stylelint', execNodeTask(
2726
'stylelint', [stylesGlob, '--config', 'stylelint-config.json', '--syntax', 'scss']
@@ -32,3 +31,22 @@ task('tslint', execNodeTask('tslint', tsLintBaseFlags));
3231

3332
/** Task that automatically fixes TSLint warnings. */
3433
task('tslint:fix', execNodeTask('tslint', [...tsLintBaseFlags, '--fix']));
34+
35+
/** Task that runs madge to detect circular dependencies. */
36+
task('madge', ['material:clean-build'], () => {
37+
madge([materialOutPath, cdkOutPath]).then((res: any) => {
38+
const circularModules = res.circular();
39+
40+
if (circularModules.length) {
41+
console.error();
42+
console.error(red(`Madge found modules with circular dependencies.`));
43+
console.error(formatMadgeCircularModules(circularModules));
44+
console.error();
45+
}
46+
});
47+
});
48+
49+
/** Returns a string that formats the graph of circular modules. */
50+
function formatMadgeCircularModules(circularModules: string[][]): string {
51+
return circularModules.map((modulePaths: string[]) => `\n - ${modulePaths.join(' > ')}`).join('');
52+
}

0 commit comments

Comments
 (0)