When releasing a version, we need to upgrade the version of the corresponding packages based on the changeset generated during development, and run the publish command to publish them to NPM.
The following example commands are all using pnpm. If you need to use other package managers, please replace them as needed.
When running this command, changesets will automatically perform the following operations:
Delete all changeset files under the .changesets
directory.
Upgrade the package version based on the changeset information.
Write changelog information to the CHANGELOG.md
file in the root directory. The file will be automatically created if it does not exist.
When running this command, changesets will automatically perform the following operations:
Delete all changeset files under the .changesets
directory.
Upgrade the version of the relevant packages based on the changeset information. In addition to the packages written in the changeset, changesets will also analyze the dependency graph of all packages in the Monorepo during running. If is required, the version will be automatically upgraded accordingly.
Write changelog to the CHANGELOG.md
file in the directory of the package that needs to be upgraded. The file will be automatically created if it does not exist.
Make sure that the automatically upgraded version meet the expected requirements. If you need to understand the version upgrade strategy, please refer to Version Upgrade Strategy.
When running this command, it will sequentially determine whether the versions of all packages in the Monorepo exist on NPM. If they do not exist, the publish
command will be run to publish them.
When the dependencies between packages in the Monorepo are declared using workspace, do not directly run npm publish
to publish the package in the corresponding subdirectory of the package. Use the release
command instead. When publishing, the workspace declaration will be automatically removed to ensure that the NPM package is available after publishing.
bump
command--snapshot
: Generates a timestamp-based version.After running, the corresponding upgraded version will become 0.0.0-canary-20220622092823
, and canary
is the tag configured for snapshot. If not configured, it will directly generate the form of 0.0.0-20220622092823
.
This parameter is mainly used to publish temporary test versions for testing and does not require code submission.
--ignore
: Manually ignore some packages during publishing.For example, if you need to ignore the module-2
package for this release:
After running the command, the update of the module-2
package will be ignored. Note that if there are packages that depend on module-2
, the corresponding packages also need to be added to the ignore
parameter, otherwise the bump
command will fail.
The usage for adding multiple packages is as follows:
release
command--otp
: Uses npm token
to publish the package.--tag
: Uses a specific tag for publishing, and latest
is used by default.--ignore-scripts
: Ignores npm scripts during publishing.When running the publish
command, npm will automatically trigger many commands, such as prepare
and prepublish
. Using this parameter can ignore the running of these commands. This parameter is only supported in Monorepo using pnpm.
--no-git-checks
: Ignores checking the current branch during publishing.By default, when running the release
command, it will automatically check whether the current branch is a release branch, whether there are uncommitted changes, etc. Using this parameter can ignore git-related checks.
For example, the following scenario exists:
There are two packages in Monorepo, module-1
and module-2
, and module-1
exists in the dependencies
of module-2
.
The current changeset is the patch version upgrade of module-1
.
After running the bump
command, only the patch version of module-1
will be upgraded.
For example, the following scenario exists:
There are two packages in Monorepo, module-1
and module-2
, and module-1
exists in the dependencies
of module-2
.
The current changeset is the minor version upgrade of module-1
.
After running the bump
command, module-1
will upgrade the minor
version, and module-2
will upgrade the patch
version number.
For example, the following scenario exists:
There are two packages in Monorepo, module-1
and module-2
, and module-1
exists in the peerDependencies
of module-2
.
The current changeset is the patch version upgrade of module-1
.
After running the bump
command, both module-1
and module-2
will upgrade the patch version.
For example, the following scenario exists:
There are two packages in Monorepo, module-1
and module-2
, and module-1
exists in the peerDependencies
of module-2
.
The current changeset is the minor version upgrade of module-1
.
After running the bump command, module-1
will upgrade the minor
version, and module-2
will upgrade the major
version number.
The upgrade strategy of peerDependencies
can be modified by configuring onlyUpdatePeerDependentsWhenOutOfRange
. When only the declared version type range is exceeded, the corresponding peerDependencies
will be upgraded.
For example, the following scenario exists:
There are two packages in Monorepo, module-1
and module-2
, and module-1
exists in the peerDependencies
of module-2
, and the version of module-1
is declared using ^
.
The current changeset is the patch or minor version upgrade of module-1
.
After running the bump
command, only the version of module-1
will be upgraded.
Note that if the package version is in the 0.x.x
range, upgrading the minor
version is also beyond the declared version type range.