将 args 传递给 lerna exec 命令 [英] Pass args into lerna exec command

查看:72
本文介绍了将 args 传递给 lerna exec 命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有yarn test,它实际上是由两个子命令yarn test:root &&组成的纱线测试:包.两者都运行 jest(但包使用 lerna exec 间接执行).我希望能够从终端输入 yarn test -t=Pattern 并让两个子命令将 -t=Pattern 附加到末尾.lerna exec -- "yarn test" 似乎没有办法做到这一点.

I have yarn test, which is actually composed of two subcommands yarn test:root && yarn test:packages. Both run jest (but packages does it indirectly using lerna exec). I want to be able to type yarn test -t=Pattern from the terminal and have both sub-commands append -t=Pattern to the end. lerna exec -- "yarn test" doesnt seem to have a way to do this.

我有一个 monorepo,它使用 lerna exec 在每个 lerna 包上运行 yarn test.

I have a monorepo, that uses lerna exec to run yarn test on each lerna package.

给定:

"test": "yarn run test:packages $@ && yarn run test:root $@",
"test:packages": "lerna exec -- yarn test $@", // No args passed
"test:root": "jest ./tests/Storyshots.jest.js $@", // Args passed

我希望能够做类似的事情

I want to be able to do something like

yarn test --updateSnapshot 和将 --updateSnapshot 附加到 yarn test 通过 lerna exec 运行

yarn test --updateSnapshot and for --updateSnapshot to be appended to yarn test run through lerna exec

使用 $@ 的常规 npm 脚本(参见 test:root)工作正常.lerna docs 没有提到任何方法.

With a regular npm script (see test:root) using $@ works fine. The lerna docs don't mention any way to do this.

更新

我认为最简单的方法是编写一个脚本来组合参数和命令.这将需要在所有 lerna 包中使用.

I think the easiest way will be to write a script which composes the args and the commands. This will need to be used in all lerna packages.

推荐答案

您可以使用 -- 将命令行参数传递给内部命令.使用 -- 将表示当前命令的选项结束,并允许将选项传递给内部命令.

You are able to pass command line args to inner commands by using --. Using -- will signify the end of the options for the current command and allow options to get passed to the inner commands.

所以对于这种情况,我们需要转义三次:

So for this situations we need to escape three times:

测试:包

  1. 纱线
  2. 纱线运行测试:包
  3. lerna exec -- 纱线测试

测试:root

  1. 纱线
  2. 纱线运行测试:root
  3. 开玩笑 ./tests/Storyshots.jest.js

纱线测试 -- -- -- -t=Pattern

这篇关于将 args 传递给 lerna exec 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆