Skip to main content

命令

¥Commands

过滤器选项

¥Filter Options

Lerna 命令可以应用过滤器选项来控制它们操作的包。

¥Lerna commands can have filter options applied to control which packages they operate on.

需要过滤的 lerna 子命令的选项

¥Options for lerna sub-commands that need filtering

安装 lerna 以访问 lerna CLI。

¥Install lerna for access to the lerna CLI.

选项

¥Options

--scope <glob>

仅包含名称与给定 glob 匹配的包。

¥Include only packages with names matching the given glob.

$ lerna exec --scope my-component -- ls -la
$ lerna run --scope "toolbar-*" test
$ lerna run --scope package-1 --scope "*-2" lint

注意:对于某些 glob,可能需要引用选项参数以避免过早的 shell 扩展。

¥Note: For certain globs, it may be necessary to quote the option argument to avoid premature shell expansion.

使用 npx 运行

¥Running with npx

lernanpx 一起运行时,在传递 glob 参数时需要使用显式 "="。这是为了防止 npx 过早地扩大参数。

¥When running lerna with npx, it is necessary to use an explicit "=" when passing glob arguments. This is to prevent npx from prematurely expanding the arguments.

例如:

¥For example:

$ npx lerna run --scope="toolbar-*" test
$ npx lerna run --scope="package-{1,2,5}" test

--ignore <glob>

排除名称与给定 glob 匹配的包。

¥Exclude packages with names matching the given 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

更多过滤示例可以参见 此处

¥More examples of filtering can be found here.

--no-private

排除私有包。默认情况下包含它们。

¥Exclude private packages. They are included by default.

--since [ref]

仅包含自指定 ref.1 以来已更改的软件包。如果没有传递 ref,则默认为最新的标签。

¥Only include packages that have been changed since the specified ref. If no ref is passed, it defaults to the most-recent tag.

# 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 将进入的目标分支,因为你可以将其用作 ref--since 选项。这对于进入默认分支和功能分支的 PR 非常有效。

¥This can be particularly useful when used in CI, if you can obtain the target branch a PR will be going into, because you can use that as the ref to the --since option. This works well for PRs going into the default branch as well as feature branches.

--exclude-dependents

使用 --since 运行命令时排除所有传递依赖,覆盖默认 "changed" 算法。

¥Exclude all transitive dependents when running a command with --since, overriding the default "changed" algorithm.

如果没有 --since,该标志不起作用,并且在这种情况下将引发错误。

¥This flag has no effect without --since, and will throw an error in that case.

--include-dependents

运行命令时包括所有传递依赖,无论 --scope--ignore--since

¥Include all transitive dependents when running a command regardless of --scope, --ignore, or --since.

--include-dependencies

运行命令时包括所有传递依赖,无论 --scope--ignore--since

¥Include all transitive dependencies when running a command regardless of --scope, --ignore, or --since.

与任何接受 --scope (bootstrapcleanlsrunexec) 的命令结合使用。确保任何范围包(通过 --scope--ignore)的所有依赖(和开发依赖)也得到操作。

¥Used in combination with any command that accepts --scope (bootstrap, clean, ls, run, exec). Ensures that all dependencies (and dev dependencies) of any scoped packages (either through --scope or --ignore) are operated on as well.

注意:这将覆盖 --scope--ignore 标志。

¥Note: This will override the --scope and --ignore flags.

即,如果与 --ignore 标志匹配的包被另一个正在引导的包所依赖,则该包仍将被引导。

¥i.e. A package matched by the --ignore flag will still be bootstrapped if it is depended on by another package that is being bootstrapped.

这对于你想要 "设置" 依赖于正在设置的其他包的单个包的情况很有用。

¥This is useful for situations where you want to "set up" a single package that relies on other packages being set up.

$ 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 运行命令时包含合并分支中的标签。仅当你从功能分支进行大量发布时这才有用,通常不建议这样做。

¥Include tags from merged branches when running a command with --since. This is only useful if you do a lot of publishing from feature branches, which is not generally recommended.

局限性

¥Limitations

尽管你可以在不先安装项目依赖的情况下运行 Lerna(例如使用 pnpm dlxnpx),但不建议这样做。该命令可能有效,但其输出可能不是 100% 准确。详细信息请参见 此问题

¥Even though you can run Lerna without installing the project dependencies first, for instance with pnpm dlx or npx, it is not recommended. The command may work, but its output may not be 100% accurate. See this issue for more details.