-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckCircularDeps.js
39 lines (32 loc) · 1.04 KB
/
checkCircularDeps.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env node
const madge = require('madge');
const pc = require('picocolors');
const dedent = require('dedent');
const dirPath = process.env.PWD;
const checkCircularDeps = async () => {
const indexPath = `${dirPath}/dist/index.js`;
console.log('Checking for any circular dependencies..');
const res = await madge(indexPath);
const circular = res.circular();
if (circular.length > 0) {
const errorPaths = circular.map((arr) => arr.join(' -> '));
console.log(
pc.red(dedent`\n\nERROR: Circular dependencies found!
Usually this means you're importing directly from the index file.\n
Please fix the import path(s) in these files:\n
`)
);
errorPaths.forEach((val, idx) =>
console.log(pc.red(pc.bold(`${idx + 1}. ${val}\n`)))
);
process.exit(1);
}
};
const standAlone = async () => {
await checkCircularDeps();
process.exit(0);
};
if (require.main === module) {
standAlone();
}
module.exports = checkCircularDeps;