使用 lerna 将自定义参数发送到 npm(纱线)脚本 [英] sending custom arguments to npm (yarn) scripts with lerna
问题描述
我在尝试使用 lerna
将参数传递给 npm
脚本时遇到问题.
I have an issue when trying to pass arguments to an npm
script with lerna
.
我有一个节点脚本,我想在工作区中的每个包中运行它.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"
}
}
现在,如果我在根目录中运行 yarn run my-script
它将运行工作区中每个包内的脚本.
so now, if I run in the root yarn run my-script
it will run the script inside each package in the workspace.
有时,我需要将执行范围限定为特定的包.所以从命令行运行这个显然有效:lerna exec --scope somepackage -- node \$LERNA_ROOT_PATH/scripts/create-common-scripts.js
.
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
.
我的问题:如何将 npm 脚本与 lerna
范围参数连接起来.这不起作用:yarn run my-script --scope somepackage
,因为它将参数设置为命令的末尾:lerna exec -- node \\$LERNA_ROOT_PATH/scripts/my-script.js --scope somepackage
.
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
.
谢谢!
推荐答案
使用 Lerna 时命令经常嵌套.意思是一个命令会调用另一个命令,等等.例如下面的命令:
When using Lerna commands are often nested. Meaning one command will call anther command, etc. For example the following command:
npm run release (in monorepo root) [1] > lerna run release [2] > npm run release (in package) [3] > release-it [4]
在 shell 中,参数可以在运行时使用双破折号 (--
) 传递给嵌套命令.它标志着参数(选项)列表的结束.--
之后的任何参数都将被提升到下一个命令.这将适用于嵌套多级深度的命令,您所要做的就是添加 --
的数量以匹配您要传递给它们的命令的级别.
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:
$ npm run release -- --stream -- -- --dry-run --no-git.requireCleanWorkingDir
将参数提升到:
1. npm run release
2. lerna run release --stream
3. npm run release
4. release-it --dry-run --no-git.requireCleanWorkingDir
这篇关于使用 lerna 将自定义参数发送到 npm(纱线)脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!