Skip to main content
Version: 9.x

将变更集与 pnpm 结合使用

注意

在撰写本文档时,最新的 pnpm 版本是 v6.14。最新的 变更集 版本是 v2.16.0。

¥At the time of writing this documentation, the latest pnpm version was v6.14. The latest Changesets version was v2.16.0.

设置

¥Setup

要在 pnpm 工作区上设置变更集,请将变更集作为开发依赖安装在工作区的根目录中:

¥To setup changesets on a pnpm workspace, install changesets as a dev dependency in the root of the workspace:

pnpm add -Dw @changesets/cli

然后更改 sets 的 init 命令:

¥Then changesets' init command:

pnpm changeset init

添加新的变更集

¥Adding new changesets

要生成新的变更集,请在存储库的根目录中运行 pnpm changeset.changeset 目录中生成的 markdown 文件应提交到存储库。

¥To generate a new changeset, run pnpm changeset in the root of the repository. The generated markdown files in the .changeset directory should be committed to the repository.

发布变更

¥Releasing changes

  1. 运行 pnpm changeset version。这将提升之前使用 pnpm changeset 指定的软件包的版本(以及这些软件包的任何依赖)并更新变更日志文件。

    ¥Run pnpm changeset version. This will bump the versions of the packages previously specified with pnpm changeset (and any dependents of those) and update the changelog files.

  2. 运行 pnpm install。这将更新锁定文件并重建包。

    ¥Run pnpm install. This will update the lockfile and rebuild packages.

  3. 提交更改。

    ¥Commit the changes.

  4. 运行 pnpm publish -r。此命令将发布注册表中尚未存在的已升级版本的所有软件包。

    ¥Run pnpm publish -r. This command will publish all packages that have bumped versions not yet present in the registry.

使用 GitHub Actions

¥Using GitHub Actions

要自动化该过程,你可以将 changeset version 与 GitHub Actions 结合使用。

¥To automate the process, you can use changeset version with GitHub actions.

提升软件包版本

¥Bump up package versions

该操作将检测变更集文件何时到达 main 分支,然后打开一个新的 PR,列出所有版本已更改的软件包。合并后,包将被更新,你可以通过添加 publish 属性来决定是否发布。

¥The action will detect when changeset files arrive in the main branch, and then open a new PR listing all the packages with bumped versions. Once merged, the packages will be updated and you can decide whether to publish or not by adding the publish property.

发布

¥Publishing

添加执行 pnpm publish -r 的新脚本 ci:publish。一旦 changeset version 打开 PR,它将发布到注册表。

¥Add a new script ci:publish which executes pnpm publish -r. It will publish to the registry once the PR is opened by changeset version.

package.json

{
"scripts": {
"ci:publish": "pnpm publish -r"
},
...
}
name: Changesets
on:
push:
branches:
- main
env:
CI: true
PNPM_CACHE_FOLDER: .pnpm-store
jobs:
version:
timeout-minutes: 15
runs-on: ubuntu-latest
steps:
- name: checkout code repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: setup node.js
uses: actions/setup-node@v3
with:
node-version: 14
- name: install pnpm
run: npm i pnpm@latest -g
- name: Setup npmrc
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
- name: setup pnpm config
run: pnpm config set store-dir $PNPM_CACHE_FOLDER
- name: install dependencies
run: pnpm install
- name: create and publish versions
uses: changesets/action@v1
with:
version: pnpm ci:version
commit: "chore: update versions"
title: "chore: update versions"
publish: pnpm ci:publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

有关此操作的更多信息和文档可以找到 此处

¥More info and documentation regarding this action can be found here.