我可以为 lerna monorepo 中的所有子包管理相同的版本吗?

Can I manage same version for all the sub-package in lerna monorepo?

my-lerna-repo/
package.json
packages/
    package-1/
        package.json
    package-2/
        package.json
            dependencies: {
                package-1
            }

我想为所有子包保持一致的版本。我们在子包中也有交叉依赖。

我想实现与 angular 类似的效果。

https://github.com/angular/angular

他们只在根级别管理包版本,在所有子包中他们提到 0.0.0-PLACEHOLDER。构建时间它从根包中选择版本。

请让我知道是否有任何现有的方法可以做到这一点,或者我需要编写自己的自定义脚本。

这正是 Lerna does with the Fixed/Locked mode,这是 Lerna 项目的默认设置。

Fixed mode Lerna projects operate on a single version line. The version is kept in the lerna.json file at the root of your project under the version key. When you run lerna publish, if a module has been updated since the last time a release was made, it will be updated to the new version you're releasing. This means that you only publish a new version of a package when you need to.

您可以使用 --force-publish 来确保您的所有包都在同一版本下发布。

根据 Lerna 文档,如果您想在同一版本下发布所有包,您需要在 lenra.json 文件中使用零 (0) 作为主要 Lerna 版本。

Note: If you have a major version zero, all updates are considered breaking. Because of that, running lerna publish with a major version zero and choosing any non-prerelease version number will cause new versions to be published for all packages, even if not all packages have changed since the last release.

这是Babel目前使用的模式。如果您想自动将所有包版本绑定在一起,请使用此选项。这种方法的一个问题是任何包中的重大更改都会导致所有包都具有新的主要版本。

示例:“0”或“0.1.0”

{
  "packages": [
    "packages/*"
  ],
  "useWorkspaces": true,
  "npmClient": "yarn",
  "version": "0"
}