发布工作流程
此功能仍在孵化中,我们可能会根据你的反馈对其进行改进。
¥This feature is still incubating, and we'll likely be improving it based on your feedback.
使用 monorepos 时,一项艰巨 的任务通常是在开始新版本时确定哪些包应该接收新版本。Yarn 提供了一些工具,旨在使此工作流程更容易,而无需第三方工具(当然,你可能更喜欢不同实现提供的工作流程!)。
¥When working with monorepos, a hard task often is to figure out which packages should receive a new version when starting a new release. Yarn offers a few tools that aim to make this workflow easier without the need for third-party tools (although it's possible you may prefer the workflow offered by different implementations, of course!).
自动更新依赖
¥Auto-updated dependencies
运行 yarn version
命令升级工作区的版本时,通过基本 semver 范围(^x.y.z
、~x.y.z
等)依赖于第一个工作区的其他每个工作区都将自动更新以引用新版本。例如,假设我们有以下工作区:
¥When running the yarn version
command to upgrade the version of a workspace, every other workspace that depend on the first one through a basic semver ranges (^x.y.z
, ~x.y.z
, ...) will get auto-updated to reference the new version. For example, let's say we have the following workspaces:
/packages/common (1.0.0)
/packages/server (depends on common@^1.0.0)
/packages/client (depends on common@^1.0.0)
在 2.0 之前的版本中,升级 common
需要你在那里运行命令,然后进入 server
和 client
中的每一个以手动升级它们的依赖以引用新版本。但现在不是了!如果我们将 yarn version 1.1.1
运行到 common
,将应用以下更改:
¥In pre-2.0, upgrading common
would have required you to run the command there, then go into each of server
and client
to manually upgrade their dependencies to reference the new version. But not anymore! If we run yarn version 1.1.1
into common
, the following changes will be applied:
/packages/common (1.1.1)
/packages/server (depends on common@^1.1.1)
/packages/client (depends on common@^1.1.1)
当然,当 monorepo 中的包总是要用作 monorepo 的一部分时,这并不那么重要,但当你使用多个要发布的包时,它会变得更加有趣。如果你忘记更新任一依赖包的范围,你的用户可能会下载旧版本的 common
,而该版本与新版本不兼容。
¥Of course it's not that important when the packages from the monorepo are always meant to be used as part of the monorepo, but it becomes much more interesting when you work with multiple packages meant to be published. Had you forgotten to update the range of either of your dependent packages, your users would have potentially downloaded an old version of common
which wouldn't have been compatible with the newer one.
延迟版本控制
¥Deferred versioning
从 2.0 开始,yarn version
命令现在接受一个新标志:--deferred
。设置后,此标志将导致命令不会立即更改本地清单的 version
字段,而是在内部记录一个条目,表明当前包需要在下一个发布周期内进行升级。例如,以下内容:
¥Starting from the 2.0, the yarn version
command now accepts a new flag: --deferred
. When set, this flag will cause the command to not immediately change the version
field of the local manifest, but to instead internally record an entry stating that the current package will need to receive an upgrade during the next release cycle. For example, the following:
不会导致 package.json
文件更改!相反,Yarn 将在 .yarn/versions
目录中创建(或重用,如果你在分支内)。此文件将记录请求的升级:
¥Will not cause the package.json
file to change! Instead, Yarn will create (or reuse, if you're inside a branch) a file within the .yarn/versions
directory. This file will record the requested upgrade:
releases:
my-package@1.0.0: minor
然后稍后,一旦你准备好,只需运行 yarn version apply
。然后,Yarn 将找到它之前保存的所有升级记录,并一次性应用它们(包括通过处理我们所看到的升级相互依赖)。
¥Then later on, once you're ready, just run yarn version apply
. Yarn will then locate all the upgrade records it previously saved, and apply them all at once (including by taking care of upgrading inter-dependencies as we saw).