From 9ce03e3515517e3f5fb5bd4b3dcafa57a3191e3d Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 3 Apr 2018 12:03:10 +0900 Subject: Update tslint-config. To avoid circular deps, this must always be one version back and must be manually updated. --- packages/monorepo-scripts/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/monorepo-scripts') diff --git a/packages/monorepo-scripts/package.json b/packages/monorepo-scripts/package.json index 28729b37c..9d2350297 100644 --- a/packages/monorepo-scripts/package.json +++ b/packages/monorepo-scripts/package.json @@ -26,7 +26,7 @@ "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", -- cgit v1.2.3 From 8281be235cf55b04f24297bf6606a8dc24d8fac7 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 3 Apr 2018 12:03:59 +0900 Subject: Use @0xproject/utils promisify everywhere --- packages/monorepo-scripts/package.json | 2 +- packages/monorepo-scripts/src/globals.d.ts | 1 - packages/monorepo-scripts/src/postpublish_utils.ts | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) (limited to 'packages/monorepo-scripts') diff --git a/packages/monorepo-scripts/package.json b/packages/monorepo-scripts/package.json index 9d2350297..cac8b8475 100644 --- a/packages/monorepo-scripts/package.json +++ b/packages/monorepo-scripts/package.json @@ -37,9 +37,9 @@ "typescript": "2.7.1" }, "dependencies": { + "@0xproject/utils": "0.4.4", "async-child-process": "^1.1.1", "chalk": "^2.3.0", - "es6-promisify": "^5.0.0", "glob": "^7.1.2", "lodash": "^4.17.4", "moment": "2.21.0", diff --git a/packages/monorepo-scripts/src/globals.d.ts b/packages/monorepo-scripts/src/globals.d.ts index c5898d0f5..b9f3d2e71 100644 --- a/packages/monorepo-scripts/src/globals.d.ts +++ b/packages/monorepo-scripts/src/globals.d.ts @@ -1,6 +1,5 @@ declare module 'async-child-process'; declare module 'publish-release'; -declare module 'es6-promisify'; declare module 'semver-diff'; // semver-sort declarations diff --git a/packages/monorepo-scripts/src/postpublish_utils.ts b/packages/monorepo-scripts/src/postpublish_utils.ts index 236b54379..d068adb4d 100644 --- a/packages/monorepo-scripts/src/postpublish_utils.ts +++ b/packages/monorepo-scripts/src/postpublish_utils.ts @@ -1,5 +1,5 @@ +import { promisify } from '@0xproject/utils'; import { execAsync } from 'async-child-process'; -import * as promisify from 'es6-promisify'; import * as fs from 'fs'; import * as _ from 'lodash'; import * as path from 'path'; -- cgit v1.2.3 From a88b4040ffdf1057ffb539c79c4ec517a670a950 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 3 Apr 2018 12:58:45 +0900 Subject: Stop using utils --- packages/monorepo-scripts/package.json | 2 +- packages/monorepo-scripts/src/globals.d.ts | 1 + packages/monorepo-scripts/src/postpublish_utils.ts | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) (limited to 'packages/monorepo-scripts') diff --git a/packages/monorepo-scripts/package.json b/packages/monorepo-scripts/package.json index cac8b8475..9d2350297 100644 --- a/packages/monorepo-scripts/package.json +++ b/packages/monorepo-scripts/package.json @@ -37,9 +37,9 @@ "typescript": "2.7.1" }, "dependencies": { - "@0xproject/utils": "0.4.4", "async-child-process": "^1.1.1", "chalk": "^2.3.0", + "es6-promisify": "^5.0.0", "glob": "^7.1.2", "lodash": "^4.17.4", "moment": "2.21.0", diff --git a/packages/monorepo-scripts/src/globals.d.ts b/packages/monorepo-scripts/src/globals.d.ts index b9f3d2e71..c5898d0f5 100644 --- a/packages/monorepo-scripts/src/globals.d.ts +++ b/packages/monorepo-scripts/src/globals.d.ts @@ -1,5 +1,6 @@ declare module 'async-child-process'; declare module 'publish-release'; +declare module 'es6-promisify'; declare module 'semver-diff'; // semver-sort declarations diff --git a/packages/monorepo-scripts/src/postpublish_utils.ts b/packages/monorepo-scripts/src/postpublish_utils.ts index d068adb4d..236b54379 100644 --- a/packages/monorepo-scripts/src/postpublish_utils.ts +++ b/packages/monorepo-scripts/src/postpublish_utils.ts @@ -1,5 +1,5 @@ -import { promisify } from '@0xproject/utils'; import { execAsync } from 'async-child-process'; +import * as promisify from 'es6-promisify'; import * as fs from 'fs'; import * as _ from 'lodash'; import * as path from 'path'; -- cgit v1.2.3 From fd9278ac02d7c03bb70a34205ef012cf432f879f Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 3 Apr 2018 15:28:07 +0900 Subject: Add find_unused_deps monorepo script --- packages/monorepo-scripts/package.json | 6 ++- .../src/find_unused_dependencies.ts | 44 ++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 packages/monorepo-scripts/src/find_unused_dependencies.ts (limited to 'packages/monorepo-scripts') 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((resolve, reject) => { + depcheck(path, opts, (unused: any) => { + resolve(unused); + }); + }); +} -- cgit v1.2.3 From e9cb5c069a46a2402fb2e930b3f14a71e056d207 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 3 Apr 2018 15:44:07 +0900 Subject: Add comment about ignored packages --- packages/monorepo-scripts/src/find_unused_dependencies.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'packages/monorepo-scripts') diff --git a/packages/monorepo-scripts/src/find_unused_dependencies.ts b/packages/monorepo-scripts/src/find_unused_dependencies.ts index 406500b21..1b47f2458 100644 --- a/packages/monorepo-scripts/src/find_unused_dependencies.ts +++ b/packages/monorepo-scripts/src/find_unused_dependencies.ts @@ -9,6 +9,7 @@ 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 () => { -- cgit v1.2.3 From b2c423dd8410b884357fdb476012e4a213e52580 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 4 Apr 2018 03:54:58 +0900 Subject: Use Results type --- packages/monorepo-scripts/src/find_unused_dependencies.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'packages/monorepo-scripts') diff --git a/packages/monorepo-scripts/src/find_unused_dependencies.ts b/packages/monorepo-scripts/src/find_unused_dependencies.ts index 1b47f2458..374cba2e3 100644 --- a/packages/monorepo-scripts/src/find_unused_dependencies.ts +++ b/packages/monorepo-scripts/src/find_unused_dependencies.ts @@ -23,7 +23,7 @@ const IGNORE_PACKAGES = ['@0xproject/deployer']; utils.log(`Checking ${lernaPackage.package.name} for unused deps. This might take a while...`); const configs = {}; - const result: any = await depcheckAsync(lernaPackage.location, configs); + const result = await depcheckAsync(lernaPackage.location, configs); if (!_.isEmpty(result.dependencies)) { _.each(result.dependencies, dep => { utils.log(dep); @@ -36,8 +36,8 @@ const IGNORE_PACKAGES = ['@0xproject/deployer']; process.exit(1); }); -async function depcheckAsync(path: string, opts: any) { - return new Promise((resolve, reject) => { +async function depcheckAsync(path: string, opts: any): Promise { + return new Promise((resolve, reject) => { depcheck(path, opts, (unused: any) => { resolve(unused); }); -- cgit v1.2.3