-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Install Xdebug 3 into the wp-env development service. * Add flag to wp-env start for setting Xdebug mode. * Add VS Code debugger configuration for Xdebug. * Only write to internal wp-env docker files on wp-env start command. * Fail if wp-env command is run without docker files set up. * Update readme with all of the recent wp-env changes.
- Loading branch information
1 parent
7ae456c
commit 454c708
Showing
9 changed files
with
253 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Listen for Xdebug", | ||
"type": "php", | ||
"request": "launch", | ||
"port": 9003, | ||
"pathMappings": { | ||
"/var/www/html/wp-content/plugins/gutenberg": "${workspaceRoot}/" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// See https://xdebug.org/docs/all_settings#mode | ||
const XDEBUG_MODES = [ | ||
'develop', | ||
'coverage', | ||
'debug', | ||
'gcstats', | ||
'profile', | ||
'trace', | ||
]; | ||
|
||
/** | ||
* Custom parsing for the Xdebug mode set via yargs. This function ensures two things: | ||
* 1. If the --xdebug flag was set by itself, default to 'debug'. | ||
* 2. If the --xdebug flag includes modes, make sure they are accepted by Xdebug. | ||
* | ||
* Note: ideally, we would also have this handle the case where no xdebug flag | ||
* is set (and then turn Xdebug off). However, yargs does not pass 'undefined' | ||
* to the coerce callback, so we cannot handle that case here. | ||
* | ||
* @param {string} value The user-set mode of Xdebug | ||
* @return {string} The Xdebug mode to use with defaults applied. | ||
*/ | ||
module.exports = function parseXdebugMode( value ) { | ||
if ( typeof value !== 'string' ) { | ||
throwXdebugModeError( value ); | ||
} | ||
|
||
if ( value.length === 0 ) { | ||
return 'debug'; | ||
} | ||
|
||
const modes = value.split( ',' ); | ||
modes.forEach( ( userMode ) => { | ||
if ( ! XDEBUG_MODES.some( ( realMode ) => realMode === userMode ) ) { | ||
throwXdebugModeError( userMode ); | ||
} | ||
} ); | ||
return value; | ||
}; | ||
|
||
function throwXdebugModeError( value ) { | ||
throw new Error( | ||
`"${ value }" is not a mode recognized by Xdebug. Valid modes are: ${ XDEBUG_MODES.join( | ||
', ' | ||
) }` | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
const parseXdebugMode = require( '../lib/parse-xdebug-mode' ); | ||
|
||
describe( 'parseXdebugMode', () => { | ||
it( 'throws an error if the passed value is not a string', () => { | ||
expect( () => parseXdebugMode() ).toThrow( | ||
'is not a mode recognized by Xdebug' | ||
); | ||
} ); | ||
|
||
it( 'sets the Xdebug mode to "debug" if no mode is specified', () => { | ||
const result = parseXdebugMode( '' ); | ||
expect( result ).toEqual( 'debug' ); | ||
} ); | ||
|
||
it( 'throws an error if a given mode is not recognized, including the invalid mode in the output', () => { | ||
const fakeMode = 'fake-mode-123'; | ||
expect.assertions( 2 ); | ||
// Single mode: | ||
expect( () => parseXdebugMode( fakeMode ) ).toThrow( fakeMode ); | ||
|
||
// Many modes: | ||
expect( () => | ||
parseXdebugMode( `debug,profile,${ fakeMode }` ) | ||
).toThrow( fakeMode ); | ||
} ); | ||
|
||
it( 'returns all modes passed', () => { | ||
const result = parseXdebugMode( 'debug,profile,trace' ); | ||
expect( result ).toEqual( 'debug,profile,trace' ); | ||
} ); | ||
} ); |