Skip to content

Commit a064680

Browse files
authored
[ xdebug ] Add --experimental-devtools option in php-wasm CLI (#2408)
1 parent aa0cbd6 commit a064680

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

packages/php-wasm/cli/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"dev": {
4646
"executor": "nx:run-commands",
4747
"options": {
48-
"command": "bun --watch ./packages/php-wasm/cli/src/main.ts",
48+
"command": "node --no-warnings --experimental-wasm-stack-switching --experimental-wasm-jspi --loader=./packages/meta/src/node-es-module-loader/loader.mts ./packages/php-wasm/cli/src/main.ts",
4949
"tty": true
5050
}
5151
},

packages/php-wasm/cli/src/main.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type { SupportedPHPVersion } from '@php-wasm/universal';
1414
import { FileLockManagerForNode } from '@php-wasm/node';
1515
import { PHP } from '@php-wasm/universal';
1616
import { loadNodeRuntime, useHostFilesystem } from '@php-wasm/node';
17+
import { startBridge } from '@php-wasm/xdebug-bridge';
1718
import path from 'path';
1819

1920
let args = process.argv.slice(2);
@@ -43,6 +44,13 @@ async function run() {
4344
args = args.filter((arg) => arg !== '--xdebug');
4445
}
4546

47+
const hasDevtoolsOption = args.some((arg) =>
48+
arg.startsWith('--experimental-devtools')
49+
);
50+
if (hasDevtoolsOption) {
51+
args = args.filter((arg) => arg !== '--experimental-devtools');
52+
}
53+
4654
// npm scripts set the TMPDIR env variable
4755
// PHP accepts a TMPDIR env variable and expects it to
4856
// be a writable directory within the PHP filesystem.
@@ -97,6 +105,12 @@ ${process.argv[0]} ${process.execArgv.join(' ')} ${process.argv[1]}
97105

98106
useHostFilesystem(php);
99107

108+
if (hasDevtoolsOption && hasXdebugOption) {
109+
const bridge = await startBridge({});
110+
111+
bridge.start();
112+
}
113+
100114
const hasMinusCOption = args.some((arg) => arg.startsWith('-c'));
101115
if (!hasMinusCOption) {
102116
args.unshift('-c', defaultPhpIniPath);

packages/php-wasm/cli/vite.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@ export default defineConfig({
1818
external: [
1919
'@php-wasm/node',
2020
'@php-wasm/universal',
21+
'assert',
2122
'net',
2223
'fs',
2324
'path',
2425
'child_process',
2526
'http',
27+
'stream',
28+
'timers',
2629
'tls',
30+
'url',
2731
'util',
2832
'dns',
2933
'ws',

0 commit comments

Comments
 (0)