Перейти к основному содержимому
Версия: Будущая

Использование Changesets с pnpm

заметка

At the time of writing this documentation, the latest pnpm version was v10.4.1. The latest Changesets version was v2.28.0.

Установка

Чтобы установить changesets в workspace pnpm, установите changesets как dev зависимость в корне workspace:

pnpm add -Dw @changesets/cli

Then run changesets' init command to generate a changesets config:

pnpm changeset init

Добавление нового changesets

Чтобы сгенерировать новый набор изменений, запустите pnpm changeset в корне рабочей области. Сгенерированные файлы Markdown в папке .changeset должны быть зафиксированы в репозитории.

Релиз изменений

  1. Запуск pnpm changeset version. Это приведёт к загрузке версий пакетов ранее указанных с помощью pnpm changeset (и любых зависимых от них) и обновлению файлов в списке изменений.
  2. Запуск pnpm install. Это обновит lockfile и заново соберет пакеты.
  3. Зафиксированы изменения.
  4. Запуск pnpm publish -r. Это команда опубликует все, которые имеют измененные версии, еще нет в реестре.

Integration with GitHub Actions

To automate the process, you can use changeset version with GitHub actions. 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. The PR will automatically update itself every time a new changeset file arrives in main. Once merged the packages will be updated, and if the publish input has been specified on the action they will be published using the given command.

Add a publish script

Add a new script called ci:publish which executes pnpm publish -r. This will publish to the registry once the PR created by changeset version has been merged. If the package is public and scoped, adding --access=public may be necessary to prevent npm rejecting the publish.

package.json

{
"scripts": {
"ci:publish": "pnpm publish -r"
},
...
}

Add the workflow

Add a new workflow at .github/workflows/changesets.yml. This workflow will create a new branch and PR, so Actions should be given read and write permissions in the repo settings (github.com/<repo-owner>/<repo-name>/settings/actions). If including the publish input on the changesets/action step, the repo should also include an auth token for npm as a repository secret named NPM_TOKEN.

.github/workflows/changesets.yml

name: Changesets

on:
push:
branches:
- main

env:
CI: true

jobs:
version:
timeout-minutes: 15
runs-on: ubuntu-latest
steps:
- name: Checkout code repository
uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v4

- name: Setup node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'

- name: Install dependencies
run: pnpm install

- name: Create and publish versions
uses: changesets/action@v1
with:
commit: "chore: update versions"
title: "chore: update versions"
publish: pnpm ci:publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

More info and documentation regarding the changesets action can be found here.