@php-wasm/xdebug-bridge 2.0.1 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -13,24 +13,21 @@ npm install @php-wasm/xdebug-bridge
13
13
  ### Programmatic API
14
14
 
15
15
  ```typescript
16
- import { startXDebugBridge } from '@php-wasm/xdebug-bridge';
16
+ import { startBridge } from './xdebug-bridge/src/start-bridge';
17
17
 
18
18
  // Start with default settings
19
- const server = startXDebugBridge();
19
+ const server = startBridge();
20
20
  await server.start();
21
21
 
22
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
23
+ const server = startBridge({
24
+ cdpHost: 'localhost', // CDP connection host
25
+ cdpPort: 9229, // CDP connection port
26
+ dbgpPort: 9003, // XDebug connection port
27
+ phpRoot: './', // Root to directory
28
28
  });
29
29
 
30
30
  await server.start();
31
-
32
- // Stop the server
33
- await server.stop();
34
31
  ```
35
32
 
36
33
  ### CLI Usage
@@ -42,29 +39,31 @@ npx xdebug-bridge
42
39
  # Custom port and verbose logging
43
40
  npx xdebug-bridge --port 9000 --verbose
44
41
 
45
- # DAP protocol, bind to all interfaces
46
- npx xdebug-bridge --protocol dap --host 0.0.0.0
47
-
48
42
  # Show help
49
43
  npx xdebug-bridge --help
50
44
  ```
51
45
 
52
46
  ## Configuration Options
53
47
 
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
48
+ - `cdpPort`: Port to listen for CDP connections (default: 9229)
49
+ - `cdpHost`: Host to bind to (default: 'localhost')
50
+ - `dbgpPort`: Port to listen for XDebug connections (default: 9003)
51
+ - `phpRoot`: Root path for php files;
52
+ - `remoteRoot`: Remote root path for php files;
53
+ - `localRoot`: Local root path for php files;
54
+ - `phpInstance`: PHP instance
55
+ - `getPHPFile`: Custom file listing function
59
56
 
60
57
  ## Events
61
58
 
62
- The server emits events for monitoring connection activity:
59
+ The bridge listens to events for monitoring connection activity:
60
+
61
+ - `connected`: Xdebug Server has started
62
+ - `close`: Xdebug Server has stopped
63
+ - `message`: Raw XDebug data received
64
+ - `error`: Xdebug Server error occurred
63
65
 
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
66
+ - `clientConnected`: Devtools client connected
67
+ - `clientDisconnected`: Devtools client disconnected
68
+ - `message`: Raw Devtools data received
69
+ - `error`: Devtools client error occurred
package/cli.cjs CHANGED
@@ -1,20 +1 @@
1
- #!/usr/bin/env node
2
- "use strict";const p=require("util"),g=require("./xdebug-bridge-Dc4daJ9d.cjs");var c=typeof document<"u"?document.currentScript:null;function a(){console.log(`
3
- XDebug Bridge Server CLI
4
-
5
- Usage: xdebug-bridge [options]
6
-
7
- Options:
8
- --protocol <protocol> Protocol to use: cdp, dap (default: cdp)
9
- --port <port> Port to listen on (default: 9003)
10
- --host <host> Host to bind to (default: localhost)
11
- --verbose Enable verbose logging
12
- --help Show this help message
13
-
14
- Examples:
15
- xdebug-bridge # Start with default settings
16
- xdebug-bridge --port 9000 --verbose # Custom port with verbose logging
17
- xdebug-bridge --protocol dap --host 0.0.0.0 # DAP protocol, bind to all interfaces
18
- `)}function d(){try{const{values:o}=p.parseArgs({args:process.argv.slice(2),options:{protocol:{type:"string",short:"p"},port:{type:"string",short:"P"},host:{type:"string",short:"h"},verbose:{type:"boolean",short:"v"},help:{type:"boolean"}},allowPositionals:!1}),t={};if(o.protocol){if(o.protocol!=="cdp"&&o.protocol!=="dap")throw new Error(`Invalid protocol: ${o.protocol}. Must be 'cdp' or 'dap'.`);t.protocol=o.protocol}if(o.port){const e=parseInt(o.port,10);if(isNaN(e)||e<1||e>65535)throw new Error(`Invalid port: ${o.port}. Must be a number between 1 and 65535.`);t.port=e}return o.host&&(t.host=o.host),o.verbose&&(t.verbose=!0),o.help&&(t.help=!0),t}catch(o){console.error(`Error parsing arguments: ${o instanceof Error?o.message:String(o)}`),process.exit(1)}}async function u(){const o=d();if(o.help){a();return}const t={protocol:o.protocol,xdebugServerPort:o.port,xdebugServerHost:o.host,verbose:o.verbose??!0};console.log("Starting XDebug Bridge Server...");const e=g.startXDebugBridge(t),i=async s=>{console.log(`
19
- Received ${s}, shutting down gracefully...`);try{await e.stop(),console.log("XDebug Bridge Server stopped."),process.exit(0)}catch(n){console.error(`Error during shutdown: ${n instanceof Error?n.message:String(n)}`),process.exit(1)}};process.on("SIGINT",()=>i("SIGINT")),process.on("SIGTERM",()=>i("SIGTERM"));try{await e.start();const s=e.getPort(),n=e.getHost();console.log(`✅ XDebug Bridge Server is running on ${n}:${s}`),console.log(`📡 Protocol: ${t.protocol||"cdp"}`),console.log("🔍 Waiting for XDebug connections..."),console.log("Press Ctrl+C to stop the server"),e.on("connection",r=>{console.log(`🔗 New XDebug connection established from ${r.remoteAddress}:${r.remotePort}`)}),e.on("disconnection",r=>{console.log(`❌ XDebug connection closed from ${r.remoteAddress}:${r.remotePort}`)}),e.on("error",r=>{console.error(`❌ Server error: ${r.message}`)}),e.on("socketError",({socket:r,error:l})=>{console.error(`❌ Socket error from ${r.remoteAddress}:${r.remotePort}: ${l.message}`)})}catch(s){console.error(`❌ Failed to start XDebug Bridge Server: ${s instanceof Error?s.message:String(s)}`),process.exit(1)}}(typeof document>"u"?require("url").pathToFileURL(__filename).href:c&&c.tagName.toUpperCase()==="SCRIPT"&&c.src||new URL("cli.cjs",document.baseURI).href)===`file://${process.argv[1]}`&&u().catch(o=>{console.error(`❌ Unexpected error: ${o instanceof Error?o.message:String(o)}`),process.exit(1)});
20
- //# sourceMappingURL=cli.cjs.map
1
+ "use strict";const i=require("./run-cli-DpXpnvR3.cjs");i.main();
package/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
package/cli.js CHANGED
@@ -1,127 +1,2 @@
1
- #!/usr/bin/env node
2
- import { parseArgs as l } from "util";
3
- import { s as p } from "./xdebug-bridge-BeKwvQ65.js";
4
- function g() {
5
- console.log(`
6
- XDebug Bridge Server CLI
7
-
8
- Usage: xdebug-bridge [options]
9
-
10
- Options:
11
- --protocol <protocol> Protocol to use: cdp, dap (default: cdp)
12
- --port <port> Port to listen on (default: 9003)
13
- --host <host> Host to bind to (default: localhost)
14
- --verbose Enable verbose logging
15
- --help Show this help message
16
-
17
- Examples:
18
- xdebug-bridge # Start with default settings
19
- xdebug-bridge --port 9000 --verbose # Custom port with verbose logging
20
- xdebug-bridge --protocol dap --host 0.0.0.0 # DAP protocol, bind to all interfaces
21
- `);
22
- }
23
- function a() {
24
- try {
25
- const { values: o } = l({
26
- args: process.argv.slice(2),
27
- options: {
28
- protocol: {
29
- type: "string",
30
- short: "p"
31
- },
32
- port: {
33
- type: "string",
34
- short: "P"
35
- },
36
- host: {
37
- type: "string",
38
- short: "h"
39
- },
40
- verbose: {
41
- type: "boolean",
42
- short: "v"
43
- },
44
- help: {
45
- type: "boolean"
46
- }
47
- },
48
- allowPositionals: !1
49
- }), t = {};
50
- if (o.protocol) {
51
- if (o.protocol !== "cdp" && o.protocol !== "dap")
52
- throw new Error(
53
- `Invalid protocol: ${o.protocol}. Must be 'cdp' or 'dap'.`
54
- );
55
- t.protocol = o.protocol;
56
- }
57
- if (o.port) {
58
- const r = parseInt(o.port, 10);
59
- if (isNaN(r) || r < 1 || r > 65535)
60
- throw new Error(
61
- `Invalid port: ${o.port}. Must be a number between 1 and 65535.`
62
- );
63
- t.port = r;
64
- }
65
- return o.host && (t.host = o.host), o.verbose && (t.verbose = !0), o.help && (t.help = !0), t;
66
- } catch (o) {
67
- console.error(
68
- `Error parsing arguments: ${o instanceof Error ? o.message : String(o)}`
69
- ), process.exit(1);
70
- }
71
- }
72
- async function d() {
73
- const o = a();
74
- if (o.help) {
75
- g();
76
- return;
77
- }
78
- const t = {
79
- protocol: o.protocol,
80
- xdebugServerPort: o.port,
81
- xdebugServerHost: o.host,
82
- verbose: o.verbose ?? !0
83
- // CLI defaults to verbose
84
- };
85
- console.log("Starting XDebug Bridge Server...");
86
- const r = p(t), c = async (s) => {
87
- console.log(`
88
- Received ${s}, shutting down gracefully...`);
89
- try {
90
- await r.stop(), console.log("XDebug Bridge Server stopped."), process.exit(0);
91
- } catch (n) {
92
- console.error(
93
- `Error during shutdown: ${n instanceof Error ? n.message : String(n)}`
94
- ), process.exit(1);
95
- }
96
- };
97
- process.on("SIGINT", () => c("SIGINT")), process.on("SIGTERM", () => c("SIGTERM"));
98
- try {
99
- await r.start();
100
- const s = r.getPort(), n = r.getHost();
101
- console.log(`✅ XDebug Bridge Server is running on ${n}:${s}`), console.log(`📡 Protocol: ${t.protocol || "cdp"}`), console.log("🔍 Waiting for XDebug connections..."), console.log("Press Ctrl+C to stop the server"), r.on("connection", (e) => {
102
- console.log(
103
- `🔗 New XDebug connection established from ${e.remoteAddress}:${e.remotePort}`
104
- );
105
- }), r.on("disconnection", (e) => {
106
- console.log(
107
- `❌ XDebug connection closed from ${e.remoteAddress}:${e.remotePort}`
108
- );
109
- }), r.on("error", (e) => {
110
- console.error(`❌ Server error: ${e.message}`);
111
- }), r.on("socketError", ({ socket: e, error: i }) => {
112
- console.error(
113
- `❌ Socket error from ${e.remoteAddress}:${e.remotePort}: ${i.message}`
114
- );
115
- });
116
- } catch (s) {
117
- console.error(
118
- `❌ Failed to start XDebug Bridge Server: ${s instanceof Error ? s.message : String(s)}`
119
- ), process.exit(1);
120
- }
121
- }
122
- import.meta.url === `file://${process.argv[1]}` && d().catch((o) => {
123
- console.error(
124
- `❌ Unexpected error: ${o instanceof Error ? o.message : String(o)}`
125
- ), process.exit(1);
126
- });
127
- //# sourceMappingURL=cli.js.map
1
+ import { m } from "./run-cli-II34aG2V.js";
2
+ m();
package/index.cjs CHANGED
@@ -1,2 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./xdebug-bridge-Dc4daJ9d.cjs");exports.startXDebugBridge=e.startXDebugBridge;
2
- //# sourceMappingURL=index.cjs.map
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./run-cli-DpXpnvR3.cjs");exports.CDPServer=e.CDPServer;exports.DbgpSession=e.DbgpSession;exports.XdebugCDPBridge=e.XdebugCDPBridge;exports.main=e.main;exports.startBridge=e.startBridge;
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './lib';
package/index.js CHANGED
@@ -1,5 +1,8 @@
1
- import { s } from "./xdebug-bridge-BeKwvQ65.js";
1
+ import { C as e, D as r, X as g, m as i, s as D } from "./run-cli-II34aG2V.js";
2
2
  export {
3
- s as startXDebugBridge
3
+ e as CDPServer,
4
+ r as DbgpSession,
5
+ g as XdebugCDPBridge,
6
+ i as main,
7
+ D as startBridge
4
8
  };
5
- //# sourceMappingURL=index.js.map
@@ -0,0 +1,8 @@
1
+ /// <reference types="node" />
2
+ import { EventEmitter } from 'events';
3
+ export declare class CDPServer extends EventEmitter {
4
+ private wss;
5
+ private ws;
6
+ constructor(port?: number);
7
+ sendMessage(message: any): void;
8
+ }
@@ -0,0 +1,11 @@
1
+ /// <reference types="node" />
2
+ import { EventEmitter } from 'events';
3
+ export declare class DbgpSession extends EventEmitter {
4
+ private server;
5
+ private socket;
6
+ private buffer;
7
+ private expectedLength;
8
+ constructor(port?: number);
9
+ private onData;
10
+ sendCommand(command: string): void;
11
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from './cdp-server';
2
+ export * from './dbgp-session';
3
+ export * from './run-cli';
4
+ export * from './start-bridge';
5
+ export * from './xdebug-cdp-bridge';
@@ -0,0 +1 @@
1
+ export declare function main(): Promise<void>;
@@ -0,0 +1,13 @@
1
+ import type { PHP } from '@php-wasm/universal';
2
+ import { XdebugCDPBridge } from './xdebug-cdp-bridge';
3
+ export type StartBridgeConfig = {
4
+ cdpPort?: number;
5
+ cdpHost?: string;
6
+ dbgpPort?: number;
7
+ phpRoot?: string;
8
+ remoteRoot?: string;
9
+ localRoot?: string;
10
+ phpInstance?: PHP;
11
+ getPHPFile?: (path: string) => string;
12
+ };
13
+ export declare function startBridge(config: StartBridgeConfig): Promise<XdebugCDPBridge>;
@@ -0,0 +1,36 @@
1
+ import type { DbgpSession } from './dbgp-session';
2
+ import type { CDPServer } from './cdp-server';
3
+ export interface XdebugCDPBridgeConfig {
4
+ knownScriptUrls: string[];
5
+ remoteRoot?: string;
6
+ localRoot?: string;
7
+ getPHPFile(path: string): string;
8
+ }
9
+ export declare class XdebugCDPBridge {
10
+ private dbgp;
11
+ cdp: CDPServer;
12
+ private nextTxnId;
13
+ private pendingCommands;
14
+ private breakpoints;
15
+ private scriptIdByUrl;
16
+ private nextScriptId;
17
+ private objectHandles;
18
+ private nextObjectId;
19
+ private callFramesMap;
20
+ private xdebugConnected;
21
+ private xdebugStatus;
22
+ private initFileUri;
23
+ private readPHPFile;
24
+ private remoteRoot;
25
+ private localRoot;
26
+ constructor(dbgp: DbgpSession, cdp: CDPServer, config: XdebugCDPBridgeConfig);
27
+ start(): void;
28
+ private sendInitialScripts;
29
+ private getOrCreateScriptId;
30
+ private formatPropertyFullName;
31
+ private sendDbgpCommand;
32
+ private handleCdpMessage;
33
+ private uriToRemotePath;
34
+ private remoteToLocal;
35
+ private handleDbgpMessage;
36
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@php-wasm/xdebug-bridge",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "description": "XDebug bridge server for PHP.wasm",
5
5
  "repository": {
6
6
  "type": "git",
@@ -26,7 +26,7 @@
26
26
  "type": "module",
27
27
  "main": "./index.cjs",
28
28
  "module": "./index.js",
29
- "bin": "cli.js",
29
+ "bin": "xdebug-bridge.js",
30
30
  "typedoc": {
31
31
  "entryPoint": "./src/index.ts",
32
32
  "readmeFile": "./README.md",
@@ -39,11 +39,18 @@
39
39
  },
40
40
  "license": "GPL-2.0-or-later",
41
41
  "types": "index.d.ts",
42
- "gitHead": "5ecb8899a1650bef8841585f01d3092fa498a419",
42
+ "gitHead": "6355c320ae2de93d4a0176e45ded2ad4cc6f4ae2",
43
43
  "engines": {
44
44
  "node": ">=20.18.3",
45
45
  "npm": ">=10.1.0"
46
46
  },
47
+ "dependencies": {
48
+ "ini": "4.1.2",
49
+ "ws": "8.18.1",
50
+ "xml2js": "0.6.2",
51
+ "yargs": "17.7.2",
52
+ "@php-wasm/universal": "2.0.3"
53
+ },
47
54
  "overrides": {
48
55
  "rollup": "^4.34.6",
49
56
  "react": "18.3.1",
@@ -51,5 +58,7 @@
51
58
  "typescript": "5.4.5",
52
59
  "ws": "^8.18.0"
53
60
  },
54
- "dependencies": {}
61
+ "optionalDependencies": {
62
+ "fs-ext": "2.1.1"
63
+ }
55
64
  }