@lerna/publish
Version:
Publish packages in the current project
87 lines (86 loc) • 4.12 kB
JavaScript
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var update_changelog_exports = {};
__export(update_changelog_exports, {
updateChangelog: () => updateChangelog
});
module.exports = __toCommonJS(update_changelog_exports);
var import_conventional_changelog_core = __toESM(require("conventional-changelog-core"));
var import_fs_extra = __toESM(require("fs-extra"));
var import_get_stream = __toESM(require("get-stream"));
var import_npmlog = __toESM(require("npmlog"));
var import_constants = require("./constants");
var import_get_changelog_config = require("./get-changelog-config");
var import_make_bump_only_filter = require("./make-bump-only-filter");
var import_read_existing_changelog = require("./read-existing-changelog");
function updateChangelog(pkg, type, { changelogPreset, rootPath, tagPrefix = "v", version }) {
import_npmlog.default.silly(type, "for %s at %s", pkg.name, pkg.location);
return (0, import_get_changelog_config.getChangelogConfig)(changelogPreset, rootPath).then((config) => {
const options = {};
const context = {};
if (config.conventionalChangelog) {
options.config = Object.assign({}, config.conventionalChangelog);
} else {
options.config = Object.assign({}, config);
}
const gitRawCommitsOpts = Object.assign({}, options.config.gitRawCommitsOpts);
if (type === "root") {
context.version = version;
context.currentTag = `${tagPrefix}${version}`;
options.tagPrefix = tagPrefix;
} else {
gitRawCommitsOpts.path = pkg.location;
options.pkg = { path: pkg.manifestLocation };
if (type === "independent") {
options.lernaPackage = pkg.name;
} else {
options.tagPrefix = tagPrefix;
context.currentTag = `${tagPrefix}${pkg.version}`;
}
}
const changelogStream = (0, import_conventional_changelog_core.default)(options, context, gitRawCommitsOpts);
return Promise.all([
(0, import_get_stream.default)(changelogStream).then((0, import_make_bump_only_filter.makeBumpOnlyFilter)(pkg)),
(0, import_read_existing_changelog.readExistingChangelog)(pkg)
]).then(([newEntry, [changelogFileLoc, changelogContents]]) => {
import_npmlog.default.silly(type, "writing new entry: %j", newEntry);
const content = [import_constants.CHANGELOG_HEADER, newEntry, changelogContents].join(import_constants.BLANK_LINE);
return import_fs_extra.default.writeFile(changelogFileLoc, content.trim() + import_constants.EOL).then(() => {
import_npmlog.default.verbose(type, "wrote", changelogFileLoc);
return {
logPath: changelogFileLoc,
newEntry
};
});
});
});
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
updateChangelog
});