Version Command

Automatically version and generate changelogs for all packages.

bash
melos version

Fixed versioning mode

By default, each package is versioned independently, based on the commits that touched that package. If you prefer all packages in the workspace to always share the same version (also known as lockstep versioning, and similar to the "fixed" release mode of tools like Nx and Lerna), set the command/version/mode configuration to fixed:

yaml
melos:
  command:
    version:
      mode: fixed

In fixed mode, melos version:

  • Determines a single new version for the whole workspace: the highest current package version, incremented by the most significant change across all packages (major if any package has a breaking change, minor if any package has a new feature, otherwise patch).
  • Bumps every package in the workspace to that version, including packages without changes of their own. Their changelog notes that the version was bumped to keep the workspace in lockstep, while packages with changes get their regular changelog entries.
  • Applies a manually specified version (melos version <package> <version>) to all packages in the workspace. Relative version changes (major, minor, patch or build) are applied to the highest current version in the workspace, regardless of which package was named.
  • Leaves packages that are already at the new shared version untouched.

Private packages are still skipped unless --all is passed, and packages excluded with filters (e.g. --ignore) are not bumped, so use filters with care if you want the workspace to stay in sync. Since all packages are versioned together, --no-dependent-versions has no effect in fixed mode.

If there are no versionable changes in any package, melos version does nothing, just like in independent mode.

By default each package is still tagged individually, e.g. foo-v1.2.3. To tag each release with a single plain version tag for the whole workspace instead, e.g. v1.2.3, enable command/version/workspaceTag:

yaml
melos:
  command:
    version:
      mode: fixed
      workspaceTag: true

Hooks

The version command supports the following hooks in addition to the common hooks:

  • preCommit: Runs before the version commit is created. Allows you to make your own changes as part of versioning. You need to stage changes that you make yourself.
yaml
command:
  version:
    hooks:
      preCommit: |
        # Make changes to the version commit here.
        # You need to stage changes that you make yourself.

--prerelease (-p)

Version any packages with changes as a prerelease. Cannot be combined with graduate flag. Defaults to false.

bash
melos version --prerelease
melos version -p

--graduate (-g)

Graduate current prerelease versioned packages to stable versions, e.g. "0.10.0-dev.1" becomes "0.10.0". Cannot be combined with prerelease flag. Defaults to false.

bash
melos version --graduate
melos version -g

--[no-]changelog (-c)

Update CHANGELOG.md files (based on conventional commit messages). Defaults to true.

bash
melos version --changelog
melos version -c

Use --no-changelog to disable.

--[no-]git-tag-version (-t)

Create a git tag. Defaults to true.

bash
melos version --git-tag-version
melos version -t

Use --no-git-tag-version to disable.

--[no-]sign-off (-s)

Add a Signed-off-by trailer to the version commit, the same as passing --signoff to git commit. Defaults to false.

bash
melos version --sign-off
melos version -s

Use --no-sign-off to disable.

The default for this option can be configured in command/version/signOff in your root pubspec.yaml file.

--[no-]release-url (-r)

Generate and print a link to the prefilled release creation page for each package after versioning. Defaults to false.

bash
melos version --release-url
melos version -r

Use --no-release-url to disable.

The default for this option can be configured in command/version/releaseUrl in your root pubspec.yaml file.

--[no-]group-commits

Group changelog entries by their conventional commit type, e.g. all features under a Features header and all fixes under a Bug Fixes header, instead of listing them in a single flat list. Defaults to false.

bash
melos version --group-commits

Use --no-group-commits to disable.

The default for this option can be configured in command/version/changelogFormat/groupByType in your root pubspec.yaml file.

--[no-]dependent-constraints

Update dependency version constraints of packages in this workspace that depend on any of the packages that will be updated with this versioning run. (defaults to on)

bash
melos version --no-dependent-constraints

Use --no-dependent-constraints to disable.

--[no-]dependent-versions

Make a new patch version and changelog entry in packages that are updated due to "--dependent-constraints" changes. Only usable with "--dependent-constraints" enabled and Conventional Commits based versioning. (defaults to on)

bash
melos version --no-dependent-versions

Use --no-dependent-versions to disable.

--[no-]smart-dependents

Only bump dependent package versions and rewrite dependency constraints when declared SemVer constraints do not allow the updated version. When enabled, packages whose declared constraints already satisfy the new dependency version are skipped. (defaults to off)

bash
melos version --smart-dependents

The default for this option can be configured in command/version/smartDependents in your root pubspec.yaml file.

--all (-a)

Version private packages that are skipped by default.

bash
melos version --all
melos version -a

--preid

When run with this option, melos version will increment prerelease versions using the specified prerelease identifier, e.g. using a "beta" preid along with the --prerelease flag would result in a version in the format "1.0.0-1.0.beta.0". Applies only to Conventional Commits based versioning.

bash
melos version --prerelease --preid=beta

--dependent-preid

This option is the same as --preid, but only applies to packages that are versioned due to a change in a dependency version. When this option is not provided but the --preid option is, the value of the --preid option will be used instead.

bash
melos version --prerelease --dependent-preid=beta

--message (-m)

Override the release's commit message. If the message contains {new_package_versions}, it will be replaced by the list of newly versioned package names. If --message is not provided, the message will default to:

text
chore(release): publish packages

{new_package_versions}

Example:

bash
melos version --message="chore(release): publish new versions"

--manual-version (-V)

Manually specify a version change for a package. Can be used multiple times. Each value must be in the format <package name>:<major|patch|minor|build|exactVersion>. Cannot be combined with --graduate or --prerelease flag.

bash
melos version --manual-version=foo:patch
melos version --manual-version=foo:1.0.0
melos version -V foo:1.0.0

# To manually version multiple packages
melos version --manual-version=foo:patch --manual-version=bar:major
melos version --manual-version=foo:1.0.0 --manual-version=bar:1.0.0
melos version -V foo:1.0.0 -V bar:2.0.0