运行“yarn run"时将参数传递给“node"可执行文件 [英] Pass arguments to “node” executable when running “yarn run”

查看:266
本文介绍了运行“yarn run"时将参数传递给“node"可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

节点可以用各种选项启动.特别有趣的是 --inspect 标志:

node can be started with various options. Especially interesting is the --inspect flag:

node --inspect node_modules/.bin/jest some.spec.js

是否可以将 --inspect 标志以某种方式传递给 yarn run?例如:

Is it possible to pass the --inspect flag somehow to yarn run? For example:

yarn run test --inspect some.spec.js 

类似问题npm run,在那里似乎是不可能的.

There is a similar question for npm run, where it seems to be not possible.

推荐答案

我不知道 yarn run ... 支持向 NodeJS 传递参数,但是,还有其他几个选项.

I don't know that yarn run ... supports passing arguments to NodeJS, however, there are a couple of other options.

您可以使用 NODE_OPTIONS 环境变量将参数传递给 NodeJS.例如,

You can use the NODE_OPTIONS environment variable to pass arguments to NodeJS. For example,

export NODE_OPTIONS="--inspect"
yarn run test some.spec.js

在 package.json 中,您可以定义一个脚本来利用这一点:

In the package.json, you can define a script to take advantage of this:

"scripts": {
  "test": "jest",
  "test:inspect": "NODE_OPTIONS='--inspect' yarn run test"
}

正如你提到的,你可以直接使用 NodeJS,

And as you mentioned, you can use NodeJS directly,

node --inspect ./node_modules/jest-cli/bin/jest.js some.spec.js

据我所知,这可能是您仅有的两个选择.但是,这两个选项都适用于 NPM 和 Yarn.

As far as I know, those may be your only two options. However, both options work for both NPM and Yarn.

这篇关于运行“yarn run"时将参数传递给“node"可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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