From 7ce0a867d9e4bfe66bd408f5cad446c41ad7c7d1 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Tue, 28 Mar 2023 22:36:42 +0200 Subject: [PATCH 1/3] support TypeScript debugging with dev-server --- .vscode/launch.json | 37 +++++++++++++++++++++++++ packages/cli/tsconfig.json | 4 ++- packages/common-db/tsconfig.json | 4 ++- packages/common/tsconfig.json | 4 ++- packages/controller/tsconfig.json | 4 ++- packages/db-base/tsconfig.json | 4 ++- packages/db-objects-file/tsconfig.json | 4 ++- packages/db-objects-jsonl/tsconfig.json | 4 ++- packages/db-objects-redis/tsconfig.json | 4 ++- packages/db-states-file/tsconfig.json | 4 ++- packages/db-states-jsonl/tsconfig.json | 4 ++- packages/db-states-redis/tsconfig.json | 4 ++- 12 files changed, 70 insertions(+), 11 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000000..b5086ea7ca --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,37 @@ +{ + "configurations": [ + { + "name": "Debug with dev-server", + "port": 9229, + "request": "attach", + "skipFiles": [ + "/**" + ], + "type": "node", + "sourceMaps": true, + "resolveSourceMapLocations": [ + "${workspaceFolder}/packages/**", + // We need to look for source maps in .dev-server + "${workspaceFolder}/.dev-server/**", + // and the node_modules/@iobroker directories, which are symlinked to the packages/ subdirs + "${workspaceFolder}/node_modules/@iobroker/**", + // Do not look multiple levels deep though + "!${workspaceFolder}/node_modules/@iobroker/**/node_modules/**", + ], + "sourceMapPathOverrides": { + "~/adapter/*": "${workspaceFolder}/packages/adapter/src/*", + "~/cli/*": "${workspaceFolder}/packages/cli/src/*", + "~/common-db/*": "${workspaceFolder}/packages/common-db/src/*", + "~/common/*": "${workspaceFolder}/packages/common/src/*", + "~/controller/*": "${workspaceFolder}/packages/controller/src/*", + "~/db-base/*": "${workspaceFolder}/packages/db-base/src/*", + "~/db-objects-file/*": "${workspaceFolder}/packages/db-objects-file/src/*", + "~/db-objects-jsonl/*": "${workspaceFolder}/packages/db-objects-jsonl/src/*", + "~/db-objects-redis/*": "${workspaceFolder}/packages/db-objects-redis/src/*", + "~/db-states-file/*": "${workspaceFolder}/packages/db-states-file/src/*", + "~/db-states-jsonl/*": "${workspaceFolder}/packages/db-states-jsonl/src/*", + "~/db-states-redis/*": "${workspaceFolder}/packages/db-states-redis/src/*", + } + } + ] +} \ No newline at end of file diff --git a/packages/cli/tsconfig.json b/packages/cli/tsconfig.json index 1a532efe4d..5c2f844281 100644 --- a/packages/cli/tsconfig.json +++ b/packages/cli/tsconfig.json @@ -2,7 +2,9 @@ "extends": "../../tsconfig.json", "compilerOptions": { "outDir": "build", - "rootDir": "src" + "rootDir": "src", + // This is needed to make sourcemaps work for debugging + "sourceRoot": "~/cli/" }, "references": [ { diff --git a/packages/common-db/tsconfig.json b/packages/common-db/tsconfig.json index 3601440cd9..978a7b20ce 100644 --- a/packages/common-db/tsconfig.json +++ b/packages/common-db/tsconfig.json @@ -3,7 +3,9 @@ "compilerOptions": { "outDir": "build", "rootDir": "src", - "noEmit": false + "noEmit": false, + // This is needed to make sourcemaps work for debugging + "sourceRoot": "~/common-db/" }, "references": [ { diff --git a/packages/common/tsconfig.json b/packages/common/tsconfig.json index 19d8e75aa3..7beb2899b8 100644 --- a/packages/common/tsconfig.json +++ b/packages/common/tsconfig.json @@ -2,7 +2,9 @@ "extends": "../../tsconfig.json", "compilerOptions": { "outDir": "build", - "rootDir": "src" + "rootDir": "src", + // This is needed to make sourcemaps work for debugging + "sourceRoot": "~/common/" }, "include": [ "src/**/*.ts" diff --git a/packages/controller/tsconfig.json b/packages/controller/tsconfig.json index 8044183095..16dbb5375f 100644 --- a/packages/controller/tsconfig.json +++ b/packages/controller/tsconfig.json @@ -2,7 +2,9 @@ "extends": "../../tsconfig.json", "compilerOptions": { "outDir": "build", - "rootDir": "src" + "rootDir": "src", + // This is needed to make sourcemaps work for debugging + "sourceRoot": "~/controller/" }, "references": [ { diff --git a/packages/db-base/tsconfig.json b/packages/db-base/tsconfig.json index ca914a8157..698dca6379 100644 --- a/packages/db-base/tsconfig.json +++ b/packages/db-base/tsconfig.json @@ -2,7 +2,9 @@ "extends": "../../tsconfig.json", "compilerOptions": { "outDir": "build", - "rootDir": "src" + "rootDir": "src", + // This is needed to make sourcemaps work for debugging + "sourceRoot": "~/db-base/" }, "references": [ { diff --git a/packages/db-objects-file/tsconfig.json b/packages/db-objects-file/tsconfig.json index 90126e8748..9da2090f31 100644 --- a/packages/db-objects-file/tsconfig.json +++ b/packages/db-objects-file/tsconfig.json @@ -3,7 +3,9 @@ "compilerOptions": { "outDir": "build", "rootDir": "src", - "noEmit": false + "noEmit": false, + // This is needed to make sourcemaps work for debugging + "sourceRoot": "~/db-objects-file/" }, "references": [ { diff --git a/packages/db-objects-jsonl/tsconfig.json b/packages/db-objects-jsonl/tsconfig.json index 60c522b93e..6fd0eae9a6 100644 --- a/packages/db-objects-jsonl/tsconfig.json +++ b/packages/db-objects-jsonl/tsconfig.json @@ -3,7 +3,9 @@ "compilerOptions": { "outDir": "build", "rootDir": "src", - "noEmit": false + "noEmit": false, + // This is needed to make sourcemaps work for debugging + "sourceRoot": "~/db-objects-jsonl/" }, "references": [ { diff --git a/packages/db-objects-redis/tsconfig.json b/packages/db-objects-redis/tsconfig.json index 116add2f9c..caf745b847 100644 --- a/packages/db-objects-redis/tsconfig.json +++ b/packages/db-objects-redis/tsconfig.json @@ -2,7 +2,9 @@ "extends": "../../tsconfig.json", "compilerOptions": { "outDir": "build", - "rootDir": "src" + "rootDir": "src", + // This is needed to make sourcemaps work for debugging + "sourceRoot": "~/db-objects-redis/" }, "references": [ { diff --git a/packages/db-states-file/tsconfig.json b/packages/db-states-file/tsconfig.json index 1f4bd47c98..fbd030d7ad 100644 --- a/packages/db-states-file/tsconfig.json +++ b/packages/db-states-file/tsconfig.json @@ -3,7 +3,9 @@ "compilerOptions": { "outDir": "build", "rootDir": "src", - "noEmit": false + "noEmit": false, + // This is needed to make sourcemaps work for debugging + "sourceRoot": "~/db-states-file/" }, "references": [ { diff --git a/packages/db-states-jsonl/tsconfig.json b/packages/db-states-jsonl/tsconfig.json index 6860e458ac..895ce9e1c2 100644 --- a/packages/db-states-jsonl/tsconfig.json +++ b/packages/db-states-jsonl/tsconfig.json @@ -3,7 +3,9 @@ "compilerOptions": { "outDir": "build", "rootDir": "src", - "noEmit": false + "noEmit": false, + // This is needed to make sourcemaps work for debugging + "sourceRoot": "~/db-states-jsonl/" }, "references": [ { diff --git a/packages/db-states-redis/tsconfig.json b/packages/db-states-redis/tsconfig.json index 01b381d36a..1f79fa7f8d 100644 --- a/packages/db-states-redis/tsconfig.json +++ b/packages/db-states-redis/tsconfig.json @@ -2,7 +2,9 @@ "extends": "../../tsconfig.json", "compilerOptions": { "outDir": "build", - "rootDir": "src" + "rootDir": "src", + // This is needed to make sourcemaps work for debugging + "sourceRoot": "~/db-states-redis/" }, "references": [ { From fd2b96614e25c8eed3ac2eea98b87994acf0e953 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Tue, 28 Mar 2023 22:50:35 +0200 Subject: [PATCH 2/3] fix: this seems to be needed too --- .vscode/launch.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.vscode/launch.json b/.vscode/launch.json index b5086ea7ca..cbeb4c8ee4 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,6 +9,8 @@ ], "type": "node", "sourceMaps": true, + "enableTurboSourcemaps": true, + "autoAttachChildProcesses": true, "resolveSourceMapLocations": [ "${workspaceFolder}/packages/**", // We need to look for source maps in .dev-server From 3a44491fb6bdeae4336018479cb22f01091bb745 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Tue, 28 Mar 2023 23:04:57 +0200 Subject: [PATCH 3/3] update contributing guide --- CONTRIBUTING.md | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a945556d47..86a8c28a4d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -44,7 +44,31 @@ When creating a PR, the tests will automatically run on the CI server on all cur We have migrated most of the codebase to TypeScript, thus new files have to be written in TypeScript too. Please ensure that your code changes are in line with our style guide via `eslint` (see [Linting](#linting)). If you are adding a new feature, or you have fixed a bug which is testable, please make sure to add a new test. Also ensure, that all existing tests are passing, before proposing a code change (see [Testing](#testing)). -Testing your code change in a running environment is currently a bit tricky. Ensure you have installed the latest nightly release of the js-controller by executing + +#### Testing in development +To test code changes, using [`dev-server`](https://github.com/ioBroker/dev-server/) is highly recommended: +1. Install or update `dev-server` to the latest version via `npm i -g @iobroker/dev-server@latest` (if not done already) +2. Setup `dev-server` in the `js-controller` repository using: + ```bash + dev-server setup --entrypoint packages/controller --symlinks + ``` +3. Open a separate terminal where you rebuild JS-Controller on code changes: + ```bash + npm run watch:ts + ``` +4. Start JS-Controller using the dev-server by executing the following in the first terminal: + ```bash + dev-server debug -x + ``` +5. Attach your debugger: + - If using VSCode: + 1. Make sure that auto-attaching is disabled (F1, enter "toggle auto attach", select "disabled"). + 2. Go to the "debug" tab and make sure "Debug with dev-server" is selected. + 3. Start a new debug session using F5. You should be able to set breakpoints in the `.ts` files and step through them. + - If using WebStorm, figure out how to translate the launch config in `.vscode/launch.json` to WebStorm (TODO!). + +#### Testing in production +Testing your code change in a productive environment is currently a bit tricky. Ensure you have installed the latest nightly release of the js-controller by executing ```bash npm i iobroker.js-controller@dev