@lerna/version

The Bump version of the package has changed since the last release

use

Lerna Version 1.0.1 # Explicit Lerna version patch # Semver keyword lerna version # select from the promptsCopy the code

When run, this command does the following:

  • Identifies packages that have been updated since the last markup version.

  • Prompt for a new version.

  • Modify the package metadata to reflect the new release and run the appropriate lifecycle scripts in the root directory and in each package.

  • Commit these changes and mark the commit.

  • Push to git remote.

Positionals

semver bump

Lerna version [major | minor | patch | premajor | preminor | prepatch | prerelease] # using the next version of semantic value, it will skip the "as..." A prompt to select a new versionCopy the code

When this location parameter is passed, Lerna Version skips the version selection prompt and increments the version by the keyword. You still have to use the –yes flag to avoid all prompts.

pre-release

If you have any packages with pre-released version numbers (e.g. 2.0.0-beta.3) and you run lerna versions with and without pre-released Bump (major, minor, or patch), it will release those packages that were pre-released previously as well as those that have changed since the last release.

For projects that use regular submissions, use the following flags for pre-release management:

  • — Convention-prerelease: publishes current changes as pre-released versions.
  • – Conventional -graduate: Upgrades the pre-release package to a stable version. Running LERna version — Conventionally commits without the above flag will post the current change as PRERelease only when the version is already prerelease.

options

–allow-branch

Whitelist of Globs that match git branches with Lerna Version enabled. Configuration in lerna.json is easiest (and recommended), but can also be passed as a CLI option.

{
  "command": {
    "version": {
      "allowBranch": "master"
    }
  }
}
Copy the code

Using the above configuration, lerna version will fail when running from any branch other than the master node. Limiting lerna versions to master branches is considered a best practice.

{
  "command": {
    "version": {
      "allowBranch": ["master", "feature/*"]
    }
  }
}
Copy the code

In the previous configuration, any branch prefixed with feature/ was allowed to use lerna version. Note that generating Git tags in the functional branch is fraught with potential errors when the branch is merged into the main branch. If the tags are “detached” from their original context (perhaps by compression merge or collision merge submission), then subsequent lerna version executions will have a hard time determining the correct “differences since the last release”

This “persistent” configuration can always be overridden on the command line. Use with caution.

lerna version --allow-branch hotfix/oops-fix-the-thing
Copy the code

–amend

lerna version --amend
# commit message is retained, and `git push` is skipped.
Copy the code

Keep the commit message and skip “Git push.”

When run with this flag, Lerna Version performs all changes to the current commit rather than adding new changes. This is useful during continuous integration (CI) to reduce the number of commits in the project history.

To prevent accidental rewriting, this command skips Git push (that is, it means –no push).

–changelog-preset

lerna version --conventional-commits --changelog-preset angular-bitbucket
Copy the code

By default, change Log is set to Angular by default. In some cases, you may need to change using other presets or custom presets.

The default is the name of the built-in or installable configuration for the regular change log. The default can be used as the full name of a package or as an automatic extension suffix (for example, Angular extends from Convention-Changelog-Angular).

–conventional-commits

lerna version --conventional-commits
Copy the code

When run with this flag, Lerna Version uses traditional commit specifications to determine version transitions and generate change changelog.md files.

Passing — no-Changelog will disable generating (or updating) the Changelog.md file.

–conventional-graduate

Description LERna version -- Straw-graduate =package-2,package-4 --conventional-commits --conventional-graduateCopy the code

When run with this flag, Lerna Version uses * to grade the specified package (comma separated) or all packages. This command works regardless of whether the current header is released or not, similar to –force publish, except that any non-pre-published packages are ignored. If changes are made to packages that are not specified (if specified) or that are not in the pre-release, those packages will be versioned according to the normal commit normally used.

To “switch” a package means to encounter a non-pre-released version of a pre-released version, for example. [email protected] = > [email protected].

Package dependencies are not specified, but package hierarchies are not specified.

–conventional-prerelease

Lerna version -- XxXle-commits -- XXxle-PRERelease =package-2,package-4 # --conventional-commits --conventional-prereleaseCopy the code

When run with this flag, lerna Version publishes the specified package (comma-separated) or all packages with * using the pre-released version. (patch will be released all did not change as the pre/minor/major/release), the method is in front of the routine to submit version and the pre, for example, if the current changes submitted contains function, the bump is recommended will be minor, so this flag will cause preminor version. If changes are made to packages that are not specified (if specified) or that are already in the pre-release, they will be versioned according to the normal commit normally used.

–create-release

lerna version --conventional-commits --create-release github
lerna version --conventional-commits --create-release gitlab
Copy the code

When run with this flag, Lerna Version creates an official GitHub or GitLab version based on the changed package. Need — Straw-commits in order to generate the change log.

To use GitHub for authentication, you can define the following environment variables.

  • GH_TOKEN (Required) – Your GitHub authentication token (under Settings > Developer Settings > Personal Access Token).
  • GHE_API_URL – The absolute URL of the API when using GitHub Enterprise.
  • GHE_VERSION – The version of GHE currently installed when using GitHub Enterprise. The following versions are supported.

To authenticate with GitLab, you can define the following environment variables.

  • GL_TOKEN (Required) – Your GitLab authentication token (under User Settings > Access Token).
  • GL_API_URL – The absolute URL of the API, including version. (Default: gitlab.com/api/v4)

Note: When using this option, you cannot pass –no Changelog.

You can also specify this option in lerna.json configuration:

{
  "changelogPreset": "angular"
}
Copy the code

If you predefined export a builder function (for example, Convention-Changelog-Conventionalcommits), you can also specify predefined configurations:

{
  "changelogPreset": {
    "name": "conventionalcommits",
    "issueUrlFormat": "{{host}}/{{owner}}/{{repository}}/issues/{{id}}"
  }
}
Copy the code

–exact

lerna version --exact
Copy the code

When run with this flag, lerna Version will specify exactly the updated dependencies (without punctuation) in the updated package, rather than semver compatibility (with a ^).

See the package.json dependency documentation for more information.

–force-publish

Lerna version --force-publish=package-2,package-4Copy the code

When run with this flag, the LERna version forces the release of specified packages (comma-separated) or all packages with *.

This skips lerna CHANGED checks on changed packages and forces updates to packages without git diff changes.

–git-remote

lerna version --git-remote upstream
Copy the code

When run with this flag, lerna Version pushes git changes to the specified remote instead of the source.

–ignore-changes

The changes in the files that match the glob are ignored while detecting the changed package.

lerna version --ignore-changes '**/*.md' '**/__tests__/**'
Copy the code

This option is best specified as the root Lerna. json configuration to avoid premature shell evaluation of globs and to share the configuration with Lerna Diff and Lerna CHANGED:

{
  "ignoreChanges": ["**/__fixtures__/**", "**/__tests__/**", "**/*.md"]
}
Copy the code

Pass –no-ignore-changes to disable any existing persistence configuration.

The package will always be released regardless of this option if: 1. The latest version of the package is a pre-release version (that is, 1.0.0-alpha, 1.0.0-0.3.7, etc.). 2. One or more link dependencies of the package have changed.

–ignore-scripts

When passed, this flag disallows life cycle scripts to run during lerna Version.

–include-merged-tags

lerna version --include-merged-tags
Copy the code

Include tags from merge branches when detecting changed packages.

–message

This option is alias -m for parity with git commit.

lerna version -m "chore(release): publish %s" # commit message = "chore(release): Publish v1.0.0" lerna version -m "chore(Release): publish %v" # commit message = "chore(Release): Lerna version -m "chore(Release): publish" # commit message = "chore(Release): Publish # # - [email protected] # - [email protected]"Copy the code

When run with this flag, Lerna Version uses the supplied message when committing the release update. It can be useful for integrating LERNA into projects that want to submit messages following certain guidelines, such as those published using Commitizen and/or semantics.

If the message contains %s, it is replaced with a new global version number prefixed with “v”. If the message contains %v, it is replaced with a new global version number without a leading “v”. Note that this placeholder interpolation only works when the default “fixed” version control mode is used, because there is no “global” version to insert when versioning independently.

It can be configured in lerna.json, and:

{
  "command": {
    "version": {
      "message": "chore(release): publish %s"
    }
  }
}
Copy the code

–no-changelog

lerna version --conventional-commits --no-changelog
Copy the code

When Xstraw-commits are used, no Changelog. md files are generated

Note: You cannot pass –create Release when using this option.

–no-commit-hooks

By default, Lerna Version will allow Git commit hooks to run when a version change is committed. Pass –no-commit-hooks commit hooks used to disable this behavior.

This option is similar to the NPM version option –commit-hooks, reversed.

–no-git-tag-version

By default, lerna version will be committed to package.json files and marked for publication. Pass –no-git-tag-version to disable this behavior.

This option is similar to the NPM version option –git-tag-version reversed.

–no-granular-pathspec

By default, Lerna Version git adds a list of leaf packages (and possibly Changelogs) that have changed during version control. This will produce the equivalent of git add — packages/*/package.json, but fully adapted to the changes.

If you know you need a different behavior, you’ll know that passing –no-granular- pathSpec makes the Git command literally git add–. By selecting this path specification, all secrets must be correctly ignored and output generated, otherwise it will be committed and pushed.

Configuring this option in lerna.json makes the most sense, because you really don’t want to mess things up:

{
  "version": "independent",
  "granularPathspec": false
}
Copy the code

The root-level configuration is intentional because it also includes the option of the same name in Lerna Publish.

–no-private

By default, lerna Version will contain private packages when selecting a version, committing, and marking a release. –no-private to disable this behavior.

Note that this option does not exclude private scoped packages, only those in their package.json file “private”: true.

–no-push

By default, lerna Version pushes committed and marked changes to the configured Git remote. –no-push to disable this behavior.

–preid

Lerna version prerelease # uses the next semantic pre-release version, for example. Lerna version prepatch --preid Next # Use the next semantic pre-release version with a specific pre-release identifier, e.g. # 1.0.0 = > - next 1.0.1. 0Copy the code

When run with this flag, lerna Version adds prejor, Preminor, Prepatch, or PRERelease semver bumps using the specified PRERelease identifier.

–sign-git-commit

This option is similar to the NPM Version option of the same name.

–sign-git-tag

This option is similar to the NPM Version option of the same name.

–force-git-tag

This option replaces any existing tags instead of failing.

–tag-version-prefix

This option allows you to provide a custom prefix instead of the default: v.

Remember that you must currently provide twice: for the version command and for the publish command:

# locally
lerna version --tag-version-prefix=''
# on ci
lerna publish from-git --tag-version-prefix=''
Copy the code

–yes

lerna version --yes # skips `Are you sure you want to publish these packages? `Copy the code

When run with this flag, the LERna version skips all confirmation prompts. Useful in continuous integration (CI) to automatically respond to release confirmation prompts.

prompt

Generate an initial change log

If the — Conditional commits option is used after monorepo has been activated for a period of time, the traditional Changelog CLI and Lerna exec can still generate change logs for previous versions:

# Lerna doesn't actually use the traditional Changelog CLI, so you need to temporarily install it NPM I -d Conventional - Changelog -cli # Documentatiional-on: `npx conventchangelog --help` # fixed versioning (default) # run in root, then leaves npx conventional-changelog --preset angular --release-count 0 --outfile ./CHANGELOG.md --verbose npx lerna exec --concurrency 1 --stream -- 'conventional-changelog --preset angular --release-count 0 --commit-path $PWD --pkg $PWD/package.json --outfile $PWD/CHANGELOG.md --verbose' # independent versioning # (no root changelog) npx lerna exec --concurrency 1 --stream -- 'conventional-changelog --preset angular --release-count 0 --commit-path $PWD --pkg $PWD/package.json --outfile $PWD/CHANGELOG.md --verbose --lerna-package $LERNA_PACKAGE_NAME'Copy the code

If a custom — Changelog preset is used, the — Preset value should be changed accordingly in the example above.

Lifecycle Scripts

// preversion:  Run BEFORE bumping the package version.
// version:     Run AFTER bumping the package version, but BEFORE commit.
// postversion: Run AFTER bumping the package version, and AFTER commit.
Copy the code

Lerna will run npm lifecycle scripts during lerna version in the following order:

  • Detect changed packages, choose version bump(s)
  • Run preversion lifecycle in root
  • For each changed package, in topological order (all dependencies before dependents):
    • Run preversion lifecycle
    • Update version in package.json
    • Run version lifecycle
  • Run version lifecycle in root
  • Add changed files to index, if enabled
  • Create commit and tag(s), if enabled
  • For each changed package, in lexical order (alphabetical according to directory structure):
    • Run postversion lifecycle
  • Run postversion lifecycle in root
  • Push commit and tag(s) to remote, if enabled
  • Create release, if enabled