-
Notifications
You must be signed in to change notification settings - Fork 234
/
Copy pathdependencyCheck.js
47 lines (41 loc) · 1.18 KB
/
dependencyCheck.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
40
41
42
43
44
45
46
47
// eslint-disable no-console
const path = require('path');
const depcheck = require('depcheck');
const options = {
specials: ['bin', 'eslint', 'jest', 'babel', 'webpack'],
ignoreDirs: ['build', '.storybook', '.yarn', 'cypress'],
ignoreMatches: [
'puppeteer',
'isarray',
'jest-environment-jsdom',
'@testing-library/dom',
'@storybook/addon-knobs',
],
};
depcheck(
path.resolve(__dirname, '..'),
options,
({ dependencies, missing }) => {
console.log(`${dependencies.length} unused dependencies.`);
console.log(dependencies.join('\n'));
// Filter out dependencies prefixed with "#".
const missingFiltered = Object.keys(missing).reduce((obj, key) => {
if (key.startsWith('#')) {
return obj;
}
return {
...obj,
[key]: missing[key],
};
}, {});
console.log(`${Object.keys(missingFiltered).length} missing dependencies.`);
Object.keys(missingFiltered).forEach(key => {
console.log(key);
console.log(`\t${missingFiltered[key].join('\n\t')}`);
console.log('\n');
});
if (dependencies.length > 0 || Object.keys(missingFiltered).length > 0) {
process.exit(1);
}
},
);