Changesets
This document explains how the Gasket monorepo uses changesets for versioning and publishing packages.
Overview
Changesets is a tool that helps manage versioning and changelogs in multi-package repositories. It allows contributors to declare their intent to release packages and automatically handles version bumping, changelog generation, and publishing.
Configuration
The changeset configuration is located in .changeset/config.json
:
{
"$schema": "https://unpkg.com/@changesets/config@3.0.5/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
Key settings:
access: "public"
- All packages are published publicly to npmbaseBranch: "main"
- The main branch is used as the base for versioningupdateInternalDependencies: "patch"
- Internal dependencies get patch bumps when the dependency is updated
Workflow
For Contributors
- Make your changes to the codebase
- Create a changeset by running:
pnpm run changeset
- Follow the prompts to:
- Select which packages are affected
- Choose the version bump type (major, minor, patch)
- Write a summary of your changes
- Commit the generated changeset file (in
.changeset/
) with your PR
For Maintainers
- When PRs with changesets are merged to
main
, a "Version Packages" PR is automatically created - This PR will:
- Bump package versions based on changesets
- Update changelogs
- Delete consumed changeset files
- When ready to publish, merge the "Version Packages" PR
- The CI workflow will automatically publish packages to npm
Available Scripts
pnpm run changeset
- Create a new changesetpnpm run version
- Apply changesets and bump versions (used by CI)pnpm run release
- Publish packages to npm (used by CI)pnpm run publish:canary
- Publish canary releasespnpm run publish:next
- Publish next/pre-releases
CI/CD Integration
The release workflow (.github/workflows/release.yml
) runs on:
- Manual trigger (workflow_dispatch)
- Pushes to the main branch
It uses the changesets/action to:
- Create/update the "Version Packages" PR when changesets exist
- Publish packages when the version PR is merged
Limitations
Peer Dependency Version Updates
When using changesets in a monorepo, peer dependencies are automatically updated from range versions (e.g., ^7
) to specific versions (e.g., ^7.3.5
) during the release process. This is built-in behavior with no direct configuration option to disable it.
Why This Happens
Changesets updates peer dependency versions to ensure version consistency across the monorepo. When a package is released, changesets will:
- Update the package version
- Update all internal dependencies that reference this package
- Update peer dependencies to match the exact published version
Example
If @gasket/plugin-logger
is at version 7.3.5
, and another package has:
"peerDependencies": {
"@gasket/plugin-logger": "^7"
}
After running changeset version
, it becomes:
"peerDependencies": {
"@gasket/plugin-logger": "^7.3.5"
}
Relevant Links
- Changesets Decisions - Versioning of Peer Dependencies
- #822 - Add an option to avoid major bump when peerDep has changed
- #542 - Add new config option for always upgrading internal dependents
Workarounds
- Manual Updates: Update the version packages PR to revert peer dependency changes before merging
- Post-process Script: Add a script that runs after
changeset version
to revert changes - Accept the Behavior: Consider whether exact versions might be beneficial for consistency
Best Practices
- One changeset per feature/fix: Create focused changesets that describe a single change
- Clear summaries: Write descriptive summaries that will be meaningful in changelogs
- Correct version bumps:
patch
- Bug fixes, dependency updatesminor
- New features, backward-compatible changesmajor
- Breaking changes
- Review generated changelogs: Check the "Version Packages" PR to ensure changes look correct
Troubleshooting
Missing changesets
If CI complains about missing changesets, but your change doesn't affect any packages:
- Create an empty changeset:
pnpm run changeset --empty
Changeset not detected
Ensure the changeset file is committed and pushed with your PR.
Version conflicts
If you see version conflicts, ensure your branch is up to date with main
.