This document explains how to use changesets for version management and releasing packages in the Egg.js monorepo.
Changesets is a tool designed for managing versions and changelogs in multi-package repositories (monorepos). It allows you to:
- Track which packages need to be released
- Version packages independently instead of bulk releases
- Generate changelogs automatically
- Publish only the packages that have changed
When you make changes to packages in the monorepo that should be released:
# Create a changeset describing your changes
pnpm changesetThis will:
- Prompt you to select which packages have changed
- Ask for the version bump type (major, minor, or patch) for each package
- Prompt you to write a summary of the changes
- Create a markdown file in
.changeset/with your changeset information
When creating a changeset, you'll need to specify the version bump type:
- major: Breaking changes (e.g.,
1.0.0→2.0.0) - minor: New features, backwards compatible (e.g.,
1.0.0→1.1.0) - patch: Bug fixes, backwards compatible (e.g.,
1.0.0→1.0.1)
Commit the generated changeset files along with your code changes:
git add .changeset/
git commit -m "feat: add new feature"Once your PR is merged to the next branch:
- The GitHub Actions workflow automatically runs
- If changesets exist, it creates a "Version Packages" PR
- The Version Packages PR will:
- Update package versions based on changesets
- Update CHANGELOG.md files
- Remove consumed changesets
- When you merge the Version Packages PR, packages are automatically published to npm
pnpm changeset# This updates package.json versions and CHANGELOGs
pnpm run changeset:version# Build and publish changed packages
pnpm run changeset:publishFor testing purposes, you can create snapshot releases:
pnpm changeset version --snapshot
pnpm changeset publish --tag snapshotTo create prerelease versions:
# Enter prerelease mode
pnpm changeset pre enter beta
# Create changesets as usual
pnpm changeset
# Version and publish
pnpm run changeset:version
pnpm run changeset:publish
# Exit prerelease mode
pnpm changeset pre exitThe changeset configuration is in .changeset/config.json:
{
"baseBranch": "next",
"access": "public",
"ignore": ["@eggjs/monorepo", "helloworld-*", "site"]
}baseBranch: The main branch for releases (set tonext)access: Package publish access level (set topublic)ignore: Packages that should never be published
- Create changesets with your PR: Always create a changeset when making changes that should be released
- Write clear summaries: The changeset summary becomes part of the changelog
- Choose the correct bump type: Follow semantic versioning principles
- Review the Version PR: Check the Version Packages PR before merging to ensure versions are correct
- One changeset per feature: Create separate changesets for different features or fixes
- Bumped all package versions at once
- Required manual execution
- No automatic changelog generation
- All-or-nothing release approach
- Version only changed packages
- Automatic PR creation
- Automatic changelog generation
- Selective package releases
- Better tracking of what changed and why
If you forgot to create a changeset:
pnpm changesetIf you need to change a changeset:
- Delete the changeset file in
.changeset/ - Create a new one with
pnpm changeset
Check the GitHub Actions logs for details. Common issues:
- NPM authentication problems
- Build failures
- Network issues
The old version management scripts (scripts/version.js) are kept for backward compatibility and emergency use. However, changesets should be the primary method for version management going forward.
To gradually migrate:
- Start using changesets for new changes
- Create changesets in all new PRs
- Let the automated workflow handle versioning and publishing
- Eventually deprecate the old scripts once the team is comfortable with changesets