Skip to content

Commit 6254975

Browse files
Twixescharlesvien
andauthored
chore(dev): Add VS Code/Cursor debugging setup (#525)
Co-authored-by: Charles Vien <charles.v@posthog.com>
1 parent 44d5712 commit 6254975

5 files changed

Lines changed: 132 additions & 2 deletions

File tree

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ out/
1414
.env.local
1515

1616
# IDE
17-
.vscode/
17+
.vscode/*
18+
!.vscode/launch.json
19+
!.vscode/tasks.json
1820
.idea/
1921
*.swp
2022
*.swo
@@ -38,4 +40,4 @@ AGENTS.md
3840
.envrc
3941

4042
# Session store used for example-client.ts
41-
.session-store.json
43+
.session-store.json

.vscode/launch.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Debug Array (Main Process)",
6+
"type": "node",
7+
"request": "attach",
8+
"port": 5858,
9+
"restart": true,
10+
"timeout": 60000,
11+
"skipFiles": ["<node_internals>/**"],
12+
"sourceMaps": true,
13+
"address": "127.0.0.1",
14+
"localRoot": "${workspaceFolder}",
15+
"remoteRoot": "${workspaceFolder}"
16+
},
17+
{
18+
"name": "Debug Array (Renderer Process)",
19+
"type": "chrome",
20+
"request": "attach",
21+
"port": 9222,
22+
"webRoot": "${workspaceFolder}/apps/array",
23+
"timeout": 60000,
24+
"sourceMaps": true,
25+
"sourceMapPathOverrides": {
26+
"webpack:///./*": "${webRoot}/*",
27+
"webpack:///src/*": "${webRoot}/src/*",
28+
"webpack:///*": "*",
29+
"webpack:///./~/*": "${webRoot}/node_modules/*"
30+
}
31+
}
32+
],
33+
"compounds": [
34+
{
35+
"name": "Debug Array (Main + Renderer)",
36+
"configurations": [
37+
"Debug Array (Main Process)",
38+
"Debug Array (Renderer Process)"
39+
],
40+
"preLaunchTask": "start-dev-with-debug",
41+
"stopAll": true
42+
}
43+
]
44+
}

.vscode/tasks.json

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "build-electron-trpc",
6+
"type": "shell",
7+
"command": "pnpm --filter @posthog/electron-trpc build",
8+
"problemMatcher": [],
9+
"presentation": {
10+
"reveal": "silent",
11+
"panel": "dedicated"
12+
}
13+
},
14+
{
15+
"label": "start-agent-watch",
16+
"type": "shell",
17+
"command": "pnpm --filter agent dev",
18+
"isBackground": true,
19+
"problemMatcher": {
20+
"pattern": {
21+
"regexp": "^.*$",
22+
"file": 1,
23+
"location": 2,
24+
"message": 3
25+
},
26+
"background": {
27+
"activeOnStart": true,
28+
"beginsPattern": ".*Watching for changes.*",
29+
"endsPattern": ".*Build success.*"
30+
}
31+
},
32+
"presentation": {
33+
"reveal": "always",
34+
"panel": "dedicated",
35+
"group": "agent"
36+
}
37+
},
38+
{
39+
"label": "start-electron-with-debug",
40+
"type": "shell",
41+
"command": "pnpm --filter array start:debug",
42+
"isBackground": true,
43+
"problemMatcher": {
44+
"pattern": {
45+
"regexp": "^.*$",
46+
"file": 1,
47+
"location": 2,
48+
"message": 3
49+
},
50+
"background": {
51+
"activeOnStart": true,
52+
"beginsPattern": ".*Launched Electron app.*|.*Launching Vite dev servers.*",
53+
"endsPattern": ".*"
54+
}
55+
},
56+
"presentation": {
57+
"reveal": "always",
58+
"panel": "dedicated",
59+
"group": "array"
60+
},
61+
"options": {
62+
"env": {
63+
"NODE_ENV": "development",
64+
"ELECTRON_ENABLE_LOGGING": "1"
65+
}
66+
}
67+
},
68+
{
69+
"label": "start-dev-with-debug",
70+
"dependsOn": [
71+
"build-electron-trpc",
72+
"start-agent-watch",
73+
"start-electron-with-debug"
74+
],
75+
"dependsOrder": "sequence",
76+
"problemMatcher": []
77+
}
78+
]
79+
}

apps/twig/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"setup": "bash bin/setup",
1313
"dev": "electron-forge start",
1414
"start": "electron-forge start",
15+
"start:debug": "electron-forge start -- --inspect=5858 --remote-debugging-port=9222",
1516
"package": "electron-forge package",
1617
"package:dev": "FORCE_DEV_MODE=1 SKIP_NOTARIZE=1 electron-forge package",
1718
"make": "electron-forge make",

apps/twig/src/main/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ function setupExternalLinkHandlers(window: BrowserWindow): void {
138138
}
139139

140140
function createWindow(): void {
141+
const isDev = !app.isPackaged;
142+
141143
mainWindow = new BrowserWindow({
142144
width: 900,
143145
height: 600,
@@ -152,6 +154,8 @@ function createWindow(): void {
152154
preload: path.join(__dirname, "preload.js"),
153155
enableBlinkFeatures: "GetDisplayMedia",
154156
partition: "persist:main",
157+
// Enable remote debugging in development for Chrome DevTools
158+
...(isDev && { webSecurity: false }),
155159
},
156160
});
157161

0 commit comments

Comments
 (0)