Version management automates the process of bumping package versions and generating changelogs based on accumulated changesets. This is the core transformation step that converts changeset intentions into concrete version updates.
Main function that processes all changesets and updates package versions accordingly.
/**
* Updates package versions and generates changelogs based on changesets
* @param cwd - Working directory path
* @param options.snapshot - Snapshot release mode (boolean or custom tag name)
* @param config - Changesets configuration object
*/
function version(
cwd: string,
options: {snapshot?: string | boolean},
config: Config
): Promise<void>;Usage Examples:
import { run } from "@changesets/cli";
// Standard version update
await run(["version"], {}, cwd);
// Snapshot release with default naming
await run(["version"], { snapshot: true }, cwd);
// Snapshot release with custom tag
await run(["version"], { snapshot: "canary" }, cwd);Snapshot releases allow for experimental or pre-production versions without affecting the main release flow.
Snapshot Version Format:
0.0.0-{timestamp}-{commit}0.0.0-{tag}-{timestamp}-{commit}snapshotPrereleaseTemplate// Snapshot with custom template
config.snapshot.prereleaseTemplate = "{tag}-{commit}-{timestamp}";
await version(cwd, { snapshot: "alpha" }, config);
// Result: 1.2.3-alpha-abc1234-20231201120000The version command processes changesets to determine appropriate version bumps:
// Configuration options for internal dependency handling
interface Config {
updateInternalDependencies: "patch" | "minor";
bumpVersionsWithWorkspaceProtocolOnly: boolean;
linked: ReadonlyArray<ReadonlyArray<string>>;
fixed: ReadonlyArray<ReadonlyArray<string>>;
}Dependency Update Rules:
Changesets automatically generates CHANGELOG.md files for each updated package:
# @myorg/ui
## 1.2.0
### Minor Changes
- abc1234: Added new Button component with accessibility features
### Patch Changes
- def5678: Fixed styling issue in Card component
- Updated dependencies
- @myorg/utils@2.1.0// Configuration for custom changelog generation
interface Config {
changelog: readonly [string, any] | false;
}
// Example configuration
{
"changelog": ["@changesets/changelog-git", {
"repo": "myorg/myrepo"
}]
}Exclude specific packages from version updates:
// Via CLI flags
await run(["version"], {
ignore: ["@myorg/internal", "@myorg/docs"]
}, cwd);
// Via configuration
{
"ignore": ["@myorg/internal", "@myorg/docs"]
}interface Config {
privatePackages: {
version: boolean; // Whether to version private packages
tag: boolean; // Whether to tag private packages
};
}Utility function to identify packages that should be versioned:
/**
* Gets changed packages that are versionable
* @param config - Changesets configuration
* @param options.cwd - Working directory
* @param options.ref - Git reference to compare against
* @returns Promise resolving to array of versionable packages
*/
function getVersionableChangedPackages(
config: Config,
options: {cwd: string, ref?: string}
): Promise<Package[]>;The version command uses release planning to coordinate updates:
interface ReleasePlan {
changesets: Changeset[];
releases: Release[];
preState: PreState | undefined;
}
interface Release {
name: string;
type: "major" | "minor" | "patch" | "none";
oldVersion: string;
newVersion: string;
changelog: string | null;
}For packages in prerelease mode:
interface PreState {
mode: "pre";
tag: string;
initialVersions: Record<string, string>;
changesets: string[];
}Before version updates, the system validates:
// Changesets are processed and then deleted
// This ensures each changeset is only applied once
const changesets = await read(cwd);
// ... process changesets ...
await cleanupChangesets(changesets);Version updates integrate with git workflows:
.changeset directory// Validates that all dependents of ignored packages are also ignored
const dependentsGraph = getDependentsGraph(packages);
for (const skippedPackage of ignoredPackages) {
const dependents = dependentsGraph.get(skippedPackage);
// Ensure all dependents are also ignored
}{
"updateInternalDependencies": "patch",
"bumpVersionsWithWorkspaceProtocolOnly": false,
"snapshot": {
"useCalculatedVersion": false,
"prereleaseTemplate": null
}
}{
"linked": [
["@myorg/ui", "@myorg/theme"],
["@myorg/client", "@myorg/server"]
],
"fixed": [
["@myorg/core", "@myorg/utils", "@myorg/helpers"]
]
}Linked vs Fixed: