Pass arguments to “node” executable when running “yarn run”

此生再无相见时 提交于 2019-12-08 16:51:13

问题


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

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

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

yarn run test --inspect some.spec.js 

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


回答1:


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

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

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"
}

And as you mentioned, you can use NodeJS directly,

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

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



来源:https://stackoverflow.com/questions/46953696/pass-arguments-to-node-executable-when-running-yarn-run

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