File tree Expand file tree Collapse file tree 2 files changed +31
-9
lines changed
Expand file tree Collapse file tree 2 files changed +31
-9
lines changed Original file line number Diff line number Diff line change @@ -83,10 +83,7 @@ export class DdevUtils {
8383 */
8484 public static isToolInstalled ( toolName : string , workspacePath : string ) : boolean {
8585 try {
86- execSync ( `ddev exec ${ toolName } --version` , {
87- cwd : workspacePath ,
88- stdio : 'ignore'
89- } ) ;
86+ this . execDdev ( `${ toolName } --version` , workspacePath ) ;
9087 return true ;
9188 } catch ( error ) {
9289 return false ;
@@ -112,10 +109,7 @@ export class DdevUtils {
112109
113110 // Try to run the tool
114111 try {
115- execSync ( `ddev exec ${ toolName } --version` , {
116- cwd : workspacePath ,
117- stdio : 'ignore'
118- } ) ;
112+ this . execDdev ( `${ toolName } --version` , workspacePath ) ;
119113
120114 return {
121115 isValid : true
@@ -188,7 +182,11 @@ export class DdevUtils {
188182 */
189183 public static execDdev ( command : string , workspacePath : string , allowedExitCodes : number [ ] = [ 0 ] ) : string {
190184 try {
191- return execSync ( `ddev exec ${ command } ` , {
185+ // Wrap command in bash -c to allow setting environment variables (specifically disabling Xdebug)
186+ // This fixes issues where Xdebug causes the command to hang or run slowly
187+ // We use single quotes for the bash command and escape any single quotes in the original command
188+ const escapedCommand = command . replace ( / ' / g, "'\\''" ) ;
189+ return execSync ( `ddev exec bash -c 'XDEBUG_MODE=off ${ escapedCommand } '` , {
192190 cwd : workspacePath ,
193191 encoding : 'utf-8'
194192 } ) ;
Original file line number Diff line number Diff line change @@ -138,4 +138,28 @@ suite('DdevUtils Test Suite', () => {
138138 assert . ok ( result . userMessage ?. includes ( 'phpstan is not installed' ) ) ;
139139 assert . ok ( result . userMessage ?. includes ( 'phpstan/phpstan' ) ) ;
140140 } ) ;
141+
142+ test ( 'execDdev wraps command with XDEBUG_MODE=off' , ( ) => {
143+ execSyncStub . returns ( 'output' ) ;
144+
145+ const result = DdevUtils . execDdev ( 'phpstan analyze' , '/test/workspace' ) ;
146+
147+ assert . strictEqual ( result , 'output' ) ;
148+ assert . strictEqual ( execSyncStub . calledOnce , true ) ;
149+ const callArgs = execSyncStub . firstCall . args ;
150+ assert . ok ( callArgs [ 0 ] . includes ( "XDEBUG_MODE=off" ) ) ;
151+ assert . ok ( callArgs [ 0 ] . includes ( "bash -c" ) ) ;
152+ assert . ok ( callArgs [ 0 ] . includes ( "'XDEBUG_MODE=off phpstan analyze'" ) ) ;
153+ } ) ;
154+
155+ test ( 'execDdev escapes single quotes in command' , ( ) => {
156+ execSyncStub . returns ( 'output' ) ;
157+
158+ const result = DdevUtils . execDdev ( "echo 'hello'" , '/test/workspace' ) ;
159+
160+ assert . strictEqual ( result , 'output' ) ;
161+ const callArgs = execSyncStub . firstCall . args ;
162+ // Should be: ddev exec bash -c 'XDEBUG_MODE=off echo '\''hello'\'''
163+ assert . ok ( callArgs [ 0 ] . includes ( "'XDEBUG_MODE=off echo '\\''hello'\\'''" ) ) ;
164+ } ) ;
141165} ) ;
You can’t perform that action at this time.
0 commit comments