debugging 如何根据在Yarn工作区中设置断点的位置来调试打字脚本?

rhfm7lfc  于 2022-11-14  发布在  Yarn
关注(0)|答案(2)|浏览(174)

由于我使用的是ts-node,因此我有以下launch.json文件:

{
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Launch Program",
      "runtimeArgs": ["-r", "ts-node/register"],
      "args": ["${workspaceFolder}/packages/first/src/index.ts"]
    }
  ]
}

目前它被设置为调试first项目中的index.ts,但是如果我想调试second项目(假设有一个具有相同结构的项目),该怎么办?我尝试指定一个glob模式(如"${workspaceFolder}/packages/**/src/index.ts"),但似乎不起作用,是否有一种方法可以实现这一点,而不必每次都更改文件夹路径?

nnvyjq4y

nnvyjq4y1#

您想要两柴多个程式,所以您应该加入多个组态。您可以在launch.json中加入多个组态,并为每个项目命名。这可让您从VSCode中选择要启动和两柴的程式。

{
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Launch Program: First",
      "runtimeArgs": ["-r", "ts-node/register"],
      "args": ["${workspaceFolder}/packages/first/src/index.ts"]
    },
    {
      "type": "node",
      "request": "launch",
      "name": "Launch Program: Second",
      "runtimeArgs": ["-r", "ts-node/register"],
      "args": ["${workspaceFolder}/packages/second/src/index.ts"]
    }
  ]
}
8yoxcaq7

8yoxcaq72#

你可以试试这个
{monorepo-root-dir}/.vscode/launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "pwa-node",
      "request": "launch",
      "name": "Debug app",
      "runtimeExecutable": "yarn",
      "runtimeArgs": ["app:dev"]
    },
  ]
}

{monorepo-root-dir}/package.json

{
  "name": "poc-yarn2-typescript",
  "packageManager": "yarn@3.2.3",
  "private": true,
  "workspaces": [
    "app",
    "modules/*"
  ],
  "scripts": {
    "app:dev": "yarn workspace @scope/app run dev"
  },
  "devDependencies": {
    "typescript": "^4.8.2"
  }
}

最后是{monorepo-root-dir}/app/package.json

{
  "name": "@scope/app",
  "description": "description",
  "authors": "author",
  "version": "1.0.0",
  "main": "dist/main.js",
  "private": true,
  "packageManager": "yarn@3.2.3",
  "scripts": {
    "build": "tsc",
    "start": "node dist/main.js",
    "dev": "ts-node src/main.ts"
  },
  "dependencies": {
    "@scope/lib-one": "workspace:^"
  },
  "devDependencies": {
    "ts-node": "^10.9.1"
  }
}

我的monorepo目录结构布局看起来像这样:

完整的源代码在这里
https://github.com/alansferreira/template-yarnpkg-typescript

相关问题