@0x-lerna-fork/publish 中文文档教程

发布于 5年前 浏览 25 项目主页 更新于 3年前

@0x-lerna-fork/publish

在当前项目中发布包

安装 lerna 以访问 lerna CLI。

Usage

lerna publish              # publish packages that have changed since the last release
lerna publish from-git     # explicitly publish packages tagged in the current commit
lerna publish from-package # explicitly publish packages where the latest version is not present in the registry

运行时,此命令会执行以下操作之一:

  • Publish packages updated since the last release (calling lerna version behind the scenes).
  • This is the legacy behavior of lerna 2.x
  • Publish packages tagged in the current commit (from-git).
  • Publish packages in the latest commit where the version is not present in the registry (from-package).
  • Publish an unversioned "canary" release of packages (and their dependents) updated in the previous commit.

Lerna 永远不会发布标记为私有的包(package.json 中的 "private": true)。

查看Per-Package Configuration,了解有关发布作用域包、自定义注册表和自定义 dist-tags 的更多详细信息。

Positionals

bump from-git

除了 lerna version 支持的 semver 关键字外, lerna publish 还支持 from-git 关键字。 这将识别由 lerna version 标记的包并将它们发布到 npm。 这在您希望手动增加版本的 CI 场景中很有用, 但是让包内容本身通过自动化过程一致地发布。

bump from-package

类似于 from-git 关键字,除了要发布的包列表是通过检查每个 package.json 来确定的 并确定注册表中是否不存在任何包版本。 注册表中不存在的任何版本都将 发表。 当以前的 lerna publish 未能将所有包发布到注册表时,这很有用。

Options

lerna publish 支持 lerna version< 提供的所有选项/code>除了以下内容:

--canary

lerna publish --canary
# 1.0.0 => 1.0.1-alpha.0+${SHA} of packages changed since the previous commit
# a subsequent canary publish will yield 1.0.1-alpha.1+${SHA}, etc

lerna publish --canary --preid beta
# 1.0.0 => 1.0.1-beta.0+${SHA}

# The following are equivalent:
lerna publish --canary minor
lerna publish --canary preminor
# 1.0.0 => 1.1.0-alpha.0+${SHA}

当使用此标志运行时,lerna publish 以更精细的方式(每次提交)发布包。 在发布到 npm 之前,它通过获取当前 version 创建新的 version 标签,将其升级到下一个 minor 版本,添加提供的元后缀(默认为 alpha)并附加当前的 git sha(例如:1.0.0 变为 1.1.0-alpha.0+81e3b443) .

如果您在 CI 中从多个活跃的开发分支发布了金丝雀版本, 建议自定义 --preid--dist-tag在每个分支的基础上避免版本冲突。

此标志的预期用例是按提交级别发布或每晚发布。

--contents <dir>

要发布的子目录。 必须应用于所有包,并且必须包含一个 package.json 文件。 包生命周期仍将在原始叶目录中运行。 您可能应该使用其中一种生命周期(prepareprepublishOnlyprepack)来创建子目录等等.

如果您从事不必要的复杂出版,这会给您带来快乐。

lerna publish --contents dist
# publish the "dist" subfolder of every Lerna-managed leaf package

注意:您应该等到postpublish 生命周期阶段(根或叶)来清理这个生成的子目录, 因为生成的 package.json 在包上传期间使用(之后 postpack)。

--dist-tag <tag>

lerna publish --dist-tag next

使用此标志运行时,lerna publish 将使用给定的 npm dist-tag 发布到 npm a>(默认为 latest)。

此选项可用于发布 prereleasebeta 版本非最新 dist-tag,帮助消费者避免自动升级到预发布质量代码。

注意:latest 标签是用户运行 npm install my-package 时使用的标签。 要安装不同的标签,用户可以运行 npm install my-package@prerelease

--git-head <sha>

显式 SHA 在打包 tarball 时在清单上设置为 gitHead,仅允许 from-package 位置。

例如,从 AWS CodeBuild 发布时(git 不可用), 您可以使用此选项传递适当的环境变量 用于此包元数据:

lerna publish from-package --git-head ${CODEBUILD_RESOLVED_SOURCE_VERSION}

在所有其他情况下,此值源自本地 git 命令。

--graph-type <all|dependencies>

设置构建包图时要使用的依赖类型。 默认值为 dependencies,因此仅包含包的 package.jsondependencies 部分中列出的包。 在构造包图和确定拓扑顺序时,传递 all 以包含 dependencies devDependencies

当使用传统的 peer + dev 依赖对时,这个选项应该配置为 all 这样 peer 总是在它们的依赖之前发布。

lerna publish --graph-type all

通过 lerna.json 配置:

{
  "command": {
    "publish": {
      "graphType": "all"
    }
  }
}

--no-git-reset

默认情况下,lerna publish 确保对工作树的任何更改都已重置。

为避免这种情况,请传递 --no-git-reset。 当与 --canary 标志一起用作 CI 管道的一部分时,这可能特别有用。 例如,已被修改的 package.json 版本号可能需要在后续的 CI 管道步骤(例如 Docker 构建)中使用。

lerna publish --no-git-reset

--no-verify-access

默认情况下,lerna 将验证登录的 npm 用户对即将发布的包的访问权限。 传递此标志将禁用该检查。

如果您使用的是不支持 npm access ls-packages 的第三方注册表,您将需要传递此标志(或将 command.publish.verifyAccess 设置为 < lerna.json 中的代码>false)。

请谨慎

--otp

使用 发布需要双因素身份验证的包时,您可以指定一次性密码使用 --otp

lerna publish --otp 123456

请记住,一次性密码会在其生成后 30 秒内过期。 如果它在发布操作期间过期,提示将在继续之前请求刷新值。

--preid

与同名的lerna version选项不同,该选项只适用于--canary版本计算。

lerna publish --canary
# uses the next semantic prerelease version, e.g.
# 1.0.0 => 1.0.1-alpha.0

lerna publish --canary --preid next
# uses the next semantic prerelease version with a specific prerelease identifier, e.g.
# 1.0.0 => 1.0.1-next.0

使用此标志运行时,lerna publish --canary 将递增 premajorpreminorprepatchprerelease 语义版本 使用指定的 prerelease identifier 进行碰撞。

--pre-dist-tag <tag>

lerna publish --pre-dist-tag next

--dist-tag 的工作方式相同,除了仅适用于与预发布版本一起发布的包。

--registry <url>

使用此标志运行时,转发的 npm 命令将为您的包使用指定的注册表。

如果您不想显式设置注册表,这很有用 例如使用时,在所有 package.json 文件中单独配置 私人登记处。

--temp-tag

通过后,此标志将通过首次发布来更改默认发布过程 所有将包更改为临时 dist-tag (lerna-temp) 然后移动 由 --dist-tag 配置的 dist-tag 的新版本(默认 latest< /代码>)。

这通常不是必需的,因为 Lerna 会在拓扑中发布包 默认顺序(依赖项之前的所有依赖项)。

--ignore-scripts

传递后,此标志将在 lerna publish 期间禁用运行生命周期脚本

--ignore-prepublish

传递后,此标志将禁用正在执行的 prepublish 脚本。

--yes

lerna publish --canary --yes
# skips `Are you sure you want to publish the above changes?`

使用此标志运行时,lerna publish 将跳过所有确认提示。 在持续集成 (CI) 中很有用,可以自动回答发布确认提示。

---tag-version-prefix

此选项允许提供自定义前缀而不是默认前缀:v

请记住,目前您必须提供两次:对于 version 命令和对于 publish 命令:

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

Deprecated Options

--skip-npm

调用 lerna version 直接,而不是。

Per-Package Configuration

叶包可以使用特殊的 publishConfig 配置,某些 环境改变了 lerna publish 的行为。

publishConfig.access

要发布具有作用域的包(例如,@mycompany/rocks),您必须设置 访问

  "publishConfig": {
    "access": "public"
  }
  • 如果为没有范围的包设置此字段,它失败。

  • 如果您希望您的作用域包保持私有(即,“restricted”),则无需设置此值。

    请注意,这与在叶包中设置 "private": true相同; 如果设置了 private 字段,则在任何情况下都永远不会 发布该包。

publishConfig.registry

您可以通过设置 registry 在每个包的基础上自定义注册表:

  "publishConfig": {
    "registry": "http://my-awesome-registry.com/"
  }
  • Passing --registry applies globally, and in some cases isn't what you want.

publishConfig.tag

您可以通过设置 tag 在每个包的基础上自定义 dist-tag:

  "publishConfig": {
    "tag": "flippin-sweet"
  }
  • Passing --dist-tag will overwrite this value.
  • This value is always ignored when --canary is passed.

publishConfig.directory

这个 < em>non-standard 字段允许您自定义发布的子目录,就像 --contents 一样,但是在每个包的基础。 --contents 的所有其他注意事项仍然适用。

  "publishConfig": {
    "directory": "dist"
  }

LifeCycle Events

Lerna 将在 lerna publish 期间按以下顺序运行 npm lifecycle scripts

Pre Publish

  • 在根包 中:

  • prepublish

  • prepare

  • prepublishOnly

  • prepack

  • 在每个子包中:

  • prepublish

  • prepare< /code>

  • prepublishOnly

  • 预打包

Packing each subpackage

  • In each subpackage:
  • postpack

After all subpackages packed

  • In root package:
  • postpack

Publishing each subpackage

  • In each subpackage:
  • publish
  • postpublish

After all subpackages published

  • In root package:
  • publish
  • postpublish

@0x-lerna-fork/publish

Publish packages in the current project

Install lerna for access to the lerna CLI.

Usage

lerna publish              # publish packages that have changed since the last release
lerna publish from-git     # explicitly publish packages tagged in the current commit
lerna publish from-package # explicitly publish packages where the latest version is not present in the registry

When run, this command does one of the following things:

  • Publish packages updated since the last release (calling lerna version behind the scenes).
  • This is the legacy behavior of lerna 2.x
  • Publish packages tagged in the current commit (from-git).
  • Publish packages in the latest commit where the version is not present in the registry (from-package).
  • Publish an unversioned "canary" release of packages (and their dependents) updated in the previous commit.

Lerna will never publish packages which are marked as private ("private": true in the package.json).

Check out Per-Package Configuration for more details about publishing scoped packages, custom registries, and custom dist-tags.

Positionals

bump from-git

In addition to the semver keywords supported by lerna version, lerna publish also supports the from-git keyword. This will identify packages tagged by lerna version and publish them to npm. This is useful in CI scenarios where you wish to manually increment versions, but have the package contents themselves consistently published by an automated process.

bump from-package

Similar to the from-git keyword except the list of packages to publish is determined by inspecting each package.json and determining if any package version is not present in the registry. Any versions not present in the registry will be published. This is useful when a previous lerna publish failed to publish all packages to the registry.

Options

lerna publish supports all of the options provided by lerna version in addition to the following:

--canary

lerna publish --canary
# 1.0.0 => 1.0.1-alpha.0+${SHA} of packages changed since the previous commit
# a subsequent canary publish will yield 1.0.1-alpha.1+${SHA}, etc

lerna publish --canary --preid beta
# 1.0.0 => 1.0.1-beta.0+${SHA}

# The following are equivalent:
lerna publish --canary minor
lerna publish --canary preminor
# 1.0.0 => 1.1.0-alpha.0+${SHA}

When run with this flag, lerna publish publishes packages in a more granular way (per commit). Before publishing to npm, it creates the new version tag by taking the current version, bumping it to the next minor version, adding the provided meta suffix (defaults to alpha) and appending the current git sha (ex: 1.0.0 becomes 1.1.0-alpha.0+81e3b443).

If you have publish canary releases from multiple active development branches in CI, it is recommended to customize the --preid and --dist-tag <tag> on a per-branch basis to avoid clashing versions.

The intended use case for this flag is a per commit level release or nightly release.

--contents <dir>

Subdirectory to publish. Must apply to ALL packages, and MUST contain a package.json file. Package lifecycles will still be run in the original leaf directory. You should probably use one of those lifecycles (prepare, prepublishOnly, or prepack) to create the subdirectory and whatnot.

If you're into unnecessarily complicated publishing, this will give you joy.

lerna publish --contents dist
# publish the "dist" subfolder of every Lerna-managed leaf package

NOTE: You should wait until the postpublish lifecycle phase (root or leaf) to clean up this generated subdirectory, as the generated package.json is used during package upload (after postpack).

--dist-tag <tag>

lerna publish --dist-tag next

When run with this flag, lerna publish will publish to npm with the given npm dist-tag (defaults to latest).

This option can be used to publish a prerelease or beta version under a non-latest dist-tag, helping consumers avoid automatically upgrading to prerelease-quality code.

Note: the latest tag is the one that is used when a user runs npm install my-package. To install a different tag, a user can run npm install my-package@prerelease.

--git-head <sha>

Explicit SHA to set as gitHead on manifests when packing tarballs, only allowed with from-package positional.

For example, when publishing from AWS CodeBuild (where git is not available), you could use this option to pass the appropriate environment variable to use for this package metadata:

lerna publish from-package --git-head ${CODEBUILD_RESOLVED_SOURCE_VERSION}

Under all other circumstances, this value is derived from a local git command.

--graph-type <all|dependencies>

Set which kind of dependencies to use when building a package graph. The default value is dependencies, whereby only packages listed in the dependencies section of a package's package.json are included. Pass all to include both dependencies and devDependencies when constructing the package graph and determining topological order.

When using traditional peer + dev dependency pairs, this option should be configured to all so the peers are always published before their dependents.

lerna publish --graph-type all

Configured via lerna.json:

{
  "command": {
    "publish": {
      "graphType": "all"
    }
  }
}

--no-git-reset

By default, lerna publish ensures any changes to the working tree have been reset.

To avoid this, pass --no-git-reset. This can be especially useful when used as part of a CI pipeline in conjunction with the --canary flag. For instance, the package.json version numbers which have been bumped may need to be used in subsequent CI pipeline steps (such as Docker builds).

lerna publish --no-git-reset

--no-verify-access

By default, lerna will verify the logged-in npm user's access to the packages about to be published. Passing this flag will disable that check.

If you are using a third-party registry that does not support npm access ls-packages, you will need to pass this flag (or set command.publish.verifyAccess to false in lerna.json).

Please use with caution

--otp

When publishing packages that require two-factor authentication, you can specify a one-time password using --otp:

lerna publish --otp 123456

Please keep in mind that one-time passwords expire within 30 seconds of their generation. If it expires during publish operations, a prompt will request a refreshed value before continuing.

--preid

Unlike the lerna version option of the same name, this option only applies to --canary version calculation.

lerna publish --canary
# uses the next semantic prerelease version, e.g.
# 1.0.0 => 1.0.1-alpha.0

lerna publish --canary --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 publish --canary will increment premajor, preminor, prepatch, or prerelease semver bumps using the specified prerelease identifier.

--pre-dist-tag <tag>

lerna publish --pre-dist-tag next

Works the same as --dist-tag, except only applies to packages being released with a prerelease version.

--registry <url>

When run with this flag, forwarded npm commands will use the specified registry for your package(s).

This is useful if you do not want to explicitly set up your registry configuration in all of your package.json files individually when e.g. using private registries.

--temp-tag

When passed, this flag will alter the default publish process by first publishing all changed packages to a temporary dist-tag (lerna-temp) and then moving the new version(s) to the dist-tag configured by --dist-tag (default latest).

This is not generally necessary, as Lerna will publish packages in topological order (all dependencies before dependents) by default.

--ignore-scripts

When passed, this flag will disable running lifecycle scripts during lerna publish.

--ignore-prepublish

When passed, this flag will disable prepublish script being executed.

--yes

lerna publish --canary --yes
# skips `Are you sure you want to publish the above changes?`

When run with this flag, lerna publish 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

--skip-npm

Call lerna version directly, instead.

Per-Package Configuration

A leaf package can be configured with special publishConfig that in certain circumstances changes the behavior of lerna publish.

publishConfig.access

To publish packages with a scope (e.g., @mycompany/rocks), you must set access:

  "publishConfig": {
    "access": "public"
  }
  • If this field is set for a package without a scope, it will fail.

  • If you want your scoped package to remain private (i.e., "restricted"), there is no need to set this value.

    Note that this is not the same as setting "private": true in a leaf package; if the private field is set, that package will never be published under any circumstances.

publishConfig.registry

You can customize the registry on a per-package basis by setting registry:

  "publishConfig": {
    "registry": "http://my-awesome-registry.com/"
  }
  • Passing --registry applies globally, and in some cases isn't what you want.

publishConfig.tag

You can customize the dist-tag on a per-package basis by setting tag:

  "publishConfig": {
    "tag": "flippin-sweet"
  }
  • Passing --dist-tag will overwrite this value.
  • This value is always ignored when --canary is passed.

publishConfig.directory

This non-standard field allows you to customize the published subdirectory just like --contents, but on a per-package basis. All other caveats of --contents still apply.

  "publishConfig": {
    "directory": "dist"
  }

LifeCycle Events

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

Pre Publish

  • In root package:

  • prepublish

  • prepare

  • prepublishOnly

  • prepack

  • In each subpackage:

  • prepublish

  • prepare

  • prepublishOnly

  • prepack

Packing each subpackage

  • In each subpackage:
  • postpack

After all subpackages packed

  • In root package:
  • postpack

Publishing each subpackage

  • In each subpackage:
  • publish
  • postpublish

After all subpackages published

  • In root package:
  • publish
  • postpublish
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文