diff options
author | Fabio Berger <me@fabioberger.com> | 2018-07-19 21:50:21 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-07-19 21:50:21 +0800 |
commit | 6f540e3e58e6cf921d038f9537d428d28078836f (patch) | |
tree | d374416f212fe4989b96083d23ee4ca9d9329095 /packages/monorepo-scripts/src | |
parent | c839965c05719091311683da9d367c43908f4f2f (diff) | |
download | dexon-sol-tools-6f540e3e58e6cf921d038f9537d428d28078836f.tar dexon-sol-tools-6f540e3e58e6cf921d038f9537d428d28078836f.tar.gz dexon-sol-tools-6f540e3e58e6cf921d038f9537d428d28078836f.tar.bz2 dexon-sol-tools-6f540e3e58e6cf921d038f9537d428d28078836f.tar.lz dexon-sol-tools-6f540e3e58e6cf921d038f9537d428d28078836f.tar.xz dexon-sol-tools-6f540e3e58e6cf921d038f9537d428d28078836f.tar.zst dexon-sol-tools-6f540e3e58e6cf921d038f9537d428d28078836f.zip |
Replace lerna-get-packages with our own implementation
Diffstat (limited to 'packages/monorepo-scripts/src')
-rw-r--r-- | packages/monorepo-scripts/src/find_unused_dependencies.ts | 3 | ||||
-rw-r--r-- | packages/monorepo-scripts/src/globals.d.ts | 20 | ||||
-rw-r--r-- | packages/monorepo-scripts/src/prepublish_checks.ts | 1 | ||||
-rw-r--r-- | packages/monorepo-scripts/src/publish.ts | 2 | ||||
-rw-r--r-- | packages/monorepo-scripts/src/test_installation.ts | 3 | ||||
-rw-r--r-- | packages/monorepo-scripts/src/types.ts | 14 | ||||
-rw-r--r-- | packages/monorepo-scripts/src/utils/utils.ts | 36 |
7 files changed, 52 insertions, 27 deletions
diff --git a/packages/monorepo-scripts/src/find_unused_dependencies.ts b/packages/monorepo-scripts/src/find_unused_dependencies.ts index 11e48ab13..1a36aceee 100644 --- a/packages/monorepo-scripts/src/find_unused_dependencies.ts +++ b/packages/monorepo-scripts/src/find_unused_dependencies.ts @@ -1,7 +1,6 @@ #!/usr/bin/env node import * as depcheckAsync from 'depcheck'; -import lernaGetPackages = require('lerna-get-packages'); import * as _ from 'lodash'; import { constants } from './constants'; @@ -13,7 +12,7 @@ const IGNORE_PACKAGES = ['@0xproject/sol-compiler']; (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); + const lernaPackages = utils.getLernaPackages(constants.monorepoRootPath); for (const lernaPackage of lernaPackages) { if (_.includes(IGNORE_PACKAGES, lernaPackage.package.name)) { continue; // skip diff --git a/packages/monorepo-scripts/src/globals.d.ts b/packages/monorepo-scripts/src/globals.d.ts index 1693a6dbb..ccdf90d2a 100644 --- a/packages/monorepo-scripts/src/globals.d.ts +++ b/packages/monorepo-scripts/src/globals.d.ts @@ -13,23 +13,5 @@ declare module 'semver-sort' { const desc: (versions: string[]) => string[]; } -declare interface LernaPackage { - location: string; - package: { - private?: boolean; - version: string; - name: string; - main?: string; - scripts?: { [command: string]: string }; - config?: { - additionalTsTypings?: string[]; - }; - }; -} -declare function lernaGetPackages(path: string): LernaPackage[]; -// lerna-get-packages declarations -declare module 'lerna-get-packages' { - export = lernaGetPackages; -} - declare module 'promisify-child-process'; +declare module '@lerna/project'; diff --git a/packages/monorepo-scripts/src/prepublish_checks.ts b/packages/monorepo-scripts/src/prepublish_checks.ts index 3b4ff9082..81b2f414b 100644 --- a/packages/monorepo-scripts/src/prepublish_checks.ts +++ b/packages/monorepo-scripts/src/prepublish_checks.ts @@ -4,6 +4,7 @@ import semver = require('semver'); import semverSort = require('semver-sort'); import { constants } from './constants'; +import { LernaPackage } from './types'; import { changelogUtils } from './utils/changelog_utils'; import { npmUtils } from './utils/npm_utils'; import { utils } from './utils/utils'; diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 72c6c0a71..94b67eab3 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -11,7 +11,7 @@ import semverDiff = require('semver-diff'); import semverSort = require('semver-sort'); import { constants } from './constants'; -import { PackageToVersionChange, SemVerIndex, VersionChangelog } from './types'; +import { LernaPackage, PackageToVersionChange, SemVerIndex, VersionChangelog } from './types'; import { changelogUtils } from './utils/changelog_utils'; import { utils } from './utils/utils'; diff --git a/packages/monorepo-scripts/src/test_installation.ts b/packages/monorepo-scripts/src/test_installation.ts index b67154667..34d065c58 100644 --- a/packages/monorepo-scripts/src/test_installation.ts +++ b/packages/monorepo-scripts/src/test_installation.ts @@ -1,7 +1,6 @@ #!/usr/bin/env node import * as fs from 'fs'; -import lernaGetPackages = require('lerna-get-packages'); import * as _ from 'lodash'; import * as path from 'path'; import { exec as execAsync } from 'promisify-child-process'; @@ -11,7 +10,7 @@ import { utils } from './utils/utils'; (async () => { const monorepoRootPath = path.join(__dirname, '../../..'); - const lernaPackages = lernaGetPackages(monorepoRootPath); + const lernaPackages = utils.getLernaPackages(monorepoRootPath); const installablePackages = _.filter( lernaPackages, lernaPackage => diff --git a/packages/monorepo-scripts/src/types.ts b/packages/monorepo-scripts/src/types.ts index 61bd75732..052a38d1f 100644 --- a/packages/monorepo-scripts/src/types.ts +++ b/packages/monorepo-scripts/src/types.ts @@ -40,3 +40,17 @@ export interface PackageRegistryJson { export interface GitTagsByPackageName { [packageName: string]: string[]; } + +export interface LernaPackage { + location: string; + package: { + private?: boolean; + version: string; + name: string; + main?: string; + scripts?: { [command: string]: string }; + config?: { + additionalTsTypings?: string[]; + }; + }; +} diff --git a/packages/monorepo-scripts/src/utils/utils.ts b/packages/monorepo-scripts/src/utils/utils.ts index be3ad950f..78bac1e4e 100644 --- a/packages/monorepo-scripts/src/utils/utils.ts +++ b/packages/monorepo-scripts/src/utils/utils.ts @@ -1,10 +1,10 @@ -import lernaGetPackages = require('lerna-get-packages'); +import * as fs from 'fs'; import * as _ from 'lodash'; import { exec as execAsync } from 'promisify-child-process'; import semver = require('semver'); import { constants } from '../constants'; -import { GitTagsByPackageName, UpdatedPackage } from '../types'; +import { GitTagsByPackageName, LernaPackage, UpdatedPackage } from '../types'; import { changelogUtils } from './changelog_utils'; @@ -12,11 +12,41 @@ export const utils = { log(...args: any[]): void { console.log(...args); // tslint:disable-line:no-console }, + getLernaPackages(rootDir: string): LernaPackage[] { + const rootPackageJsonString = fs.readFileSync(`${rootDir}/package.json`, 'utf8'); + const rootPackageJson = JSON.parse(rootPackageJsonString); + if (_.isUndefined(rootPackageJson.workspaces)) { + throw new Error(`Did not find 'workspaces' key in root package.json`); + } + const lernaPackages = []; + for (const workspace of rootPackageJson.workspaces) { + const workspacePath = workspace.replace('*', ''); + const subpackageNames = fs.readdirSync(`${rootDir}/${workspacePath}`); + for (const subpackageName of subpackageNames) { + if (_.startsWith(subpackageName, '.')) { + continue; + } + const pathToPackageJson = `${rootDir}/${workspacePath}${subpackageName}`; + try { + const packageJsonString = fs.readFileSync(`${pathToPackageJson}/package.json`, 'utf8'); + const packageJson = JSON.parse(packageJsonString); + const lernaPackage = { + location: pathToPackageJson, + package: packageJson, + }; + lernaPackages.push(lernaPackage); + } catch (err) { + utils.log(`Couldn't find a 'package.json' for ${subpackageName}. Skipping...`); + } + } + } + return lernaPackages; + }, async getUpdatedLernaPackagesAsync(shouldIncludePrivate: boolean): Promise<LernaPackage[]> { const updatedPublicPackages = await utils.getLernaUpdatedPackagesAsync(shouldIncludePrivate); const updatedPackageNames = _.map(updatedPublicPackages, pkg => pkg.name); - const allLernaPackages = lernaGetPackages(constants.monorepoRootPath); + const allLernaPackages = utils.getLernaPackages(constants.monorepoRootPath); const updatedPublicLernaPackages = _.filter(allLernaPackages, pkg => { return _.includes(updatedPackageNames, pkg.package.name); }); |