diff options
author | Fabio Berger <me@fabioberger.com> | 2018-04-04 02:58:18 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-04 02:58:18 +0800 |
commit | 674e56cea69fe96ddd0071d3c4c5b5ea8ae299bf (patch) | |
tree | 19ddd0c0312eed054595c0d3431ecddead18e857 /packages/monorepo-scripts | |
parent | 4a9752d7cda05f616d2709e34f4687da813d3090 (diff) | |
parent | 61809130a6659335c7550cf35c55e20b3e579a6f (diff) | |
download | dexon-sol-tools-674e56cea69fe96ddd0071d3c4c5b5ea8ae299bf.tar dexon-sol-tools-674e56cea69fe96ddd0071d3c4c5b5ea8ae299bf.tar.gz dexon-sol-tools-674e56cea69fe96ddd0071d3c4c5b5ea8ae299bf.tar.bz2 dexon-sol-tools-674e56cea69fe96ddd0071d3c4c5b5ea8ae299bf.tar.lz dexon-sol-tools-674e56cea69fe96ddd0071d3c4c5b5ea8ae299bf.tar.xz dexon-sol-tools-674e56cea69fe96ddd0071d3c4c5b5ea8ae299bf.tar.zst dexon-sol-tools-674e56cea69fe96ddd0071d3c4c5b5ea8ae299bf.zip |
Merge pull request #496 from 0xProject/removeUnusedDeps
Remove unused deps + Remove Dharma from website
Diffstat (limited to 'packages/monorepo-scripts')
-rw-r--r-- | packages/monorepo-scripts/package.json | 8 | ||||
-rw-r--r-- | packages/monorepo-scripts/src/find_unused_dependencies.ts | 45 |
2 files changed, 51 insertions, 2 deletions
diff --git a/packages/monorepo-scripts/package.json b/packages/monorepo-scripts/package.json index e2ff1928d..b113b4b39 100644 --- a/packages/monorepo-scripts/package.json +++ b/packages/monorepo-scripts/package.json @@ -10,8 +10,10 @@ "clean": "shx rm -rf lib", "build": "tsc", "test:publish": "run-s build script:publish", + "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:publish": "IS_DRY_RUN=true node ./lib/publish.js", + "script:find_unused_deps": "node ./lib/find_unused_dependencies.js" }, "repository": { "type": "git", @@ -24,10 +26,11 @@ "homepage": "https://github.com/0xProject/0x-monorepo/packages/monorepo-scripts/README.md", "comment": "// We purposefully use an older version of tslint-config here to avoid creating an import cycle", "devDependencies": { - "@0xproject/tslint-config": "0.4.8", + "@0xproject/tslint-config": "0.4.13", "@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", @@ -35,6 +38,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..374cba2e3 --- /dev/null +++ b/packages/monorepo-scripts/src/find_unused_dependencies.ts @@ -0,0 +1,45 @@ +#!/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'; + +// For some reason, `depcheck` hangs on some packages. Add them here. +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 = 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): Promise<depcheck.Results> { + return new Promise<depcheck.Results>((resolve, reject) => { + depcheck(path, opts, (unused: any) => { + resolve(unused); + }); + }); +} |