问题
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
- yarn
- yarn run test:packages
- lerna exec -- yarn test
test:root
- yarn
- yarn run test:root
- 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