【问题标题】:Passing arguments to a node.js package.json bin command or debugging a bin command?将参数传递给 node.js package.json bin 命令或调试 bin 命令?
【发布时间】:2019-05-11 10:46:58
【问题描述】:

我想在调试模式下启动 bin 命令。 但我似乎不能写 --inspect-brk=3000 作为参数,因为它只想接受一个文件名和 npm 链接检查文件是否存在。

  "bin": {
    "mycommand": "index.js --inspect-brk=3000",
  }

ENOENT:没有这样的文件或目录

有什么想法吗? 我可能只是制作一个 debug.js 来启动 index.js 并传递 arg 并通过管道传输 stdin/stdout。

【问题讨论】:

    标签: node.js package.json


    【解决方案1】:

    debug.js

    #!/usr/bin/env node
    // A wrapper to allow starting the index.js in debug mode port is 3000
    const { spawn } = require('child_process')
    var child = spawn('node', ['--inspect-brk=3000', 'index.js'], { stdio: 'inherit' })
    

    launch.json

            {
                "type": "node",
                "request": "launch",
                "name": "Launch Program",
                "program": "",
                "runtimeExecutable": "${workspaceFolder}/../Tools/someprogramthatrunsmine",
                "runtimeArgs": [
                    "mycommand-debug",
                    "someinputs"
                ],
                "cwd": "${workspaceFolder}",
                //"console": "integratedTerminal",
                "port": 3000
            }
        ]
    

    package.json bin 命令

      "bin": {
        "mycommand-debug": "debug.js"
      },
    

    运行npm link链接命令进行本地测试。

    现在,当我的 index.js 代码由不同的运行时可执行文件运行时,单击 Vscode 中的“调试”按钮可以对其进行断点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-21
      • 1970-01-01
      • 2020-05-09
      相关资源
      最近更新 更多