Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support TypeScript debugging with dev-server #2161

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"configurations": [
{
"name": "Debug with dev-server",
"port": 9229,
"request": "attach",
"skipFiles": [
"<node_internals>/**"
],
"type": "node",
"sourceMaps": true,
"enableTurboSourcemaps": true,
"autoAttachChildProcesses": 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/*",
}
}
]
}
26 changes: 25 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 (<kbd>F1</kbd>, 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 <kbd>F5</kbd>. 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
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down
4 changes: 3 additions & 1 deletion packages/common-db/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down
4 changes: 3 additions & 1 deletion packages/common/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion packages/controller/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down
4 changes: 3 additions & 1 deletion packages/db-base/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down
4 changes: 3 additions & 1 deletion packages/db-objects-file/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down
4 changes: 3 additions & 1 deletion packages/db-objects-jsonl/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down
4 changes: 3 additions & 1 deletion packages/db-objects-redis/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down
4 changes: 3 additions & 1 deletion packages/db-states-file/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down
4 changes: 3 additions & 1 deletion packages/db-states-jsonl/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down
4 changes: 3 additions & 1 deletion packages/db-states-redis/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down