What is the difference between args and runtimeArg

2019-04-24 00:34发布

问题:

What is the difference between args and runtimeArgs in launch.json?

// Optional arguments passed to the runtime executable
"runtimeArgs": []
// Command line arguments passed to the program
"args": []

Is the program not the same thing as the runtime executable?

Extra information and motivation behind the question:

I am developing a nodejs application. In my package.json, I have a start script:

"start": "electron ./src/Main/main.js arg2", and in my app code, I access process.argv[2] which gets me arg2, so when I run npm start, my app works as intended.

When I run the app from VSCode, however it doesn't, and the reason was that I wasn't supplying any additional arguments in launch.json. Where should I put those arguments? process.argv seems to contains the arguments provided in either args or runtimeArgs though it also sticks in some --debug-brk argument, which I don't want.

I want to be able to use process.argv consistently when I run the app from the command line (npm start) or start it from VSCode.

回答1:

I think this is mostly explained in the Node debugging docs:

Instead of launching the Node.js program directly with node, you can use 'npm' scripts or other task runner tools directly from a launch configuration:

  • Any program available on the PATH (for example 'npm', 'mocha', 'gulp', etc.) can be used for the runtimeExecutable attribute [...]

runtimeExecutable is not the program you want to debug, but the executable used to run it. So it appears that runtimeArgs is to runtimeExecutable as args is to program.

If you're interested in how it works in detail, here's the relevant part of the debugAdapter.ts implementation.