aboutsummaryrefslogtreecommitdiffstats
path: root/packages/monorepo-scripts/src/find_unused_dependencies.ts
blob: 42b4b7890197b4677d1645933931f0727517b8c4 (plain) (blame)
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
#!/usr/bin/env node

import * as depcheckAsync from 'depcheck';
import * as _ from 'lodash';

import { constants } from './constants';
import { utils } from './utils/utils';

// For some reason, `depcheck` hangs on some packages. Add them here.
const IGNORE_PACKAGES = ['@0x/sol-compiler'];

(async () => {
    utils.log('*** NOTE: Not all deps listed here are actually not required. ***');
    utils.log("*** `depcheck` isn't perfect so double check before actually removing any. ***\n");
    const packages = utils.getPackages(constants.monorepoRootPath);
    for (const pkg of packages) {
        if (_.includes(IGNORE_PACKAGES, pkg.packageJson.name)) {
            continue; // skip
        }
        utils.log(`Checking ${pkg.packageJson.name} for unused deps. This might take a while...`);

        const configs = {};
        const { dependencies } = await depcheckAsync(pkg.location, configs);
        if (!_.isEmpty(dependencies)) {
            _.each(dependencies, dep => {
                utils.log(dep);
            });
        }
        utils.log('\n');
    }
})().catch(err => {
    utils.log(err);
    process.exit(1);
});