【问题标题】:Debugging custom Yeoman generator using VSCode使用 VSCode 调试自定义 Yeoman 生成器
【发布时间】:2015-08-15 11:49:41
【问题描述】:

花时间让 VSCode 调试我正在开发的自定义 Yeoman 生成器。

Yeoman 文档说要像这样执行生成器:

node --debug `which yo` <generator> [arguments]

我使用 node-inspector 完成了这项工作。我在一个终端窗口中启动节点检查器,然后在另一个窗口中执行上述操作,当我使用节点检查器站点启动浏览器时,我可以在 yeoman 生成器的脚本中附加并命中断点。

现在我正在尝试使用 VSCode 进行设置。我在这里不需要节点检查器...所以我设置了一个如下所示的启动配置:

{
    // Name of configuration; appears in the launch configuration drop down menu.
    "name": "Launch yeoman generator-nodehttps",
    // Type of configuration. Possible values: "node", "mono".
    "type": "node",
    // Workspace relative or absolute path to the program.
    "program": "/Users/ac/.npm-packages/lib/node_modules/yo/lib/cli.js",
    // Automatically stop program after launch.
    "stopOnEntry": false,
    // Command line arguments passed to the program.
    "args": ["nodehttps"],
    // Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
    "cwd": ".",
    // Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
    "runtimeExecutable": null,
    // Environment variables passed to the program.
    "env": { }
}

我的 program 属性不同的原因是因为将 which yo(用单引号或不加引号)放在 VSCode 中会产生一个错误,即“哪个 yo 不存在

它成功启动了一个新的终端窗口并且我可以与生成器进行交互,但是我的断点都没有被命中,我也没有在 VSCode 调用堆栈/变量窗口中看到任何显示...但是 VSCode 似乎附加到进程(编辑器底部的橙色条)。

但无论我如何调整,我似乎都无法让 VSCode 调试我的生成器......想法?

【问题讨论】:

    标签: debugging yeoman visual-studio-code yeoman-generator


    【解决方案1】:

    运行 'which yo' 会导致 '/usr/local/bin/yo'。我建议将其用于“程序”属性。此外,将“stopOnEntry”设置为 true,这样您就可以看到发生了什么。对我来说,使用 VSCode 调试你可以使用这个启动配置:

    {
        "name": "yo",
        "type": "node",
        "program": "/usr/local/bin/yo",
        "args": ["nodehttps"],
        "stopOnEntry": true
    }
    

    【讨论】:

    • 完美......这也对我有用。我有一条通往 Yeoman 的不同路径,因为我将 NPM 全局包保存到我的个人资料文件夹中,以避免每次使用全局包时都使用 sudo
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多