@0x-lerna-fork/version
自上次发布以来更改包的 Bump 版本
Usage
lerna version 1.0.1 # explicit
lerna version patch # semver keyword
lerna version # select from prompt(s)
运行时,此命令执行以下操作:
- Identifies packages that have been updated since the previous tagged release.
- Prompts for a new version.
- Modifies package metadata to reflect new release.
- Commits those changes and tags the commit.
- Pushes to the git remote.
Positionals
semver bump
lerna version [major | minor | patch | premajor | preminor | prepatch | prerelease]
# uses the next semantic version(s) value and this skips `Select a new version for...` prompt
传递此位置参数时,lerna version
将跳过版本选择提示和 increment 该关键字的版本。
您仍然必须使用 --yes
标志来避免所有提示。
Prerelease
如果你有任何带有预发布版本号的包(例如 2.0.0-beta.3
)并且你运行 lerna version
和一个非预发布的 bump( major
、minor
或 patch
),它将发布那些先前预发布的包以及已更改的包自上次发布以来。
对于使用常规提交的项目,使用以下标志进行预发布管理:
--conventional-prerelease
:将当前更改作为预发布版本发布。
--conventional-graduate
:将预发布版本控制的包升级到稳定版本。
在没有上述标志的情况下运行 lerna version --conventional-commits
仅当版本已经在预发布时才会将当前更改发布为预发布。
Options
--allow-branch <glob>
与启用 lerna version
的 git 分支匹配的 glob 白名单。
在 lerna.json
中配置是最简单的(也是推荐的),但也可以作为 CLI 选项传递。
{
"command": {
"version": {
"allowBranch": "master"
}
}
}
使用上面的配置,lerna version
在从 master
以外的任何分支运行时都会失败。
将 lerna version
限制在主要分支被认为是最佳实践。
{
"command": {
"version": {
"allowBranch": ["master", "feature/*"]
}
}
}
使用前面的配置,lerna version
将被允许在任何前缀为 feature/
的分支中。
请注意,在功能分支中生成 git 标签充满了潜在的错误,因为分支会合并到主分支中。 如果标签与其原始上下文“分离”(可能通过压缩合并或冲突的合并提交),未来的 lerna version
执行将难以确定正确的“自上次发布以来的差异”。
始终可以在命令行上覆盖此“持久”配置。
请谨慎使用。
lerna version --allow-branch hotfix/oops-fix-the-thing
--amend
lerna version --amend
# commit message is retained, and `git push` is skipped.
使用此标志运行时,lerna version
将对当前提交执行所有更改,而不是添加新的更改。
这在持续集成 (CI) 期间非常有用,可减少项目历史记录中的提交次数。
为了防止意外覆盖,此命令将跳过 git push
(即,它暗示 --no-push
)。
--conventional-commits
lerna version --conventional-commits
使用此标志运行时,lerna version
将使用Conventional Commits Specification 到 确定版本 bump 和 生成 CHANGELOG.md 文件。
传递 --no-changelog
将禁用 CHANGELOG.md
文件的生成(或更新) .
--conventional-graduate
lerna version --conventional-commits --conventional-graduate=package-2,package-4
# force all prerelease packages to be graduated
lerna version --conventional-commits --conventional-graduate
当使用这个标志运行时,lerna version
将升级指定的包(逗号分隔)或所有使用 *
的包。 无论当前 HEAD 是否已发布,此命令都有效,类似于 --force-publish
,除了忽略任何非预发布包。 如果未指定的包(如果指定包)或不在预发行版中的包存在更改,则这些包将像通常使用 --conventional-commits
一样进行版本控制。
“毕业”一个包意味着碰到预发布版本的非预发布变体,例如。 <代码>package-1@1.0.0-alpha.0 => package-1@1.0.0。
注意:指定包时,指定包的依赖将被释放,但不会毕业。
--conventional-prerelease
lerna version --conventional-commits --conventional-prerelease=package-2,package-4
# force all prerelease packages to be graduated
lerna version --conventional-commits --conventional-graduate
当使用这个标志运行时,lerna version
将发布预发布版本指定的包(逗号分隔)或所有使用 *
的包。 通过在 conventional-commits
中使用 pre
作为推荐版本的前缀,将所有未发布的更改发布为 pre(patch/minor/major/release),例如。 如果当前更改包括功能提交,建议的 bump 将是 minor
,因此此标志将导致 preminor
版本。 如果未指定的包(如果指定包)或已在预发行版中的包存在更改,则这些包将像通常使用 --conventional-commits
一样进行版本控制。
--changelog-preset
lerna version --conventional-commits --changelog-preset angular-bitbucket
默认情况下,更改日志预设设置为 角度
。
在某些情况下,您可能想要更改使用另一个预设或自定义预设。
预设是常规更改日志的内置或可安装配置的名称。
预设可以作为包的全名或自动扩展的后缀传递
(例如,angular
被扩展为 conventional-changelog-angular
)。
--exact
lerna version --exact
当使用此标志运行时,lerna version
将在更新的包中准确指定更新的依赖项(没有标点符号),而不是 semver 兼容(使用 ^
)。
有关详细信息,请参阅 package.json 依赖项 文档。
--force-publish
lerna version --force-publish=package-2,package-4
# force all packages to be versioned
lerna version --force-publish
当使用此标志运行时,lerna version
将强制发布指定的包(以逗号分隔)或使用 *
的所有包。
这将跳过 lerna changed
检查更改的包并强制更新没有 git diff
更改的包。
--git-remote <name>
lerna version --git-remote upstream
当使用此标志运行时,lerna version
会将 git 更改推送到指定的远程而不是 origin
。
--create-release <type>
lerna version --conventional-commits --create-release github
lerna version --conventional-commits --create-release gitlab
使用此标志运行时,lerna version
将基于更改的包创建官方 GitHub 或 GitLab 版本。 需要传递 --conventional-commits
以便生成变更日志。
要使用 GitHub 进行身份验证,可以定义以下环境变量。
GH_TOKEN
(required) - Your GitHub authentication token (under Settings > Developer settings > Personal access tokens).
GHE_API_URL
- When using GitHub Enterprise, an absolute URL to the API.
GHE_VERSION
- When using GitHub Enterprise, the currently installed GHE version. Supports the following versions.
要使用 GitLab 进行身份验证,可以定义以下环境变量。
GL_TOKEN
(required) - Your GitLab authentication token (under User Settings > Access Tokens).
GL_API_URL
- An absolute URL to the API, including the version. (Default: https://gitlab.com/api/v4)
注意:使用此选项时,您不能传递 --no-changelog
。
--ignore-changes
检测更改包时忽略与 glob(s) 匹配的文件中的更改。
lerna version --ignore-changes '**/*.md' '**/__tests__/**'
此选项最好指定为根 lerna.json
配置,既可以避免对 glob 进行过早的 shell 评估,也可以与 lerna diff
和 lerna changed< 共享配置/code>:
{
"ignoreChanges": ["**/__fixtures__/**", "**/__tests__/**", "**/*.md"]
}
传递 --no-ignore-changes
以禁用任何现有的持久配置。
在以下情况下,将始终发布包,而不管此选项:
- The latest release of the package is a
prerelease
version (i.e. 1.0.0-alpha
, 1.0.0–0.3.7
, etc.).
- One or more linked dependencies of the package have changed.
lerna version --include-merged-tags
当使用此标志运行时,lerna version
还将在包更改检测期间考虑合并分支的标签。
--message <msg>
此选项别名为 -m
以与 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): publish 1.0.0"
# When versioning packages independently, no placeholders are replaced
lerna version -m "chore(release): publish"
# commit message = "chore(release): publish
#
# - package-1@3.0.1
# - package-2@1.5.4"
使用此标志运行时,lerna version
将在提交版本更新时使用提供的消息
用于发布。 用于将 lerna 集成到期望提交消息遵守的项目中
某些准则,例如使用 commitizen 和/或 语义释放。
如果消息包含%s
,它将被替换为前缀为“v”的新全局版本版本号。
如果消息包含%v
,它将被替换为新的全球版本版本号,不带前导“v”。
请注意,此占位符插值仅在使用默认“固定”版本控制模式时适用,因为在独立版本控制时没有“全局”版本可插值。
这也可以在 lerna.json 中配置:
{
"command": {
"version": {
"message": "chore(release): publish %s"
}
}
}
--no-changelog
lerna version --conventional-commits --no-changelog
使用 conventional-commits
时,不要生成任何 CHANGELOG.md
文件。
注意:使用此选项时,您不能传递 --create-release
。
--no-commit-hooks
默认情况下,lerna version
将允许在提交版本更改时运行 git commit hooks。
传递 --no-commit-hooks
以禁用此行为。
此选项类似于 npm version
选项 --commit-hooks
,只是反转。
--no-git-tag-version
默认情况下,lerna version
将提交对 package.json 文件的更改并标记发布。
传递 --no-git-tag-version
以禁用该行为。
此选项类似于 npm version
选项 --git-tag -version
,只是反转了。
--no-push
默认情况下,lerna version
会将已提交和标记的更改推送到已配置的 git remote。
传递 --no-push
以禁用此行为。
--preid
lerna version prerelease
# uses the next semantic prerelease version, e.g.
# 1.0.0 => 1.0.1-alpha.0
lerna version prepatch --preid next
# uses the next semantic prerelease version with a specific prerelease identifier, e.g.
# 1.0.0 => 1.0.1-next.0
使用此标志运行时,lerna version
将递增 premajor
、preminor
、prepatch
或 prerelease< /代码> 语义版本
使用指定的 prerelease identifier 进行碰撞。
--sign-git-commit
此选项类似于同名的 npm version
选项 .
--sign-git-tag
此选项类似于同名的 npm version
选项 .
--yes
lerna version --yes
# skips `Are you sure you want to publish these packages?`
使用此标志运行时,lerna version
将跳过所有确认提示。
在持续集成 (CI) 中很有用,可以自动回答发布确认提示。
--tag-version-prefix
此选项允许提供自定义前缀而不是默认前缀:v
。
请记住,目前您必须提供两次:version
命令和 publish
命令:
# locally
lerna version --tag-version-prefix=''
# on ci
lerna publish from-git --tag-version-prefix=''
Deprecated Options
--cd-version
将 semver 关键字传递给 code>bump 位置代替。
--repo-version
将明确的版本号传递给 bump
位置。
--skip-git
使用 --no-git-tag-version
和 --no-push 代替。
注意:此选项不限制所有 git 命令的执行。 git
仍然是 lerna version
所必需的。
Tips
Generating Initial Changelogs
如果您开始使用 --conventional-commits
选项 after monorepo 已激活一段时间,您仍然可以使用 conventional 为以前的版本生成变更日志-changelog-cli
和 lerna exec
:
# Lerna does not actually use conventional-changelog-cli, so you need to install it temporarily
npm i -D conventional-changelog-cli
# Documentation: `npx conventional-changelog --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'
如果您使用自定义 --changelog-preset
,您应该更改 --preset< /code> 值在上面的例子中相应地。
@0x-lerna-fork/version
Bump version of packages changed since the last release
Usage
lerna version 1.0.1 # explicit
lerna version patch # semver keyword
lerna version # select from prompt(s)
When run, this command does the following:
- Identifies packages that have been updated since the previous tagged release.
- Prompts for a new version.
- Modifies package metadata to reflect new release.
- Commits those changes and tags the commit.
- Pushes to the git remote.
Positionals
semver bump
lerna version [major | minor | patch | premajor | preminor | prepatch | prerelease]
# uses the next semantic version(s) value and this skips `Select a new version for...` prompt
When this positional parameter is passed, lerna version
will skip the version selection prompt and increment the version by that keyword.
You must still use the --yes
flag to avoid all prompts.
Prerelease
If you have any packages with a prerelease version number (e.g. 2.0.0-beta.3
) and you run lerna version
with and a non-prerelease bump (major
, minor
, or patch
), it will publish those previously pre-released packages as well as the packages that have changed since the last release.
For projects using conventional commits, use the following flags for prerelease management:
--conventional-prerelease
: release current changes as prerelease versions.
--conventional-graduate
: graduate prerelease versioned packages to stable versions.
Running lerna version --conventional-commits
without the above flags will release current changes as prerelease only if the version is already in prerelease.
Options
--allow-branch <glob>
A whitelist of globs that match git branches where lerna version
is enabled.
It is easiest (and recommended) to configure in lerna.json
, but it is possible to pass as a CLI option as well.
{
"command": {
"version": {
"allowBranch": "master"
}
}
}
With the configuration above, the lerna version
will fail when run from any branch other than master
.
It is considered a best-practice to limit lerna version
to the primary branch alone.
{
"command": {
"version": {
"allowBranch": ["master", "feature/*"]
}
}
}
With the preceding configuration, lerna version
will be allowed in any branch prefixed with feature/
.
Please be aware that generating git tags in feature branches is fraught with potential errors as the branches are merged into the primary branch. If the tags are "detached" from their original context (perhaps through a squash merge or a conflicted merge commit), future lerna version
executions will have difficulty determining the correct "diff since last release."
It is always possible to override this "durable" config on the command-line.
Please use with caution.
lerna version --allow-branch hotfix/oops-fix-the-thing
--amend
lerna version --amend
# commit message is retained, and `git push` is skipped.
When run with this flag, lerna version
will perform all changes on the current commit, instead of adding a new one.
This is useful during Continuous integration (CI) to reduce the number of commits in the project's history.
In order to prevent unintended overwrites, this command will skip git push
(i.e., it implies --no-push
).
--conventional-commits
lerna version --conventional-commits
When run with this flag, lerna version
will use the Conventional Commits Specification to determine the version bump and generate CHANGELOG.md files.
Passing --no-changelog
will disable the generation (or updating) of CHANGELOG.md
files.
--conventional-graduate
lerna version --conventional-commits --conventional-graduate=package-2,package-4
# force all prerelease packages to be graduated
lerna version --conventional-commits --conventional-graduate
When run with this flag, lerna version
will graduate the specified packages (comma-separated) or all packages using *
. This command works regardless of whether the current HEAD has been released, similar to --force-publish
, except that any non-prerelease packages are ignored. If changes are present for packages that are not specified (if specifying packages), or for packages that are not in prerelease, those packages will be versioned as they normally would using --conventional-commits
.
"Graduating" a package means bumping to the non-prerelease variant of a prerelease version, eg. package-1@1.0.0-alpha.0 => package-1@1.0.0
.
NOTE: when specifying packages, dependents of specified packages will be released, but will not be graduated.
--conventional-prerelease
lerna version --conventional-commits --conventional-prerelease=package-2,package-4
# force all prerelease packages to be graduated
lerna version --conventional-commits --conventional-graduate
When run with this flag, lerna version
will release with prerelease versions the specified packages (comma-separated) or all packages using *
. Releases all unreleased changes as pre(patch/minor/major/release) by prefixing the version recommendation from conventional-commits
with pre
, eg. if present changes include a feature commit, the recommended bump will be minor
, so this flag will result in a preminor
release. If changes are present for packages that are not specified (if specifying packages), or for packages that are already in prerelease, those packages will be versioned as they normally would using --conventional-commits
.
--changelog-preset
lerna version --conventional-commits --changelog-preset angular-bitbucket
By default, the changelog preset is set to angular
.
In some cases you might want to change either use a another preset or a custom one.
Presets are names of built-in or installable configuration for conventional changelog.
Presets may be passed as the full name of the package, or the auto-expanded suffix
(e.g., angular
is expanded to conventional-changelog-angular
).
--exact
lerna version --exact
When run with this flag, lerna version
will specify updated dependencies in updated packages exactly (with no punctuation), instead of as semver compatible (with a ^
).
For more information, see the package.json dependencies documentation.
--force-publish
lerna version --force-publish=package-2,package-4
# force all packages to be versioned
lerna version --force-publish
When run with this flag, lerna version
will force publish the specified packages (comma-separated) or all packages using *
.
This will skip the lerna changed
check for changed packages and forces a package that didn't have a git diff
change to be updated.
--git-remote <name>
lerna version --git-remote upstream
When run with this flag, lerna version
will push the git changes to the specified remote instead of origin
.
--create-release <type>
lerna version --conventional-commits --create-release github
lerna version --conventional-commits --create-release gitlab
When run with this flag, lerna version
will create an official GitHub or GitLab release based on the changed packages. Requires --conventional-commits
to be passed so that changelogs can be generated.
To authenticate with GitHub, the following environment variables can be defined.
GH_TOKEN
(required) - Your GitHub authentication token (under Settings > Developer settings > Personal access tokens).
GHE_API_URL
- When using GitHub Enterprise, an absolute URL to the API.
GHE_VERSION
- When using GitHub Enterprise, the currently installed GHE version. Supports the following versions.
To authenticate with GitLab, the following environment variables can be defined.
GL_TOKEN
(required) - Your GitLab authentication token (under User Settings > Access Tokens).
GL_API_URL
- An absolute URL to the API, including the version. (Default: https://gitlab.com/api/v4)
NOTE: When using this option, you cannot pass --no-changelog
.
--ignore-changes
Ignore changes in files matched by glob(s) when detecting changed packages.
lerna version --ignore-changes '**/*.md' '**/__tests__/**'
This option is best specified as root lerna.json
configuration, both to avoid premature shell evaluation of the globs and to share the config with lerna diff
and lerna changed
:
{
"ignoreChanges": ["**/__fixtures__/**", "**/__tests__/**", "**/*.md"]
}
Pass --no-ignore-changes
to disable any existing durable configuration.
In the following cases, a package will always be published, regardless of this option:
- The latest release of the package is a
prerelease
version (i.e. 1.0.0-alpha
, 1.0.0–0.3.7
, etc.).
- One or more linked dependencies of the package have changed.
lerna version --include-merged-tags
When run with this flag, lerna version
will also consider tags of merged branches during package change detection.
--message <msg>
This option is aliased to -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): publish 1.0.0"
# When versioning packages independently, no placeholders are replaced
lerna version -m "chore(release): publish"
# commit message = "chore(release): publish
#
# - package-1@3.0.1
# - package-2@1.5.4"
When run with this flag, lerna version
will use the provided message when committing the version updates
for publication. Useful for integrating lerna into projects that expect commit messages to adhere
to certain guidelines, such as projects which use commitizen and/or semantic-release.
If the message contains %s
, it will be replaced with the new global version version number prefixed with a "v".
If the message contains %v
, it will be replaced with the new global version version number without the leading "v".
Note that this placeholder interpolation only applies when using the default "fixed" versioning mode, as there is no "global" version to interpolate when versioning independently.
This can be configured in lerna.json, as well:
{
"command": {
"version": {
"message": "chore(release): publish %s"
}
}
}
--no-changelog
lerna version --conventional-commits --no-changelog
When using conventional-commits
, do not generate any CHANGELOG.md
files.
NOTE: When using this option, you cannot pass --create-release
.
--no-commit-hooks
By default, lerna version
will allow git commit hooks to run when committing version changes.
Pass --no-commit-hooks
to disable this behavior.
This option is analogous to the npm version
option --commit-hooks
, just inverted.
--no-git-tag-version
By default, lerna version
will commit changes to package.json files and tag the release.
Pass --no-git-tag-version
to disable the behavior.
This option is analogous to the npm version
option --git-tag-version
, just inverted.
--no-push
By default, lerna version
will push the committed and tagged changes to the configured git remote.
Pass --no-push
to disable this behavior.
--preid
lerna version prerelease
# uses the next semantic prerelease version, e.g.
# 1.0.0 => 1.0.1-alpha.0
lerna version prepatch --preid next
# uses the next semantic prerelease version with a specific prerelease identifier, e.g.
# 1.0.0 => 1.0.1-next.0
When run with this flag, lerna version
will increment premajor
, preminor
, prepatch
, or prerelease
semver
bumps using the specified prerelease identifier.
--sign-git-commit
This option is analogous to the npm version
option of the same name.
--sign-git-tag
This option is analogous to the npm version
option of the same name.
--yes
lerna version --yes
# skips `Are you sure you want to publish these packages?`
When run with this flag, lerna version
will skip all confirmation prompts.
Useful in Continuous integration (CI) to automatically answer the publish confirmation prompt.
--tag-version-prefix
This option allows to provide custom prefix instead of the default one: v
.
Keep in mind that currently you have to supply it twice: for version
command and for publish
command:
# locally
lerna version --tag-version-prefix=''
# on ci
lerna publish from-git --tag-version-prefix=''
Deprecated Options
--cd-version
Pass the semver keyword to the bump
positional instead.
--repo-version
Pass an explicit version number to the bump
positional instead.
--skip-git
Use --no-git-tag-version
and --no-push
instead.
NOTE: This option does not restrict all git commands from being executed. git
is still required by lerna version
.
Tips
Generating Initial Changelogs
If you start using the --conventional-commits
option after the monorepo has been active for awhile, you can still generate changelogs for previous releases using conventional-changelog-cli
and lerna exec
:
# Lerna does not actually use conventional-changelog-cli, so you need to install it temporarily
npm i -D conventional-changelog-cli
# Documentation: `npx conventional-changelog --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'
If you use a custom --changelog-preset
, you should change --preset
value accordingly in the example above.