Using Changesets with pnpm

Using Changesets with pnpm - 图1note

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

Setup

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

  1. pnpm add -DW @changesets/cli

Then changesets’ init command:

  1. pnpm changeset init

Adding new changesets

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. 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. Run pnpm install. This will update the lockfile and rebuild packages.
  3. Commit the changes.
  4. Run pnpm publish -r. This command will publish all packages that have bumped versions not yet present in the registry.

Using GitHub Actions

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

Bump up package versions

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

By adding publish: pnpm ci:publish which is a script that executes changeset publish will publish to the registry once the PR is opened by changeset version.

  1. name: Changesets
  2. on:
  3. push:
  4. branches:
  5. - main
  6. env:
  7. CI: true
  8. PNPM_CACHE_FOLDER: .pnpm-store
  9. jobs:
  10. version:
  11. timeout-minutes: 15
  12. runs-on: ubuntu-latest
  13. steps:
  14. - name: checkout code repository
  15. uses: actions/checkout@v3
  16. with:
  17. fetch-depth: 0
  18. - name: setup node.js
  19. uses: actions/setup-node@v3
  20. with:
  21. node-version: 14
  22. - name: install pnpm
  23. run: npm i pnpm@latest -g
  24. - name: Setup npmrc
  25. run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
  26. - name: setup pnpm config
  27. run: pnpm config set store-dir $PNPM_CACHE_FOLDER
  28. - name: install dependencies
  29. run: pnpm install
  30. - name: create and publish versions
  31. uses: changesets/action@master
  32. with:
  33. version: pnpm ci:version
  34. commit: "chore: update versions"
  35. title: "chore: update versions"
  36. publish: pnpm ci:publish
  37. env:
  38. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

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