humpty
Version:
Makes sure your changelogs mention your breaking changes
59 lines (50 loc) • 2.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = printUnmentionedChanges;
var _changeTypes = require("./changeTypes");
var changeTypes = _interopRequireWildcard(_changeTypes);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function condensedGitRef(gitRef) {
const isSha = gitRef.match(/^[0-9a-f]{6,}$/);
if (isSha) {
return gitRef.slice(0, 6);
}
return gitRef;
} // @flow
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}`;
}