aboutsummaryrefslogtreecommitdiffstats
path: root/packages/monorepo-scripts
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-04-03 14:28:07 +0800
committerFabio Berger <me@fabioberger.com>2018-04-03 14:28:07 +0800
commitfd9278ac02d7c03bb70a34205ef012cf432f879f (patch)
tree46e1a478aba816e2458cbef18be9b935b852fe1e /packages/monorepo-scripts
parent1b7c7037b8f05a99e840c32504bd14a79957c78d (diff)
downloaddexon-sol-tools-fd9278ac02d7c03bb70a34205ef012cf432f879f.tar
dexon-sol-tools-fd9278ac02d7c03bb70a34205ef012cf432f879f.tar.gz
dexon-sol-tools-fd9278ac02d7c03bb70a34205ef012cf432f879f.tar.bz2
dexon-sol-tools-fd9278ac02d7c03bb70a34205ef012cf432f879f.tar.lz
dexon-sol-tools-fd9278ac02d7c03bb70a34205ef012cf432f879f.tar.xz
dexon-sol-tools-fd9278ac02d7c03bb70a34205ef012cf432f879f.tar.zst
dexon-sol-tools-fd9278ac02d7c03bb70a34205ef012cf432f879f.zip
Add find_unused_deps monorepo script
Diffstat (limited to 'packages/monorepo-scripts')
-rw-r--r--packages/monorepo-scripts/package.json6
-rw-r--r--packages/monorepo-scripts/src/find_unused_dependencies.ts44
2 files changed, 49 insertions, 1 deletions
diff --git a/packages/monorepo-scripts/package.json b/packages/monorepo-scripts/package.json
index 9d2350297..ccdf6ca2e 100644
--- a/packages/monorepo-scripts/package.json
+++ b/packages/monorepo-scripts/package.json
@@ -11,9 +11,11 @@
"build": "tsc",
"test:publish": "run-s build script:publish",
"convert_changelogs": "run-s build script:convert_changelogs",
+ "find_unused_deps": "run-s build script:find_unused_deps",
"script:deps_versions": "node ./lib/deps_versions.js",
"script:publish": "IS_DRY_RUN=true node ./lib/publish.js",
- "script:convert_changelogs": "node ./lib/convert_changelogs.js"
+ "script:convert_changelogs": "node ./lib/convert_changelogs.js",
+ "script:find_unused_deps": "node ./lib/find_unused_dependencies.js"
},
"repository": {
"type": "git",
@@ -30,6 +32,7 @@
"@types/glob": "^5.0.33",
"@types/node": "^8.0.53",
"@types/rimraf": "^2.0.2",
+ "depcheck": "^0.6.9",
"lerna-get-packages": "^1.0.0",
"npm-run-all": "^4.1.2",
"shx": "^0.2.2",
@@ -37,6 +40,7 @@
"typescript": "2.7.1"
},
"dependencies": {
+ "@types/depcheck": "^0.6.0",
"async-child-process": "^1.1.1",
"chalk": "^2.3.0",
"es6-promisify": "^5.0.0",
diff --git a/packages/monorepo-scripts/src/find_unused_dependencies.ts b/packages/monorepo-scripts/src/find_unused_dependencies.ts
new file mode 100644
index 000000000..406500b21
--- /dev/null
+++ b/packages/monorepo-scripts/src/find_unused_dependencies.ts
@@ -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);
+ });
+ });
+}