-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Description
Description
When developing on Windows, using WSL2 (a proper Linux kernel running under Windows, so you get native performance gains to web applications for example) is becoming more and more common.
the @wordpress/env package by default works great under WSL2, but the xdebug configuration requires special attention.
The current configuration added when the --xdebug flag is present adds the line
xdebug.discover_client_host=true
This works great when the same host system is used, or when there's direct access, unfortunately with WSL2 there's a system in between, so the remote debugging session never connects to your IDE, but instead connects to the WSL2 system, and ends up in a black hole there.
The benefit to discover_client_host is that is' zero-config if you wish to share a debug session with others on the same network as you, but I wonder if this is actually needed, based on the pretense that this package is meant for local development, not deployments?
The solution, when using WSL2, is to disable discover_client_host and instead define the client host directly;
xdebug.discover_client_host=false
xdebug.client_host=host.docker.internal
It would also be possible to produce a conditional config here, there are a few ways to check if WSL is in use, one could check the uname -a value (My current output of this is Linux DESKTOP-L81G2QH 5.4.72-microsoft-standard-WSL2 #1 SMP Wed Oct 28 23:40:43 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux, which includes a WSL2 suffix), and also a environmental variable of WSL_DISTRO_NAME is always set on these systems.
That's a lot of background history, and then I looked at the source it self, and it looks like there is already a conditional check, the problem is that WSL is returning a Linux system to os.type(), which needs to be a false-y value for the host.docker.internal setting to be used, so perhaps this needs expanded to check for WSL if a Linux system is detected? Checking for os.release() alongside it would reveal the WSL build identifier, so maybe init-config.js:101 should be something along these lines:
const isLinux = os.type() === 'Linux' && ! os.release().indexOf( 'WSL' )
Ref:
gutenberg/packages/env/lib/init-config.js
Lines 101 to 108 in 3a7cb59
| function dockerFileContents( image, xdebugMode ) { | |
| const isLinux = os.type() === 'Linux'; | |
| // Discover client host does not appear to work on macOS with Docker. | |
| const clientDetectSettings = isLinux | |
| ? 'xdebug.discover_client_host=true' | |
| : 'xdebug.client_host="host.docker.internal"'; | |
| return `FROM ${ image } |