diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2019-02-07 18:15:37 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2019-02-07 18:15:37 +0800 |
commit | de234280690571dc3441c1a06bb49049df3289dc (patch) | |
tree | d6792c9172245ee836e31a2588f3ae91dd53a012 /packages/monorepo-scripts | |
parent | 4d75681357b04ae77637ee62645b662796a3b15b (diff) | |
parent | 2a344e26cc51fa41a9df3535b625b8609dfc167e (diff) | |
download | dexon-0x-contracts-de234280690571dc3441c1a06bb49049df3289dc.tar dexon-0x-contracts-de234280690571dc3441c1a06bb49049df3289dc.tar.gz dexon-0x-contracts-de234280690571dc3441c1a06bb49049df3289dc.tar.bz2 dexon-0x-contracts-de234280690571dc3441c1a06bb49049df3289dc.tar.lz dexon-0x-contracts-de234280690571dc3441c1a06bb49049df3289dc.tar.xz dexon-0x-contracts-de234280690571dc3441c1a06bb49049df3289dc.tar.zst dexon-0x-contracts-de234280690571dc3441c1a06bb49049df3289dc.zip |
Merge development
Diffstat (limited to 'packages/monorepo-scripts')
-rw-r--r-- | packages/monorepo-scripts/package.json | 12 | ||||
-rw-r--r-- | packages/monorepo-scripts/src/deps_versions.ts | 98 | ||||
-rw-r--r-- | packages/monorepo-scripts/src/publish.ts | 2 |
3 files changed, 79 insertions, 33 deletions
diff --git a/packages/monorepo-scripts/package.json b/packages/monorepo-scripts/package.json index 6904a793b..24dca0004 100644 --- a/packages/monorepo-scripts/package.json +++ b/packages/monorepo-scripts/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "@0x/monorepo-scripts", - "version": "1.0.19", + "version": "1.0.22", "engines": { "node": ">=6.12" }, @@ -32,13 +32,13 @@ }, "homepage": "https://github.com/0xProject/0x-monorepo/packages/monorepo-scripts/README.md", "devDependencies": { - "@types/glob": "^5.0.33", + "@types/glob": "5.0.35", "@types/mkdirp": "^0.5.2", "@types/node": "*", "@types/opn": "^5.1.0", "@types/rimraf": "^2.0.2", "@types/semver": "5.5.0", - "@types/yargs": "^10.0.0", + "@types/yargs": "^11.0.0", "depcheck": "^0.6.9", "make-promises-safe": "^1.1.0", "npm-run-all": "^4.1.2", @@ -47,8 +47,8 @@ "typescript": "3.0.1" }, "dependencies": { - "@0x/utils": "^3.0.1", - "@0x/types": "^1.5.2", + "@0x/types": "^2.0.1", + "@0x/utils": "^4.0.2", "@lerna/batch-packages": "^3.0.0-beta.18", "@types/depcheck": "^0.6.0", "async-child-process": "^1.1.1", @@ -56,7 +56,7 @@ "es6-promisify": "^5.0.0", "glob": "^7.1.2", "isomorphic-fetch": "2.2.1", - "lodash": "^4.17.5", + "lodash": "^4.17.11", "mkdirp": "^0.5.1", "moment": "2.21.0", "opn": "^5.3.0", diff --git a/packages/monorepo-scripts/src/deps_versions.ts b/packages/monorepo-scripts/src/deps_versions.ts index d15bb6b4d..fb57a26ef 100644 --- a/packages/monorepo-scripts/src/deps_versions.ts +++ b/packages/monorepo-scripts/src/deps_versions.ts @@ -1,9 +1,9 @@ #!/usr/bin/env node -import { PackageJSON } from '@0x/types'; +import { PackageJSON, PackageJSONConfig } from '@0x/types'; import chalk from 'chalk'; import { sync as globSync } from 'glob'; -import * as _ from 'lodash'; +import * as path from 'path'; import { utils } from './utils/utils'; @@ -17,11 +17,35 @@ interface VersionsByDependency { [depName: string]: Versions; } -const PACKAGE_JSON_GLOB = '../*/package.json'; +interface ParsedDependencies { + ignored: VersionsByDependency; + included: VersionsByDependency; +} + +const PACKAGE_JSON_GLOB = '../../*/package.json'; + +const config = utils.readJSONFile<PackageJSON>(path.join(__dirname, '../../../package.json')) + .config as PackageJSONConfig; +const dependenciesWithIgnoredVersions: string[] = (config.ignoreDependencyVersions as string).split(' '); +const packagesWithIgnoredVersions: string[] = (config.ignoreDependencyVersionsForPackage as string).split(' '); + +if (require.main === module) { + const dependencies = parseDependencies(); + const ignoredMultiples = getDependenciesWithMultipleVersions(dependencies.ignored); + const multiples = getDependenciesWithMultipleVersions(dependencies.included); + printVersionsByDependency(multiples); + utils.log(`├── ${chalk.bold('IGNORED')}`); + printVersionsByDependency(ignoredMultiples); + if (Object.keys(multiples).length !== 0) { + utils.log( + `Some dependencies have multiple versions. Please fix by trying to find compatible versions. As a last resort, you can add space-separated exceptions to root package.json config.ignoreDependencyVersions`, + ); + process.exit(1); + } +} -// tslint:disable:no-unused-variable -function getDependencies(path: string): Dependencies { - const packageJSON = utils.readJSONFile<PackageJSON>(path); +function getDependencies(_path: string): Dependencies { + const packageJSON = utils.readJSONFile<PackageJSON>(_path); const dependencies = { ...packageJSON.dependencies, ...packageJSON.devDependencies, @@ -29,27 +53,49 @@ function getDependencies(path: string): Dependencies { return dependencies; } -const files = globSync(PACKAGE_JSON_GLOB); -const versionsByDependency: VersionsByDependency = {}; -files.map(path => { - const [_1, packageName, _2] = path.split('/'); - const dependencies = getDependencies(path); - _.map(dependencies, (version: string, depName: string) => { - if (_.isUndefined(versionsByDependency[depName])) { - versionsByDependency[depName] = {}; - } - versionsByDependency[depName][packageName] = version; +function parseDependencies(): ParsedDependencies { + const files = globSync(path.join(__dirname, PACKAGE_JSON_GLOB)); + const parsedDependencies: ParsedDependencies = { + ignored: {}, + included: {}, + }; + files.map(_path => { + const pathParts = _path.split('/'); + const packageName = pathParts[pathParts.length - 2]; + const packageCategory = packagesWithIgnoredVersions.includes(packageName) ? 'ignored' : 'included'; + const dependencies = getDependencies(_path); + Object.keys(dependencies).forEach((depName: string) => { + const category = dependenciesWithIgnoredVersions.includes(depName) ? 'ignored' : packageCategory; + if (parsedDependencies[category][depName] === undefined) { + parsedDependencies[category][depName] = {}; + } + const version = dependencies[depName]; + parsedDependencies[category][depName][packageName] = version; + }); }); -}); + return parsedDependencies; +} + +function getDependenciesWithMultipleVersions(versionsByDependency: VersionsByDependency): VersionsByDependency { + return Object.keys(versionsByDependency) + .filter((depName: string) => hasMultipleVersions(versionsByDependency[depName])) + .reduce<VersionsByDependency>((obj, depName: string) => { + obj[depName] = versionsByDependency[depName]; + return obj; + }, {}); +} -_.map(versionsByDependency, (versions: Versions, depName: string) => { - if (_.uniq(_.values(versions)).length === 1) { - delete versionsByDependency[depName]; - } else { +function printVersionsByDependency(versionsByDependency: VersionsByDependency): void { + Object.keys(versionsByDependency).forEach((depName: string) => { + const versions: Versions = versionsByDependency[depName]; utils.log(chalk.bold(depName)); - _.map(versions, (version: string, packageName: string) => { - utils.log(`├── ${packageName} -> ${version}`); + Object.keys(versions).forEach((packageName: string) => { + utils.log(`├── ${packageName} -> ${versions[packageName]}`); }); - } -}); -// tslint:disable:no-unused-variable + }); +} + +function hasMultipleVersions(versions: Versions): boolean { + const uniques = new Set(Object.values(versions)); + return uniques.size > 1; +} diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index ddb2811f2..b9179678e 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -47,7 +47,7 @@ async function confirmAsync(message: string): Promise<void> { await confirmAsync( 'THIS IS NOT A TEST PUBLISH! You are about to publish one or more packages to npm. Are you sure you want to continue? (y/n)', ); - await confirmDocPagesRenderAsync(packagesWithDocs); + // await confirmDocPagesRenderAsync(packagesWithDocs); } // Update CHANGELOGs |