pnpm에서 changesets 사용하기
At the time of writing this documentation, the latest pnpm version was v10.4.1. The latest Changesets version was v2.28.0.
설치
pnpm 워크스페이스에서 changesets를 설정하려면 워크스페이스의 루트에서 개발 의존성으로 changesets를 설치하세요.
pnpm add -Dw @changesets/cli
Then run changesets' init command to generate a changesets config:
pnpm changeset init
새 changesets 추가하기
새 changesets를 생성하려면 저장소의 루트에서 pnpm changeset
를 실행하세요. .changeset
디렉토리에 생성된 마크다운 파일은 저장소에 커밋되어야 합니다.
변경 사항 릴리즈하기
pnpm changeset version
을 실행합니다.pnpm changeset
(및 이들의 의존 항목)로 지정된 패키지의 버전을 bump하고 changelog 파일을 업데이트합니다.pnpm install
를 실행합니다. 이를 통해 lockfile을 업데이트하고 패키지를 재빌드합니다.- 변경 사항을 커밋합니다.
pnpm publish -r
를 실행합니다. 이 명령어는 아직 레지스트리에 없고 버전 충돌된 모든 패키지들을 게시합니다.
Integration with GitHub Actions
To automate the process, you can use changeset version
with GitHub actions. changeset 파일이 main
브랜치에 도착하면 action이 감지하며, bump된 버전에 대한 모든 패키지를 나열하는 새 PR을 엽니다. 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.