Pass args into lerna exec command

那年仲夏 提交于 2021-01-24 07:21:07

问题


Goal

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.

Background

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

Given:

"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 and for --updateSnapshot to be appended to yarn test run through lerna exec

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

Update

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.


回答1:


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:

test:packages

  1. yarn
  2. yarn run test:packages
  3. lerna exec -- yarn test

test:root

  1. yarn
  2. yarn run test:root
  3. jest ./tests/Storyshots.jest.js

yarn test -- -- -- -t=Pattern




回答2:


To append args, you just use something like lerna exec 'yarn test --updateSnapshot'



来源:https://stackoverflow.com/questions/48169878/pass-args-into-lerna-exec-command

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!