Add find_unused_deps monorepo script
This commit is contained in:
44
packages/monorepo-scripts/src/find_unused_dependencies.ts
Normal file
44
packages/monorepo-scripts/src/find_unused_dependencies.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import * as depcheck from 'depcheck';
|
||||
import * as fs from 'fs';
|
||||
import lernaGetPackages = require('lerna-get-packages');
|
||||
import * as _ from 'lodash';
|
||||
import { exec as execAsync } from 'promisify-child-process';
|
||||
|
||||
import { constants } from './constants';
|
||||
import { utils } from './utils';
|
||||
|
||||
const IGNORE_PACKAGES = ['@0xproject/deployer'];
|
||||
|
||||
(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 lernaPackages = lernaGetPackages(constants.monorepoRootPath);
|
||||
for (const lernaPackage of lernaPackages) {
|
||||
if (_.includes(IGNORE_PACKAGES, lernaPackage.package.name)) {
|
||||
continue; // skip
|
||||
}
|
||||
utils.log(`Checking ${lernaPackage.package.name} for unused deps. This might take a while...`);
|
||||
|
||||
const configs = {};
|
||||
const result: any = await depcheckAsync(lernaPackage.location, configs);
|
||||
if (!_.isEmpty(result.dependencies)) {
|
||||
_.each(result.dependencies, dep => {
|
||||
utils.log(dep);
|
||||
});
|
||||
}
|
||||
utils.log('\n');
|
||||
}
|
||||
})().catch(err => {
|
||||
utils.log(err);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
async function depcheckAsync(path: string, opts: any) {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
depcheck(path, opts, (unused: any) => {
|
||||
resolve(unused);
|
||||
});
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user