Show all errors of a given kind at once rather then throwing after the first instance is encountered
This commit is contained in:
parent
074c42e8b6
commit
53eae14763
@ -18,6 +18,7 @@ async function prepublishChecksAsync(): Promise<void> {
|
|||||||
await checkChangelogFormatAsync(updatedPublicLernaPackages);
|
await checkChangelogFormatAsync(updatedPublicLernaPackages);
|
||||||
await checkGitTagsForNextVersionAndDeleteIfExistAsync(updatedPublicLernaPackages);
|
await checkGitTagsForNextVersionAndDeleteIfExistAsync(updatedPublicLernaPackages);
|
||||||
await checkPublishRequiredSetupAsync();
|
await checkPublishRequiredSetupAsync();
|
||||||
|
throw new Error('Intentional stop!');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkGitTagsForNextVersionAndDeleteIfExistAsync(
|
async function checkGitTagsForNextVersionAndDeleteIfExistAsync(
|
||||||
@ -53,6 +54,8 @@ async function checkGitTagsForNextVersionAndDeleteIfExistAsync(
|
|||||||
async function checkCurrentVersionMatchesLatestPublishedNPMPackageAsync(
|
async function checkCurrentVersionMatchesLatestPublishedNPMPackageAsync(
|
||||||
updatedPublicLernaPackages: LernaPackage[],
|
updatedPublicLernaPackages: LernaPackage[],
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
utils.log('Check package versions against npmjs.org...');
|
||||||
|
const versionMismatches = [];
|
||||||
for (const lernaPackage of updatedPublicLernaPackages) {
|
for (const lernaPackage of updatedPublicLernaPackages) {
|
||||||
const packageName = lernaPackage.package.name;
|
const packageName = lernaPackage.package.name;
|
||||||
const packageVersion = lernaPackage.package.version;
|
const packageVersion = lernaPackage.package.version;
|
||||||
@ -63,16 +66,28 @@ async function checkCurrentVersionMatchesLatestPublishedNPMPackageAsync(
|
|||||||
const allVersionsIncludingUnpublished = npmUtils.getPreviouslyPublishedVersions(packageRegistryJsonIfExists);
|
const allVersionsIncludingUnpublished = npmUtils.getPreviouslyPublishedVersions(packageRegistryJsonIfExists);
|
||||||
const latestNPMVersion = semverUtils.getLatestVersion(allVersionsIncludingUnpublished);
|
const latestNPMVersion = semverUtils.getLatestVersion(allVersionsIncludingUnpublished);
|
||||||
if (packageVersion !== latestNPMVersion) {
|
if (packageVersion !== latestNPMVersion) {
|
||||||
throw new Error(
|
versionMismatches.push({
|
||||||
`Found verson ${packageVersion} in package.json but version ${latestNPMVersion}
|
packageJsonVersion: packageVersion,
|
||||||
on NPM (could be unpublished version) for ${packageName}. These versions must match. If you update
|
npmVersion: latestNPMVersion,
|
||||||
the package.json version, make sure to also update the internal dependency versions too.`,
|
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> {
|
async function checkChangelogFormatAsync(updatedPublicLernaPackages: LernaPackage[]): Promise<void> {
|
||||||
|
const changeLogInconsistencies = [];
|
||||||
for (const lernaPackage of updatedPublicLernaPackages) {
|
for (const lernaPackage of updatedPublicLernaPackages) {
|
||||||
const packageName = lernaPackage.package.name;
|
const packageName = lernaPackage.package.name;
|
||||||
const changelog = changelogUtils.getChangelogOrCreateIfMissing(packageName, lernaPackage.location);
|
const changelog = changelogUtils.getChangelogOrCreateIfMissing(packageName, lernaPackage.location);
|
||||||
@ -82,11 +97,11 @@ async function checkChangelogFormatAsync(updatedPublicLernaPackages: LernaPackag
|
|||||||
const lastEntry = changelog[0];
|
const lastEntry = changelog[0];
|
||||||
const doesLastEntryHaveTimestamp = !_.isUndefined(lastEntry.timestamp);
|
const doesLastEntryHaveTimestamp = !_.isUndefined(lastEntry.timestamp);
|
||||||
if (semverUtils.lessThan(lastEntry.version, currentVersion)) {
|
if (semverUtils.lessThan(lastEntry.version, currentVersion)) {
|
||||||
throw new Error(
|
changeLogInconsistencies.push({
|
||||||
`CHANGELOG version cannot be below current package version.
|
packageJsonVersion: currentVersion,
|
||||||
Update ${packageName}'s CHANGELOG. It's current version is ${currentVersion}
|
changelogVersion: lastEntry.version,
|
||||||
but the latest CHANGELOG entry is: ${lastEntry.version}`,
|
packageName,
|
||||||
);
|
});
|
||||||
} else if (semverUtils.greaterThan(lastEntry.version, currentVersion) && doesLastEntryHaveTimestamp) {
|
} else if (semverUtils.greaterThan(lastEntry.version, currentVersion) && doesLastEntryHaveTimestamp) {
|
||||||
// Remove incorrectly added timestamp
|
// Remove incorrectly added timestamp
|
||||||
delete changelog[0].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> {
|
async function checkPublishRequiredSetupAsync(): Promise<void> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user