Changesets comes with a default format for the changelogs for packages which is relatively basic in what information it displays, however this is customisable. Here we will talk about how to modify the changelog, so that it contains extra meta-information.
To change how the changelog is generated, you use the changelog
setting in the ./changeset/config.json
. This setting accepts a string, which points to a module. You can reference an npm package that you have installed, or a local file where you have written your own functions.
For example, changesets
has a package, @changesets/changelog-git
. To use it, you would first need to install the package.
yarn add @changesets/changelog-git
Next, change your .changeset/config.json
to point to the new package:
"changelog": "@changesets/changelog-git"
If you want to write your own, you can reference a file path. For example, you can create a new file .changeset/my-changelog-config.js
, then you can reference it in the .changeset/config.json
file as:
"changelog": ".changeset/my-changelog-config.js"
The changelog formatting is done by two different functions. getReleaseLine
and getDependencyReleaseLine
. These must be provided in an object as the export of your generation file. A basic file setup for the changelog generation functions would be:
async function getReleaseLine() {}
async function getDependencyReleaseLine() {}
module.exports {
getReleaseLine,
getDependencyReleaseLine
}
These functions are run during the changeset version
and are expected to return a string (or a promise with a string).
If you are using typescript to write your changelog functions, you can use the type. First install @changesets/types
, and then:
import { ChangelogFunctions } from "@changesets/types";
async function getReleaseLine() {}
async function getDependencyReleaseLine() {}
const defaultChangelogFunctions: ChangelogFunctions = {
getReleaseLine,
getDependencyReleaseLine
};
export default defaultChangelogFunctions;
type getReleaseLine(
changeset: {
// This is the string of the summary from the changeset markdown file
summary: string
// This is an array of information about what is going to be released. each is an object with name: the name of the package, and type, which is "major", "minor", or "patch"
releases
// the hash for the commit that introduced the changeset
commit
},
// the type of the change this changeset refers to, as "major", "minor", or "patch"
type
// This needs to be explained - see @changesets/changelog-github's code for how this works
changelogOpts
) => string
TODO - this guide is incomplete. Until it is completed, you may need to dig into the code for some of our existing
TODO
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。