Add Changesets

When we finish development, we need to add a changeset to declare the current changes for version releases.

Information

A changeset includes:

  • Which packages are affected by this change.

  • The type of version for this change, which complies with the semver specification.

  • Changelog information for this change.

Steps

INFO

The following example commands are all using pnpm. If you need to use other package managers, please replace them as needed.

Modern.js Module

Run the change command in the root directory:

pnpm run change

Select the type of version for this change

Fill in the changelog information

After running, a corresponding changeset file will be created in the .changeset directory of the project, and the file content is as follows:

---
'module-changeset': patch
---

feat: test module solution changeset

This file contains all the information of the changeset.

Monorepo

There are three NPM module packages in the monorepo, module-1, module-2, and module-3.

Run the change command in the root directory

pnpm run change

Select the list of packages to upgrade for this change

Changesets will categorize the packages in the Monorepo into two categories, changed packages and unchanged packages, based on the current code changes (git diff Head...baseBranch), making it easy for users to choose.

Use the space key to select the corresponding package or category, and then press Enter after the selection is completed:

Select the packages corresponding to different version types

Changesets will ask about the major and minor types. If there are packages that have not selected these two types, the patch type will be used by default.

Fill in the changelog information

After running, a corresponding changeset file will be created in the .changeset directory of the project, and the file content is as follows:

---
'module-2': minor
'module-3': patch
---

feat: test-changeset

This file contains all the information of the changeset, and different packages will be marked according to the selected version type.

Parameters

The change command supports the following parameters:

  • --empty: Adds an empty changeset.
pnpm run change --empty

After running, an empty changeset file will be created in the .changeset directory of the project, and the file content is as follows:

---
---
  • --open: When using this parameter, the system default editor will be opened for filling in the changelog.

Notes

  • Not all changes require changesets

If the current change is to modify some infrastructure of the repository, such as CI, testing, etc., there is no need to add changesets, or an empty changeset can be added.

  • Multiple changesets can be submitted in one pull request

When a pull request has multiple feature developments or bug fixes, multiple pnpm run change commands can be executed to add multiple changeset files. Each file selects the corresponding packages for the feature and adds change information.

  • When creating a changeset, all packages related to the feature need to be selected

When creating a changeset in a Monorepo, all related packages to the feature need to be selected to avoid some packages not being published when releasing.