humpty
Version:
Makes sure your changelogs mention your breaking changes
59 lines (52 loc) • 2.1 kB
JavaScript
// @flow
import * as changeTypes from "./changeTypes";
function condensedGitRef(gitRef) {
const isSha = gitRef.match(/^[0-9a-f]{6,}$/);
if (isSha) {
return gitRef.slice(0, 6);
}
return gitRef;
}
export default function printUnmentionedChanges({
unmentionedChanges,
unmentionedChangeCount,
oldApi,
newApi
}) {
if (unmentionedChangeCount === 0) {
return;
}
const plural = unmentionedChangeCount === 1 ? "" : "s";
const intro = `🚨 Found ${unmentionedChangeCount} breaking API change${plural} not mentioned in git commits (${condensedGitRef(
oldApi
)}..${condensedGitRef(newApi)}):`;
const fullChanges = unmentionedChanges
.map(changedExport => {
const exportName = changedExport.isDefaultExport
? "Default export"
: changedExport.name;
const changeList = changedExport.apiChanges
.map(apiChange => {
switch (apiChange.changeType) {
case changeTypes.PROP_TYPE_CHANGED:
return ` - ${apiChange.changeType}: "${apiChange.propName}" was ${apiChange.oldType}, now ${apiChange.newType}.`;
case changeTypes.PROP_REMOVED:
return ` - ${apiChange.changeType}: "${apiChange.propName}".`;
case changeTypes.PROP_MADE_REQUIRED:
return ` - ${apiChange.changeType}: "${apiChange.propName}" was optional, now required.`;
case changeTypes.PROP_MADE_OPTIONAL:
return ` - ${apiChange.changeType}: "${apiChange.propName}" was required, now optional.`;
case !changedExport.isDefaultExport && changeTypes.EXPORT_REMOVED:
return ` - ${apiChange.changeType}: ${changedExport.name} is no longer exported from the entry file.`;
case changedExport.isDefaultExport && changeTypes.EXPORT_REMOVED:
return ` - ${apiChange.changeType}: There is no longer a default export.`;
default:
break;
}
})
.join("\n");
return `${exportName}\n${changeList}`;
})
.join("\n");
return `${intro}\n\n${fullChanges}`;
}