{
  // Use IntelliSense to learn about possible Node.js debug attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  // For available variables, visit: https://code.visualstudio.com/docs/editor/variables-reference
  "version": "0.2.0",
  "inputs": [
    {
      // Get the name of the package containing the file in the active tab.
      "id": "getPackageName",
      "type": "command",
      "command": "shellCommand.execute",
      "args": {
        // Get the current file's absolute path, chop off everything up to and including the repo's `packages`
        // directory, then split on `/` and take the first entry
        "command": "echo '${file}' | sed s/'.*sentry-javascript\\/packages\\/'// | grep --extended-regexp --only-matching --max-count 1 '[^\\/]+' | head -1",
        "cwd": "${workspaceFolder}",
        // normally `input` commands bring up a selector for the user, but given that there should only be one
        // choice here, this lets us skip the prompt
        "useSingleResult": true
      }
    }
  ],
  "configurations": [
    // Debug the ts-node script in the currently active window
    {
      "name": "Debug ts-node script (open file)",
      "type": "pwa-node",
      "cwd": "${workspaceFolder}/packages/${input:getPackageName}",
      "request": "launch",
      "runtimeExecutable": "yarn",
      "runtimeArgs": ["ts-node", "-P", "${workspaceFolder}/tsconfig.dev.json", "${file}"],
      "skipFiles": ["<node_internals>/**"],
      "outFiles": ["${workspaceFolder}/**/*.js", "!**/node_modules/**"],
      "sourceMaps": true,
      "smartStep": true,
      "internalConsoleOptions": "openOnSessionStart",
      "outputCapture": "std"
    },
    // Run rollup using the config file which is in the currently active tab.
    {
      "name": "Debug rollup (config from open file)",
      "type": "pwa-node",
      "cwd": "${workspaceFolder}/packages/${input:getPackageName}",
      "request": "launch",
      "runtimeExecutable": "yarn",
      "runtimeArgs": ["rollup", "-c", "${file}"],
      "skipFiles": ["<node_internals>/**"],
      "outFiles": ["${workspaceFolder}/**/*.js", "!**/node_modules/**"],
      "sourceMaps": true,
      "smartStep": true,
      "internalConsoleOptions": "openOnSessionStart",
      "outputCapture": "std"
    },
    // Run a specific test file in watch mode (must have file in currently active tab when hitting the play button).
    // NOTE: If you try to run this and VSCode complains that the command `shellCommand.execute` can't be found, go
    // install the recommended extension Tasks Shell Input.
    {
      "name": "Debug unit tests - just open file",
      "type": "node",
      "cwd": "${workspaceFolder}/packages/${input:getPackageName}",
      "request": "launch",
      "program": "${workspaceFolder}/node_modules/.bin/jest",
      "args": [
        "--watch",
        // this runs one test at a time, rather than running them in parallel (necessary for debugging so that you know
        // you're hitting a single test's breakpoints, in order)
        "--runInBand",
        // coverage messes up the source maps
        "--coverage",
        "false",
        // remove this to run all package tests
        "${relativeFile}"
      ],
      "sourceMaps": true,
      "smartStep": true,
      // otherwise it goes to the VSCode debug terminal, which prints the test output or console logs (depending on
      // "outputCapture" option here; default is to show console logs), but not both
      "console": "integratedTerminal",
      // since we're not using it, don't automatically switch to it
      "internalConsoleOptions": "neverOpen"
    },

    // Run a specific test file in watch mode (must have file in currently active tab when hitting the play button).
    // NOTE: If you try to run this and VSCode complains that the command `shellCommand.execute` can't be found, go
    // install the recommended extension Tasks Shell Input.
    {
      "name": "Debug playwright tests (just open file)",
      "type": "pwa-node",
      "cwd": "${workspaceFolder}/packages/${input:getPackageName}",
      "request": "launch",
      "runtimeExecutable": "yarn",
      "runtimeArgs": [
        // `nodemon` is basically `node --watch`
        "nodemon",
        // be default it only watches JS files, so have it watch TS files instead
        "--ext",
        "ts",
        "${workspaceFolder}/node_modules/playwright/node_modules/.bin/playwright",
        "test",
        "${file}"
      ],
      "skipFiles": ["<node_internals>/**"],
      "outFiles": ["${workspaceFolder}/**/*.js", "!**/node_modules/**"],
      "sourceMaps": true,
      "smartStep": true,
      "internalConsoleOptions": "openOnSessionStart",
      // show stdout and stderr output in the debug console
      "outputCapture": "std"
    },

    // @sentry/nextjs - Run a specific integration test file
    // Must have test file in currently active tab when hitting the play button, and must already have run `yarn` in test app directory
    {
      "name": "Debug @sentry/nextjs integration tests - just open file",
      "type": "node",
      "cwd": "${workspaceFolder}/packages/nextjs",
      "request": "launch",
      // since we're not using the normal test runner, we need to make sure we're using the current version of all local
      // SDK packages and then manually rebuild the test app
      "preLaunchTask": "Prepare nextjs integration test app for debugging",
      // running `server.js` directly (rather than running the tests through yarn) allows us to skip having to reinstall
      // dependencies on every new test run
      "program": "${workspaceFolder}/packages/nextjs/test/integration/test/server.js",
      "args": [
        "--debug",
        // remove these two lines to run all integration tests
        "--filter",
        "${fileBasename}"
      ],

      "skipFiles": ["<node_internals>/**"],
      "sourceMaps": true,
      // this controls which files are sourcemapped
      "outFiles": [
        // our SDK code
        "${workspaceFolder}/**/cjs/**/*.js",
        // the built test app
        "${workspaceFolder}/packages/nextjs/test/integration/.next/**/*.js",
        "!**/node_modules/**"
      ],
      "resolveSourceMapLocations": [
        "${workspaceFolder}/**/cjs/**",
        "${workspaceFolder}/packages/nextjs/test/integration/.next/**",
        "!**/node_modules/**"
      ],
      "internalConsoleOptions": "openOnSessionStart"
    }
  ]
}
