diff options
author | Fabio Berger <me@fabioberger.com> | 2018-06-18 23:41:03 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-06-19 05:06:55 +0800 |
commit | 53eae14763b9c2b7ff26a832b5ea9d8b4511969e (patch) | |
tree | ade1c6f9829c604099cd81d9002373437b897df9 /packages/monorepo-scripts/src | |
parent | 074c42e8b6a04ee8b1333711642c136746e29f4b (diff) | |
download | dexon-sol-tools-53eae14763b9c2b7ff26a832b5ea9d8b4511969e.tar dexon-sol-tools-53eae14763b9c2b7ff26a832b5ea9d8b4511969e.tar.gz dexon-sol-tools-53eae14763b9c2b7ff26a832b5ea9d8b4511969e.tar.bz2 dexon-sol-tools-53eae14763b9c2b7ff26a832b5ea9d8b4511969e.tar.lz dexon-sol-tools-53eae14763b9c2b7ff26a832b5ea9d8b4511969e.tar.xz dexon-sol-tools-53eae14763b9c2b7ff26a832b5ea9d8b4511969e.tar.zst dexon-sol-tools-53eae14763b9c2b7ff26a832b5ea9d8b4511969e.zip |
Show all errors of a given kind at once rather then throwing after the first instance is encountered
Diffstat (limited to 'packages/monorepo-scripts/src')
-rw-r--r-- | packages/monorepo-scripts/src/prepublish_checks.ts | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/packages/monorepo-scripts/src/prepublish_checks.ts b/packages/monorepo-scripts/src/prepublish_checks.ts index 64de56ece..17227d13f 100644 --- a/packages/monorepo-scripts/src/prepublish_checks.ts +++ b/packages/monorepo-scripts/src/prepublish_checks.ts @@ -18,6 +18,7 @@ async function prepublishChecksAsync(): Promise<void> { await checkChangelogFormatAsync(updatedPublicLernaPackages); await checkGitTagsForNextVersionAndDeleteIfExistAsync(updatedPublicLernaPackages); await checkPublishRequiredSetupAsync(); + throw new Error('Intentional stop!'); } async function checkGitTagsForNextVersionAndDeleteIfExistAsync( @@ -53,6 +54,8 @@ async function checkGitTagsForNextVersionAndDeleteIfExistAsync( async function checkCurrentVersionMatchesLatestPublishedNPMPackageAsync( updatedPublicLernaPackages: LernaPackage[], ): Promise<void> { + 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; @@ -63,16 +66,28 @@ async function checkCurrentVersionMatchesLatestPublishedNPMPackageAsync( const allVersionsIncludingUnpublished = npmUtils.getPreviouslyPublishedVersions(packageRegistryJsonIfExists); const latestNPMVersion = semverUtils.getLatestVersion(allVersionsIncludingUnpublished); if (packageVersion !== latestNPMVersion) { - throw new Error( - `Found verson ${packageVersion} in package.json but version ${latestNPMVersion} - on NPM (could be unpublished version) for ${packageName}. These versions must match. If you update - the package.json version, make sure to also update the internal dependency versions too.`, - ); + versionMismatches.push({ + packageJsonVersion: packageVersion, + npmVersion: latestNPMVersion, + packageName, + }); } } + if (!_.isEmpty(versionMismatches)) { + utils.log(`Found version mismatches between package.json and NPM published versions (might be unpublished).`); + _.each(versionMismatches, versionMismatch => { + utils.log( + `${versionMismatch.packageName}: ${versionMismatch.packageJsonVersion} package.json, ${ + versionMismatch.npmVersion + } on NPM`, + ); + }); + throw new Error(`Please fix the above package.json/NPM inconsistencies.`); + } } async function checkChangelogFormatAsync(updatedPublicLernaPackages: LernaPackage[]): Promise<void> { + const changeLogInconsistencies = []; for (const lernaPackage of updatedPublicLernaPackages) { const packageName = lernaPackage.package.name; const changelog = changelogUtils.getChangelogOrCreateIfMissing(packageName, lernaPackage.location); @@ -82,11 +97,11 @@ async function checkChangelogFormatAsync(updatedPublicLernaPackages: LernaPackag const lastEntry = changelog[0]; const doesLastEntryHaveTimestamp = !_.isUndefined(lastEntry.timestamp); if (semverUtils.lessThan(lastEntry.version, currentVersion)) { - throw new Error( - `CHANGELOG version cannot be below current package version. - Update ${packageName}'s CHANGELOG. It's current version is ${currentVersion} - but the latest CHANGELOG entry is: ${lastEntry.version}`, - ); + changeLogInconsistencies.push({ + packageJsonVersion: currentVersion, + changelogVersion: lastEntry.version, + packageName, + }); } else if (semverUtils.greaterThan(lastEntry.version, currentVersion) && doesLastEntryHaveTimestamp) { // Remove incorrectly added timestamp delete changelog[0].timestamp; @@ -96,6 +111,17 @@ async function checkChangelogFormatAsync(updatedPublicLernaPackages: LernaPackag } } } + if (!_.isEmpty(changeLogInconsistencies)) { + utils.log(`CHANGELOG versions cannot below package.json versions:`); + _.each(changeLogInconsistencies, inconsistency => { + utils.log( + `${inconsistency.packageName}: ${inconsistency.packageJsonVersion} package.json, ${ + inconsistency.changelogVersion + } CHANGELOG.json`, + ); + }); + } + throw new Error('Fix the above inconsistencies to continue.'); } async function checkPublishRequiredSetupAsync(): Promise<void> { |