Skip to content

Commit

Permalink
modify circular deps checker to output images of circular deps graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
oatkiller committed Aug 20, 2020
1 parent 7699f1c commit 0ee93a8
Showing 1 changed file with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { resolve } from 'path';

/* eslint-disable-next-line import/no-extraneous-dependencies */
import madge from 'madge';
/* eslint-disable-next-line import/no-extraneous-dependencies */
import { run, createFailError } from '@kbn/dev-utils';
import * as os from 'os';
import * as path from 'path';

run(
async ({ log }) => {
const result = await madge(
[resolve(__dirname, '../../public'), resolve(__dirname, '../../common')],
[path.resolve(__dirname, '../../public'), path.resolve(__dirname, '../../common')],
{
fileExtensions: ['ts', 'js', 'tsx'],
excludeRegExp: [
Expand All @@ -34,6 +34,29 @@ run(

const circularFound = result.circular();
if (circularFound.length !== 0) {
let count = 0;
for (const found of circularFound) {
count++;
try {
const specificGraph = await madge(found, {
fileExtensions: ['ts', 'js', 'tsx'],
});
const imagePath = await specificGraph.image(
path.join(os.tmpdir(), `siem-circular-deps-${count}.svg`)
);
console.log('wrote image to: ', imagePath);
} catch (error) {
if (
error.message === 'Graphviz could not be found. Ensure that "gvpr" is in your $PATH.'
) {
console.log(
`Tried to save an image of the dependency graph but failed. ${error.message}`
);
} else {
throw error;
}
}
}
throw createFailError(
`SIEM circular dependencies of imports has been found:\n - ${circularFound.join('\n - ')}`
);
Expand Down

0 comments on commit 0ee93a8

Please sign in to comment.