I have an issue when trying to pass arguments to an npm
script with lerna
.
I have a node script that I want to run inside each package in the workspace. lerna
docs suggests the following:
{
"scripts": {
"my-script": "lerna exec -- node \\$LERNA_ROOT_PATH/scripts/my-script.js"
}
}
so now, if I run in the root yarn run my-script
it will run the script inside each package in the workspace.
Sometimes, I need to scope the execution to a specific package. So running this from command line obviously works: lerna exec --scope somepackage -- node \$LERNA_ROOT_PATH/scripts/create-common-scripts.js
.
My question: how can I connect the npm script with the lerna
scope argument. this is not working: yarn run my-script --scope somepackage
, as it sets the argument to the end of the command: lerna exec -- node \\$LERNA_ROOT_PATH/scripts/my-script.js --scope somepackage
.
Thanks!
When using Lerna commands are often nested. Meaning one command will call anther command, etc. For example the following command:
In a shell arguments can be passed to nested commands at runtime using a double dash (
--
). It marks the end of the parameter (option) list. Any parameter after the--
will be hoisted to the next command. This will work with commands nested multiple levels deep, all you have to do is add the number of--
to match the level of the command you want to pass them to.With the previous example in mind, the following command:
Will hoists the parameters to: