From 6f540e3e58e6cf921d038f9537d428d28078836f Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 19 Jul 2018 15:50:21 +0200 Subject: Replace lerna-get-packages with our own implementation --- .../src/find_unused_dependencies.ts | 3 +- packages/monorepo-scripts/src/globals.d.ts | 20 +----------- packages/monorepo-scripts/src/prepublish_checks.ts | 1 + packages/monorepo-scripts/src/publish.ts | 2 +- packages/monorepo-scripts/src/test_installation.ts | 3 +- packages/monorepo-scripts/src/types.ts | 14 +++++++++ packages/monorepo-scripts/src/utils/utils.ts | 36 ++++++++++++++++++++-- .../types/lerna-get-packages/index.d.ts | 16 ---------- 8 files changed, 52 insertions(+), 43 deletions(-) delete mode 100644 packages/typescript-typings/types/lerna-get-packages/index.d.ts (limited to 'packages') 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 { 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); }); diff --git a/packages/typescript-typings/types/lerna-get-packages/index.d.ts b/packages/typescript-typings/types/lerna-get-packages/index.d.ts deleted file mode 100644 index 0650a542c..000000000 --- a/packages/typescript-typings/types/lerna-get-packages/index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -declare interface LernaPackage { - location: string; - package: { - private?: boolean; - version: string; - name: string; - main?: string; - config?: { - additionalTsTypings?: string[]; - }; - }; -} -declare function lernaGetPackages(path: string): LernaPackage[]; -declare module 'lerna-get-packages' { - export = lernaGetPackages; -} -- cgit v1.2.3 From 74c0fd419b74cdc959add175f575f52306518140 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 19 Jul 2018 15:51:38 +0200 Subject: Upgrade Lerna to 3.0-Beta14 --- packages/monorepo-scripts/package.json | 5 ++--- packages/monorepo-scripts/src/constants.ts | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) (limited to 'packages') diff --git a/packages/monorepo-scripts/package.json b/packages/monorepo-scripts/package.json index f3a6aa793..1d641a7f5 100644 --- a/packages/monorepo-scripts/package.json +++ b/packages/monorepo-scripts/package.json @@ -33,12 +33,11 @@ "@types/node": "^8.0.53", "@types/opn": "^5.1.0", "@types/rimraf": "^2.0.2", + "@types/semver": "5.5.0", "depcheck": "^0.6.9", - "lerna-get-packages": "^1.0.0", "make-promises-safe": "^1.1.0", "npm-run-all": "^4.1.2", "shx": "^0.2.2", - "@types/semver": "5.5.0", "tslint": "5.11.0", "typescript": "2.7.1" }, @@ -56,8 +55,8 @@ "prompt": "^1.0.0", "publish-release": "0xproject/publish-release", "rimraf": "^2.6.2", - "semver-diff": "^2.1.0", "semver": "5.5.0", + "semver-diff": "^2.1.0", "semver-sort": "0.0.4" }, "publishConfig": { diff --git a/packages/monorepo-scripts/src/constants.ts b/packages/monorepo-scripts/src/constants.ts index 3aaf881cb..f08313bd2 100644 --- a/packages/monorepo-scripts/src/constants.ts +++ b/packages/monorepo-scripts/src/constants.ts @@ -3,6 +3,6 @@ import * as path from 'path'; export const constants = { monorepoRootPath: path.join(__dirname, '../../..'), stagingWebsite: 'http://staging-0xproject.s3-website-us-east-1.amazonaws.com', - lernaExecutable: path.join('node_modules', 'lerna', 'bin', 'lerna.js'), + lernaExecutable: path.join('node_modules', 'lerna', 'cli.js'), githubPersonalAccessToken: process.env.GITHUB_PERSONAL_ACCESS_TOKEN_0X_JS, }; -- cgit v1.2.3 From 7d840c7a1825f9aad16f3ab644e6f31819fefd59 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 19 Jul 2018 16:26:00 +0200 Subject: Remove unused declaration --- packages/monorepo-scripts/src/globals.d.ts | 1 - 1 file changed, 1 deletion(-) (limited to 'packages') diff --git a/packages/monorepo-scripts/src/globals.d.ts b/packages/monorepo-scripts/src/globals.d.ts index ccdf90d2a..cb6a61b55 100644 --- a/packages/monorepo-scripts/src/globals.d.ts +++ b/packages/monorepo-scripts/src/globals.d.ts @@ -14,4 +14,3 @@ declare module 'semver-sort' { } declare module 'promisify-child-process'; -declare module '@lerna/project'; -- cgit v1.2.3 From 1df9370bc21e93267b5432668967118d7001abf2 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 19 Jul 2018 16:26:45 +0200 Subject: Renames to remove mention of Lerna --- .../src/find_unused_dependencies.ts | 10 ++--- packages/monorepo-scripts/src/prepublish_checks.ts | 44 +++++++++++----------- packages/monorepo-scripts/src/publish.ts | 35 ++++++++--------- packages/monorepo-scripts/src/test_installation.ts | 15 +++----- packages/monorepo-scripts/src/types.ts | 4 +- packages/monorepo-scripts/src/utils/utils.ts | 24 ++++++------ 6 files changed, 64 insertions(+), 68 deletions(-) (limited to 'packages') diff --git a/packages/monorepo-scripts/src/find_unused_dependencies.ts b/packages/monorepo-scripts/src/find_unused_dependencies.ts index 1a36aceee..4bb4b7dc5 100644 --- a/packages/monorepo-scripts/src/find_unused_dependencies.ts +++ b/packages/monorepo-scripts/src/find_unused_dependencies.ts @@ -12,15 +12,15 @@ 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 = utils.getLernaPackages(constants.monorepoRootPath); - for (const lernaPackage of lernaPackages) { - if (_.includes(IGNORE_PACKAGES, lernaPackage.package.name)) { + const packages = utils.getPackages(constants.monorepoRootPath); + for (const pkg of packages) { + if (_.includes(IGNORE_PACKAGES, pkg.packageJson.name)) { continue; // skip } - utils.log(`Checking ${lernaPackage.package.name} for unused deps. This might take a while...`); + utils.log(`Checking ${pkg.packageJson.name} for unused deps. This might take a while...`); const configs = {}; - const { dependencies } = await depcheckAsync(lernaPackage.location, configs); + const { dependencies } = await depcheckAsync(pkg.location, configs); if (!_.isEmpty(dependencies)) { _.each(dependencies, dep => { utils.log(dep); diff --git a/packages/monorepo-scripts/src/prepublish_checks.ts b/packages/monorepo-scripts/src/prepublish_checks.ts index 81b2f414b..431e848ca 100644 --- a/packages/monorepo-scripts/src/prepublish_checks.ts +++ b/packages/monorepo-scripts/src/prepublish_checks.ts @@ -4,35 +4,33 @@ import semver = require('semver'); import semverSort = require('semver-sort'); import { constants } from './constants'; -import { LernaPackage } from './types'; +import { Package } from './types'; import { changelogUtils } from './utils/changelog_utils'; import { npmUtils } from './utils/npm_utils'; import { utils } from './utils/utils'; async function prepublishChecksAsync(): Promise { const shouldIncludePrivate = false; - const updatedPublicLernaPackages = await utils.getUpdatedLernaPackagesAsync(shouldIncludePrivate); + const updatedPublicPackages = await utils.getUpdatedPackagesAsync(shouldIncludePrivate); - await checkCurrentVersionMatchesLatestPublishedNPMPackageAsync(updatedPublicLernaPackages); - await checkChangelogFormatAsync(updatedPublicLernaPackages); - await checkGitTagsForNextVersionAndDeleteIfExistAsync(updatedPublicLernaPackages); + await checkCurrentVersionMatchesLatestPublishedNPMPackageAsync(updatedPublicPackages); + await checkChangelogFormatAsync(updatedPublicPackages); + await checkGitTagsForNextVersionAndDeleteIfExistAsync(updatedPublicPackages); await checkPublishRequiredSetupAsync(); } -async function checkGitTagsForNextVersionAndDeleteIfExistAsync( - updatedPublicLernaPackages: LernaPackage[], -): Promise { - const packageNames = _.map(updatedPublicLernaPackages, lernaPackage => lernaPackage.package.name); +async function checkGitTagsForNextVersionAndDeleteIfExistAsync(updatedPublicPackages: Package[]): Promise { + const packageNames = _.map(updatedPublicPackages, pkg => pkg.packageJson.name); const localGitTags = await utils.getLocalGitTagsAsync(); const localTagVersionsByPackageName = await utils.getGitTagsByPackageNameAsync(packageNames, localGitTags); const remoteGitTags = await utils.getRemoteGitTagsAsync(); const remoteTagVersionsByPackageName = await utils.getGitTagsByPackageNameAsync(packageNames, remoteGitTags); - for (const lernaPackage of updatedPublicLernaPackages) { - const currentVersion = lernaPackage.package.version; - const packageName = lernaPackage.package.name; - const packageLocation = lernaPackage.location; + for (const pkg of updatedPublicPackages) { + const currentVersion = pkg.packageJson.version; + const packageName = pkg.packageJson.name; + const packageLocation = pkg.location; const nextVersion = await utils.getNextPackageVersionAsync(currentVersion, packageName, packageLocation); const remoteTagVersions = remoteTagVersionsByPackageName[packageName]; @@ -50,13 +48,13 @@ async function checkGitTagsForNextVersionAndDeleteIfExistAsync( } async function checkCurrentVersionMatchesLatestPublishedNPMPackageAsync( - updatedPublicLernaPackages: LernaPackage[], + updatedPublicPackages: Package[], ): Promise { utils.log('Check package versions against npmjs.org...'); const versionMismatches = []; - for (const lernaPackage of updatedPublicLernaPackages) { - const packageName = lernaPackage.package.name; - const packageVersion = lernaPackage.package.version; + for (const pkg of updatedPublicPackages) { + const packageName = pkg.packageJson.name; + const packageVersion = pkg.packageJson.version; const packageRegistryJsonIfExists = await npmUtils.getPackageRegistryJsonIfExistsAsync(packageName); if (_.isUndefined(packageRegistryJsonIfExists)) { continue; // noop for packages not yet published to NPM @@ -85,14 +83,14 @@ async function checkCurrentVersionMatchesLatestPublishedNPMPackageAsync( } } -async function checkChangelogFormatAsync(updatedPublicLernaPackages: LernaPackage[]): Promise { +async function checkChangelogFormatAsync(updatedPublicPackages: Package[]): Promise { utils.log('Check CHANGELOGs for inconsistencies...'); const changeLogInconsistencies = []; - for (const lernaPackage of updatedPublicLernaPackages) { - const packageName = lernaPackage.package.name; - const changelog = changelogUtils.getChangelogOrCreateIfMissing(packageName, lernaPackage.location); + for (const pkg of updatedPublicPackages) { + const packageName = pkg.packageJson.name; + const changelog = changelogUtils.getChangelogOrCreateIfMissing(packageName, pkg.location); - const currentVersion = lernaPackage.package.version; + const currentVersion = pkg.packageJson.version; if (!_.isEmpty(changelog)) { const lastEntry = changelog[0]; const doesLastEntryHaveTimestamp = !_.isUndefined(lastEntry.timestamp); @@ -106,7 +104,7 @@ async function checkChangelogFormatAsync(updatedPublicLernaPackages: LernaPackag // Remove incorrectly added timestamp delete changelog[0].timestamp; // Save updated CHANGELOG.json - await changelogUtils.writeChangelogJsonFileAsync(lernaPackage.location, changelog); + await changelogUtils.writeChangelogJsonFileAsync(pkg.location, changelog); utils.log(`${packageName}: Removed timestamp from latest CHANGELOG.json entry.`); } } diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 94b67eab3..c44e1f85e 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 { LernaPackage, PackageToVersionChange, SemVerIndex, VersionChangelog } from './types'; +import { Package, PackageToVersionChange, SemVerIndex, VersionChangelog } from './types'; import { changelogUtils } from './utils/changelog_utils'; import { utils } from './utils/utils'; @@ -34,19 +34,20 @@ const packageNameToWebsitePath: { [name: string]: string } = { 'sol-cov': 'sol-cov', subproviders: 'subproviders', 'order-utils': 'order-utils', + 'ethereum-types': 'ethereum-types', }; (async () => { // Fetch public, updated Lerna packages const shouldIncludePrivate = false; - const updatedPublicLernaPackages = await utils.getUpdatedLernaPackagesAsync(shouldIncludePrivate); + const updatedPublicPackages = await utils.getUpdatedPackagesAsync(shouldIncludePrivate); - await confirmDocPagesRenderAsync(updatedPublicLernaPackages); + await confirmDocPagesRenderAsync(updatedPublicPackages); // Update CHANGELOGs - const updatedPublicLernaPackageNames = _.map(updatedPublicLernaPackages, pkg => pkg.package.name); - utils.log(`Will update CHANGELOGs and publish: \n${updatedPublicLernaPackageNames.join('\n')}\n`); - const packageToVersionChange = await updateChangeLogsAsync(updatedPublicLernaPackages); + const updatedPublicPackageNames = _.map(updatedPublicPackages, pkg => pkg.packageJson.name); + utils.log(`Will update CHANGELOGs and publish: \n${updatedPublicPackageNames.join('\n')}\n`); + const packageToVersionChange = await updateChangeLogsAsync(updatedPublicPackages); // Push changelog changes to Github if (!IS_DRY_RUN) { @@ -65,7 +66,7 @@ const packageNameToWebsitePath: { [name: string]: string } = { process.exit(1); }); -async function confirmDocPagesRenderAsync(packages: LernaPackage[]): Promise { +async function confirmDocPagesRenderAsync(packages: Package[]): Promise { // push docs to staging utils.log("Upload all docJson's to S3 staging..."); await execAsync(`yarn stage_docs`, { cwd: constants.monorepoRootPath }); @@ -76,14 +77,14 @@ async function confirmDocPagesRenderAsync(packages: LernaPackage[]): Promise { - const scriptsIfExists = pkg.package.scripts; + const scriptsIfExists = pkg.packageJson.scripts; if (_.isUndefined(scriptsIfExists)) { throw new Error('Found a public package without any scripts in package.json'); } return !_.isUndefined(scriptsIfExists[DOC_GEN_COMMAND]); }); _.each(packagesWithDocs, pkg => { - const name = pkg.package.name; + const name = pkg.packageJson.name; const nameWithoutPrefix = _.startsWith(name, NPM_NAMESPACE) ? name.split('@0xproject/')[1] : name; const docSegmentIfExists = packageNameToWebsitePath[nameWithoutPrefix]; if (_.isUndefined(docSegmentIfExists)) { @@ -114,15 +115,15 @@ async function pushChangelogsToGithubAsync(): Promise { utils.log(`Pushed CHANGELOG updates to Github`); } -async function updateChangeLogsAsync(updatedPublicLernaPackages: LernaPackage[]): Promise { +async function updateChangeLogsAsync(updatedPublicPackages: Package[]): Promise { const packageToVersionChange: PackageToVersionChange = {}; - for (const lernaPackage of updatedPublicLernaPackages) { - const packageName = lernaPackage.package.name; - let changelog = changelogUtils.getChangelogOrCreateIfMissing(packageName, lernaPackage.location); + for (const pkg of updatedPublicPackages) { + const packageName = pkg.packageJson.name; + let changelog = changelogUtils.getChangelogOrCreateIfMissing(packageName, pkg.location); - const currentVersion = lernaPackage.package.version; + const currentVersion = pkg.packageJson.version; const shouldAddNewEntry = changelogUtils.shouldAddNewChangelogEntry( - lernaPackage.package.name, + pkg.packageJson.name, currentVersion, changelog, ); @@ -157,11 +158,11 @@ async function updateChangeLogsAsync(updatedPublicLernaPackages: LernaPackage[]) } // Save updated CHANGELOG.json - await changelogUtils.writeChangelogJsonFileAsync(lernaPackage.location, changelog); + await changelogUtils.writeChangelogJsonFileAsync(pkg.location, changelog); utils.log(`${packageName}: Updated CHANGELOG.json`); // Generate updated CHANGELOG.md const changelogMd = changelogUtils.generateChangelogMd(changelog); - await changelogUtils.writeChangelogMdFileAsync(lernaPackage.location, changelogMd); + await changelogUtils.writeChangelogMdFileAsync(pkg.location, changelogMd); utils.log(`${packageName}: Updated CHANGELOG.md`); } diff --git a/packages/monorepo-scripts/src/test_installation.ts b/packages/monorepo-scripts/src/test_installation.ts index 34d065c58..668d4ef1d 100644 --- a/packages/monorepo-scripts/src/test_installation.ts +++ b/packages/monorepo-scripts/src/test_installation.ts @@ -10,17 +10,14 @@ import { utils } from './utils/utils'; (async () => { const monorepoRootPath = path.join(__dirname, '../../..'); - const lernaPackages = utils.getLernaPackages(monorepoRootPath); + const packages = utils.getPackages(monorepoRootPath); const installablePackages = _.filter( - lernaPackages, - lernaPackage => - !lernaPackage.package.private && - !_.isUndefined(lernaPackage.package.main) && - lernaPackage.package.main.endsWith('.js'), + packages, + pkg => !pkg.packageJson.private && !_.isUndefined(pkg.packageJson.main) && pkg.packageJson.main.endsWith('.js'), ); - for (const installableLernaPackage of installablePackages) { - const packagePath = installableLernaPackage.location; - const packageName = installableLernaPackage.package.name; + for (const installablePackage of installablePackages) { + const packagePath = installablePackage.location; + const packageName = installablePackage.packageJson.name; utils.log(`Testing ${packageName}`); let result = await execAsync('npm pack', { cwd: packagePath }); const packedPackageFileName = result.stdout.trim(); diff --git a/packages/monorepo-scripts/src/types.ts b/packages/monorepo-scripts/src/types.ts index 052a38d1f..9f991c86c 100644 --- a/packages/monorepo-scripts/src/types.ts +++ b/packages/monorepo-scripts/src/types.ts @@ -41,9 +41,9 @@ export interface GitTagsByPackageName { [packageName: string]: string[]; } -export interface LernaPackage { +export interface Package { location: string; - package: { + packageJson: { private?: boolean; version: string; name: string; diff --git a/packages/monorepo-scripts/src/utils/utils.ts b/packages/monorepo-scripts/src/utils/utils.ts index 78bac1e4e..f04b9b671 100644 --- a/packages/monorepo-scripts/src/utils/utils.ts +++ b/packages/monorepo-scripts/src/utils/utils.ts @@ -4,7 +4,7 @@ import { exec as execAsync } from 'promisify-child-process'; import semver = require('semver'); import { constants } from '../constants'; -import { GitTagsByPackageName, LernaPackage, UpdatedPackage } from '../types'; +import { GitTagsByPackageName, Package, UpdatedPackage } from '../types'; import { changelogUtils } from './changelog_utils'; @@ -12,13 +12,13 @@ export const utils = { log(...args: any[]): void { console.log(...args); // tslint:disable-line:no-console }, - getLernaPackages(rootDir: string): LernaPackage[] { + getPackages(rootDir: string): Package[] { 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 = []; + const packages = []; for (const workspace of rootPackageJson.workspaces) { const workspacePath = workspace.replace('*', ''); const subpackageNames = fs.readdirSync(`${rootDir}/${workspacePath}`); @@ -30,27 +30,27 @@ export const utils = { try { const packageJsonString = fs.readFileSync(`${pathToPackageJson}/package.json`, 'utf8'); const packageJson = JSON.parse(packageJsonString); - const lernaPackage = { + const pkg = { location: pathToPackageJson, - package: packageJson, + packageJson, }; - lernaPackages.push(lernaPackage); + packages.push(pkg); } catch (err) { utils.log(`Couldn't find a 'package.json' for ${subpackageName}. Skipping...`); } } } - return lernaPackages; + return packages; }, - async getUpdatedLernaPackagesAsync(shouldIncludePrivate: boolean): Promise { + async getUpdatedPackagesAsync(shouldIncludePrivate: boolean): Promise { const updatedPublicPackages = await utils.getLernaUpdatedPackagesAsync(shouldIncludePrivate); const updatedPackageNames = _.map(updatedPublicPackages, pkg => pkg.name); - const allLernaPackages = utils.getLernaPackages(constants.monorepoRootPath); - const updatedPublicLernaPackages = _.filter(allLernaPackages, pkg => { - return _.includes(updatedPackageNames, pkg.package.name); + const allPackages = utils.getPackages(constants.monorepoRootPath); + const updatedPackages = _.filter(allPackages, pkg => { + return _.includes(updatedPackageNames, pkg.packageJson.name); }); - return updatedPublicLernaPackages; + return updatedPackages; }, async getLernaUpdatedPackagesAsync(shouldIncludePrivate: boolean): Promise { const result = await execAsync(`${constants.lernaExecutable} updated --json`, { -- cgit v1.2.3 From f9c4d0925ea18290c6a578b2d42aa9d41c1f680f Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 19 Jul 2018 16:32:03 +0200 Subject: Add additional pattern removal and added HACK comment --- packages/monorepo-scripts/src/utils/utils.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/monorepo-scripts/src/utils/utils.ts b/packages/monorepo-scripts/src/utils/utils.ts index f04b9b671..862656fbf 100644 --- a/packages/monorepo-scripts/src/utils/utils.ts +++ b/packages/monorepo-scripts/src/utils/utils.ts @@ -20,7 +20,9 @@ export const utils = { } const packages = []; for (const workspace of rootPackageJson.workspaces) { - const workspacePath = workspace.replace('*', ''); + // HACK: Remove allowed wildcards from workspace entries. + // This might be entirely comprehensive. + const workspacePath = workspace.replace('*', '').replace('**/*', ''); const subpackageNames = fs.readdirSync(`${rootDir}/${workspacePath}`); for (const subpackageName of subpackageNames) { if (_.startsWith(subpackageName, '.')) { -- cgit v1.2.3 From 9ab6ab1bf99864510fe2a0ed7296d04e103bde65 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 19 Jul 2018 17:22:26 +0200 Subject: Improve log --- packages/monorepo-scripts/src/utils/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/monorepo-scripts/src/utils/utils.ts b/packages/monorepo-scripts/src/utils/utils.ts index 862656fbf..8ba59c81d 100644 --- a/packages/monorepo-scripts/src/utils/utils.ts +++ b/packages/monorepo-scripts/src/utils/utils.ts @@ -38,7 +38,7 @@ export const utils = { }; packages.push(pkg); } catch (err) { - utils.log(`Couldn't find a 'package.json' for ${subpackageName}. Skipping...`); + utils.log(`Couldn't find a 'package.json' for ${subpackageName}. Skipping.`); } } } -- cgit v1.2.3