Skip to content

Commit ad6583c

Browse files
authored
[XDebug] Add a mock @php-wasm/xdebug-bridge package (#2398)
## Motivation for the change, related issues Adds a mock, AI-generated `@php-wasm/xdebug-bridge` package to jumpstart the work on [XDebug in browser devtools](#2288). Cursor prompt: > Create a new package `@php-wasm/xdebug-bridge` with a startXDebugBridge() function that starts a plain network server, It should accept a few config params via an object, e.g. protocol ("cdp"), xdebugServerPort (number, default to xdebug default port). > > It should also ship a CLI script that can be used to run that function from CLI. Accept CLI args, print useful information, but make sure startXDebugBridge() can still be executed without printing anything to console. ## Testing Instructions (or ideally a Blueprint) Confirm it doesn't break the CI. cc @mho22
1 parent 39642b2 commit ad6583c

File tree

14 files changed

+734
-0
lines changed

14 files changed

+734
-0
lines changed

package-lock.json

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"extends": ["../../../.eslintrc.json"],
3+
"ignorePatterns": ["!**/*"],
4+
"overrides": [
5+
{
6+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7+
"rules": {}
8+
},
9+
{
10+
"files": ["*.ts", "*.tsx"],
11+
"rules": {}
12+
},
13+
{
14+
"files": ["*.js", "*.jsx"],
15+
"rules": {}
16+
}
17+
]
18+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# @php-wasm/xdebug-bridge
2+
3+
XDebug bridge server for PHP.wasm that enables debugging connections between XDebug and debugging clients.
4+
5+
## Installation
6+
7+
```bash
8+
npm install @php-wasm/xdebug-bridge
9+
```
10+
11+
## Usage
12+
13+
### Programmatic API
14+
15+
```typescript
16+
import { startXDebugBridge } from '@php-wasm/xdebug-bridge';
17+
18+
// Start with default settings
19+
const server = startXDebugBridge();
20+
await server.start();
21+
22+
// Start with custom configuration
23+
const server = startXDebugBridge({
24+
protocol: 'cdp', // or 'dap'
25+
xdebugServerPort: 9003, // XDebug connection port
26+
xdebugServerHost: 'localhost',
27+
verbose: false, // Silent mode
28+
});
29+
30+
await server.start();
31+
32+
// Stop the server
33+
await server.stop();
34+
```
35+
36+
### CLI Usage
37+
38+
```bash
39+
# Start with default settings
40+
npx xdebug-bridge
41+
42+
# Custom port and verbose logging
43+
npx xdebug-bridge --port 9000 --verbose
44+
45+
# DAP protocol, bind to all interfaces
46+
npx xdebug-bridge --protocol dap --host 0.0.0.0
47+
48+
# Show help
49+
npx xdebug-bridge --help
50+
```
51+
52+
## Configuration Options
53+
54+
- `protocol`: Protocol to use ('cdp' or 'dap', default: 'cdp')
55+
- `xdebugServerPort`: Port to listen for XDebug connections (default: 9003)
56+
- `xdebugServerHost`: Host to bind to (default: 'localhost')
57+
- `verbose`: Enable verbose logging (default: false for API, true for CLI)
58+
- `logger`: Custom logger function
59+
60+
## Events
61+
62+
The server emits events for monitoring connection activity:
63+
64+
- `started`: Server has started
65+
- `stopped`: Server has stopped
66+
- `connection`: New XDebug connection established
67+
- `disconnection`: XDebug connection closed
68+
- `xdebugData`: Raw XDebug data received
69+
- `error`: Server error occurred
70+
- `socketError`: Socket-level error occurred
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"name": "@php-wasm/xdebug-bridge",
3+
"version": "1.2.3",
4+
"description": "XDebug bridge server for PHP.wasm",
5+
"repository": {
6+
"type": "git",
7+
"url": "https://github.com/WordPress/wordpress-playground"
8+
},
9+
"homepage": "https://developer.wordpress.org/playground",
10+
"author": "The WordPress contributors",
11+
"contributors": [
12+
{
13+
"name": "Adam Zielinski",
14+
"email": "[email protected]",
15+
"url": "https://github.com/adamziel"
16+
}
17+
],
18+
"exports": {
19+
".": {
20+
"import": "./index.js",
21+
"require": "./index.cjs"
22+
},
23+
"./package.json": "./package.json",
24+
"./README.md": "./README.md"
25+
},
26+
"type": "module",
27+
"main": "./index.cjs",
28+
"module": "./index.js",
29+
"bin": "cli.js",
30+
"typedoc": {
31+
"entryPoint": "./src/index.ts",
32+
"readmeFile": "./README.md",
33+
"displayName": "@php-wasm/xdebug-bridge",
34+
"tsconfig": "./tsconfig.lib.json"
35+
},
36+
"publishConfig": {
37+
"access": "public",
38+
"directory": "../../../dist/packages/php-wasm/xdebug-bridge"
39+
},
40+
"license": "GPL-2.0-or-later",
41+
"types": "index.d.ts",
42+
"gitHead": "2f8d8f3cea548fbd75111e8659a92f601cddc593",
43+
"engines": {
44+
"node": ">=20.18.3",
45+
"npm": ">=10.1.0"
46+
}
47+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"name": "php-wasm-xdebug-bridge",
3+
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "packages/php-wasm/xdebug-bridge/src",
5+
"projectType": "library",
6+
"targets": {
7+
"build": {
8+
"executor": "nx:noop",
9+
"dependsOn": ["build:README"]
10+
},
11+
"build:README": {
12+
"executor": "nx:run-commands",
13+
"options": {
14+
"commands": [
15+
"cp packages/php-wasm/xdebug-bridge/README.md dist/packages/php-wasm/xdebug-bridge"
16+
]
17+
},
18+
"dependsOn": ["build:package-json"]
19+
},
20+
"build:package-json": {
21+
"executor": "@wp-playground/nx-extensions:package-json",
22+
"options": {
23+
"tsConfig": "packages/php-wasm/xdebug-bridge/tsconfig.lib.json",
24+
"outputPath": "dist/packages/php-wasm/xdebug-bridge",
25+
"buildTarget": "php-wasm-xdebug-bridge:build:bundle:production"
26+
}
27+
},
28+
"build:bundle": {
29+
"executor": "@nx/vite:build",
30+
"outputs": ["{options.outputPath}"],
31+
"options": {
32+
"main": "dist/packages/php-wasm/xdebug-bridge/index.js",
33+
"outputPath": "dist/packages/php-wasm/xdebug-bridge"
34+
},
35+
"defaultConfiguration": "production",
36+
"configurations": {
37+
"development": {
38+
"minify": false
39+
},
40+
"production": {
41+
"minify": true
42+
}
43+
}
44+
},
45+
"dev": {
46+
"executor": "nx:run-commands",
47+
"options": {
48+
"command": "bun --watch ./packages/php-wasm/xdebug-bridge/src/cli.ts",
49+
"tty": true
50+
}
51+
},
52+
"test": {
53+
"executor": "@nx/vite:test",
54+
"outputs": [
55+
"{workspaceRoot}/coverage/packages/php-wasm/xdebug-bridge"
56+
],
57+
"options": {
58+
"reportsDirectory": "../../../coverage/packages/php-wasm/xdebug-bridge",
59+
"testFiles": ["tests/mock-test.spec.ts"]
60+
}
61+
},
62+
"lint": {
63+
"executor": "@nx/eslint:lint",
64+
"outputs": ["{options.outputFile}"],
65+
"options": {
66+
"lintFilePatterns": ["packages/php-wasm/xdebug-bridge/**/*.ts"]
67+
}
68+
}
69+
},
70+
"tags": ["php-wasm"]
71+
}

0 commit comments

Comments
 (0)