From e8b7fbd699fba959fbef88a2b1b6c8584966ebb5 Mon Sep 17 00:00:00 2001 From: Junyi Date: Wed, 3 Jan 2024 09:19:51 +0800 Subject: [PATCH] chore(vscode): add inspect argument for attaching to debug port (#3307) --- .vscode/launch.json | 10 ++++++++++ packages/core/cli/src/commands/dev.js | 10 ++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 32b0b4193..8069f3847 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,6 +11,16 @@ "console": "integratedTerminal", "internalConsoleOptions": "neverOpen" }, + { + "address": "localhost", + "localRoot": "${workspaceFolder}", + "name": "Attach to debug server (remote)", + "port": 9229, + "remoteRoot": "${workspaceFolder}", + "request": "attach", + "skipFiles": ["/**"], + "type": "node" + }, { "type": "node", "request": "launch", diff --git a/packages/core/cli/src/commands/dev.js b/packages/core/cli/src/commands/dev.js index 98e17f69c..4a0d1aa6b 100644 --- a/packages/core/cli/src/commands/dev.js +++ b/packages/core/cli/src/commands/dev.js @@ -15,6 +15,7 @@ module.exports = (cli) => { .option('--client') .option('--server') .option('--db-sync') + .option('--inspect [port]') .allowUnknownOption() .action(async (opts) => { promptForTs(); @@ -33,7 +34,7 @@ module.exports = (cli) => { return; } - const { port, client, server } = opts; + const { port, client, server, inspect } = opts; if (port) { process.env.APP_PORT = opts.port; @@ -59,8 +60,13 @@ module.exports = (cli) => { if (server || !client) { console.log('starting server', serverPort); + const filteredArgs = process.argv.filter( + (item, i) => !item.startsWith('--inspect') && !(process.argv[i - 1] === '--inspect' && Number.parseInt(item)), + ); + const argv = [ 'watch', + ...(inspect ? [`--inspect=${inspect === true ? 9229 : inspect}`] : []), '--ignore=./storage/plugins/**', '--tsconfig', SERVER_TSCONFIG_PATH, @@ -68,7 +74,7 @@ module.exports = (cli) => { 'tsconfig-paths/register', `${APP_PACKAGE_ROOT}/src/index.ts`, 'start', - ...process.argv.slice(3), + ...filteredArgs.slice(3), `--port=${serverPort}`, ];