VSCode 的 launch.json 中的 args 和 runtimeArgs 有什么区别?

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

launch.json中的argsruntimeArgs有什么区别?

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

这个程序和运行time可执行文件不是一回事吗?

问题背后的额外信息和动机:

我正在开发一个 nodejs 应用程序。在我的 package.json 中,我有一个 start 脚本:

"start": "electron ./src/Main/main.js arg2",在我的应用程序代码中,我访问 process.argv[2] 这让我 arg2,所以当我 运行 npm start,我的应用程序工作如预期。

当我 运行 来自 VSCode 的应用程序时,但它没有,原因是我没有在 launch.json 中提供任何额外的参数。我应该把这些论点放在哪里? process.argv 似乎包含 argsruntimeArgs 中提供的参数,尽管它也包含在一些 --debug-brk 参数中,我不想要这些参数。

当我从命令行 (npm start) 运行 应用程序或从 VSCode 启动它时,我希望能够始终如一地使用 process.argv

我认为这主要在 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不是你要调试的程序,而是用来运行它的可执行文件。所以看起来runtimeArgs runtimeExecutable 就像 argsprogram.

如果您对它的详细工作原理感兴趣,here's debugAdapter.ts 实现的相关部分。

如果删除属性“program”,参数会一个接一个地附加,您看不出有任何区别。

考虑以下示例,包括“类型”“程序”:

         {
            
           "name": "vscode-jest-tests",
            "type": "node",
            "request": "launch",
            "program": "${workspaceFolder}/node_modules/jest-cli/bin/jest.js",
            "stopOnEntry": false,
            "args": [ 
                "--runInBand"                       
            ],
            "cwd": "${workspaceFolder}",
            "preLaunchTask": null,
            "runtimeExecutable": null,
            "runtimeArgs": [
                "--nolazy"
            ],
            "env": {
                "NODE_ENV": "development"
            },
            "console": "integratedTerminal",
            "internalConsoleOptions": "neverOpen",
            "disableOptimisticBPs": true
        }

=> set "NODE_ENV=development" && "C:\Program Files\nodejs\node.exe" --nolazy --inspect-brk=35238 [=46= .js --runInBand

  • runtimeArg"--nolazy"发生在后面node.exe(对应类型) 和

  • arg“--runInBand”发生jest.js之后(对应于程序)

如果删除属性“program”,参数会一个接一个地附加,您看不出有任何区别。