命令
lerna add-cachinglerna changedlerna cleanlerna createlerna difflerna execlerna importlerna infolerna initlerna listlerna publishlerna repairlerna runlerna versionlerna watch
筛选选项
Lerna 命令可以应用筛选选项来控制其操作的包。
需要筛选的 lerna 子命令的选项
安装 lerna 以访问 lerna CLI。
选项
--scope <glob>
仅包含名称与给定 glob 匹配的包。
$ lerna exec --scope my-component -- ls -la
$ lerna run --scope "toolbar-*" test
$ lerna run --scope package-1 --scope "*-2" lint
注意:对于某些 glob,可能需要引用选项参数以避免过早的 shell 展开。
使用 npx 运行
当使用 npx 运行 lerna 时,必须使用显式的 "=" 传递 glob 参数。这是为了防止 npx 过早地展开参数。
例如
$ npx lerna run --scope="toolbar-*" test
$ npx lerna run --scope="package-{1,2,5}" test
--ignore <glob>
排除名称与给定 glob 匹配的包。
$ lerna exec --ignore "package-{1,2,5}" -- ls -la
$ lerna run --ignore package-1 test
$ lerna run --ignore "package-@(1|2)" --ignore package-3 lint
可以在 此处找到更多筛选示例。
--no-private
排除私有包。默认情况下包含它们。
--since [ref]
仅包含自指定 ref 以来发生更改的包。如果未传递 ref,则默认为最新的标签。
# List the contents of packages that have changed since the latest tag
$ lerna exec --since -- ls -la
# Run the tests for all packages that have changed since `main`
$ lerna run test --since main
# List all packages that have changed since `some-branch`
$ lerna ls --since some-branch
这在 CI 中特别有用,如果你可以获取 PR 将要进入的目标分支,因为你可以将其用作 --since 选项的 ref。这适用于进入默认分支和功能分支的 PR。
--exclude-dependents
使用 --since 运行命令时排除所有传递依赖项,覆盖默认的“已更改”算法。
此标志在没有 --since 的情况下无效,在这种情况下会抛出错误。
--include-dependents
无论 --scope、--ignore 或 --since 如何,在运行命令时都包含所有传递依赖项。
--include-dependencies
无论 --scope、--ignore 或 --since 如何,在运行命令时都包含所有传递依赖项。
与任何接受 --scope 的命令(bootstrap、clean、ls、run、exec)结合使用。确保任何作用域包(通过 --scope 或 --ignore)的所有依赖项(以及开发依赖项)也都被操作。
注意:这将覆盖
--scope和--ignore标志。即,如果
--ignore标志匹配的包被另一个正在引导的包依赖,则该包仍将被引导。
这对于需要“设置”依赖于其他包设置的单个包的情况很有用。
$ lerna bootstrap --scope my-component --include-dependencies
# my-component and all of its dependencies will be bootstrapped
$ lerna bootstrap --scope "package-*" --ignore "package-util-*" --include-dependencies
# all packages matching "package-util-*" will be ignored unless they are
# depended upon by a package whose name matches "package-*"
--include-merged-tags
$ lerna exec --since --include-merged-tags -- ls -la
使用 --since 运行命令时包含来自合并分支的标签。仅当你在功能分支中执行大量发布时,这才是有用的,这通常不建议这样做。
局限性
即使你可以在不首先安装项目依赖项的情况下运行 Lerna,例如使用 pnpm dlx 或 npx,也不建议这样做。该命令可能会起作用,但其输出可能不完全准确。有关更多详细信息,请参阅 此问题。