Skip to content

Version and Changelog Management

Changeset is a tool for managing versions and generating changelogs, especially suitable for Monorepo projects. This guide details how to use Changeset to manage versions and releases for VUP projects.

What is Changeset

Changeset is a version management tool that provides:

  • Semantic Versioning - Automatic version number management
  • Changelog Generation - Automatic generation of detailed changelogs
  • Monorepo Support - Support for multi-package version management
  • Release Management - Automated release process
  • Change Tracking - Track the impact of each change

Quick Start

VUP project has Changeset pre-configured and ready to use:

1. View Existing Configuration

bash
# View .changeset directory
ls .changeset/

# View configuration file
cat .changeset/config.json

2. Add Changes

bash
# Add change records
pnpm changeset

# Select change type
# - patch: Bug fixes
# - minor: New features
# - major: Breaking changes

3. Generate Versions

bash
# Generate version updates
pnpm changeset version

# Publish changes
pnpm changeset publish

Change Types

Patch (Patch Version)

Used for bug fixes and minor improvements:

bash
# Example: Fix login issue
- Fix user login failure issue
- Optimize error message display

Version Change: 1.0.01.0.1

Minor (Minor Version)

Used for new features and backward-compatible improvements:

bash
# Example: Add new features
- Add user avatar upload feature
- Add dark mode support
- Optimize page loading speed

Version Change: 1.0.01.1.0

Major (Major Version)

Used for breaking changes:

bash
# Example: Breaking changes
- Refactor API interface, remove old version support
- Change component API structure
- Upgrade dependency versions, requires Node.js 18+

Version Change: 1.0.02.0.0

Project Configuration

.changeset/config.json

json
{
  "$schema": "https://unpkg.com/@changesets/config@2.3.1/schema.json",
  "changelog": "@changesets/cli/changelog",
  "commit": false,
  "fixed": [],
  "linked": [],
  "access": "public",
  "baseBranch": "main",
  "updateInternalDependencies": "patch",
  "ignore": []
}

package.json Scripts

json
{
  "scripts": {
    "changeset": "changeset",
    "version-packages": "changeset version",
    "release": "changeset publish"
  }
}

Workflow

1. Develop New Features

bash
# Create feature branch
git checkout -b feature/new-feature

# Develop feature
# ... write code ...

# Commit code
git add .
git commit -m "feat: add new feature"

2. Add Change Records

bash
# Add change records
pnpm changeset

# Select change type
? Select a package: @vup/cli
? Select a package: @vup/templates
? Select a package: @vup/docs
? What kind of change is this for @vup/cli? minor
? What kind of change is this for @vup/templates? patch
? What kind of change is this for @vup/docs? patch
? Please enter a summary for this change: Add new feature support

3. Commit Changes

bash
# Commit change records
git add .
git commit -m "chore: add changeset for new feature"
git push origin feature/new-feature

4. Merge to Main Branch

bash
# Merge PR
git checkout main
git pull origin main

# Generate version updates
pnpm changeset version

# Commit version updates
git add .
git commit -m "chore: version packages"
git push origin main

5. Release Version

bash
# Publish to NPM
pnpm changeset publish

# Create Git tag
git tag v1.1.0
git push origin v1.1.0

Changelog Format

Auto-generated Changelog

markdown
# @vup/cli

## 1.1.0

### Minor Changes

- Add new feature support

## 1.0.1

### Patch Changes

- Fix login issue
- Optimize error messages

Manually Added Changelog

markdown
# Changelog

All notable changes to this project will be documented in this file.

## [1.1.0] - 2024-01-15

### Added

- Add user avatar upload feature
- Add dark mode support
- Optimize page loading speed

### Changed

- Update dependency versions
- Optimize build configuration

### Fixed

- Fix login failure issue
- Fix page refresh issue

## [1.0.0] - 2024-01-01

### Added

- Initial version release
- Basic feature implementation

Multi-package Management

Configure in .changeset/config.json:

json
{
  "linked": [
    ["@vup/cli", "@vup/templates"],
    ["@vup/docs", "@vup/homepage"]
  ]
}

Fixed Package Versions

json
{
  "fixed": [["@vup/cli", "@vup/templates", "@vup/docs"]]
}

Release Strategy

Automatic Release

Use GitHub Actions for automatic release:

yaml
name: Release
on:
  push:
    branches: [main]

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: 18
          registry-url: https://registry.npmjs.org/
      - run: pnpm install
      - run: pnpm changeset version
      - run: pnpm changeset publish
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

Manual Release

bash
# Check changes
pnpm changeset status

# Generate versions
pnpm changeset version

# Publish packages
pnpm changeset publish

Best Practices

1. Change Records

  • Use clear and concise descriptions
  • Include the scope of impact
  • Follow semantic versioning standards

2. Version Management

  • Release versions regularly
  • Avoid accumulating changes for too long
  • Maintain consistency in version numbers

3. Changelog

  • Keep changelog complete
  • Use unified format
  • Update and maintain regularly

4. Release Process

  • Test thoroughly before release
  • Use automation tools to reduce errors
  • Maintain consistency in release process

Common Issues

Issue 1: Missing Change Records

Cause: Forgot to commit .changeset directory

Solution:

bash
# Check change records
ls .changeset/

# Add change records
git add .changeset/
git commit -m "chore: add changeset"

Issue 2: Version Conflicts

Cause: Multiple package versions don't match

Solution:

bash
# Check version status
pnpm changeset status

# Manually adjust versions
pnpm changeset version

Issue 3: Release Failure

Cause: NPM authentication or network issues

Solution:

bash
# Check NPM authentication
npm whoami

# Re-login
npm login

# Retry release
pnpm changeset publish