@@ -328,70 +328,66 @@ export async function main(argv: string[]): Promise<any> {
328328 if ( ! isMacintosh ) {
329329 // We spawn process.execPath directly
330330 child = spawn ( process . execPath , argv . slice ( 2 ) , options ) ;
331-
332- if ( args . wait && waitMarkerFilePath ) {
333- return new Promise < void > ( resolve => {
334-
335- // Complete when process exits
336- child . once ( 'exit' , ( ) => resolve ( undefined ) ) ;
337-
338- // Complete when wait marker file is deleted
339- whenDeleted ( waitMarkerFilePath ! ) . then ( resolve , resolve ) ;
340- } ) . then ( ( ) => {
341- // Make sure to delete the tmp stdin file if we have any
342- if ( stdinFilePath ) {
343- unlinkSync ( stdinFilePath ) ;
344- }
345- } ) ;
346- }
347331 } else {
348332 // On mac, we spawn using the open command to obtain behavior
349333 // similar to if the app was launched from the dock
350334 // https://github.com/microsoft/vscode/issues/102975
351- const requiresWait = verbose || hasReadStdinArg ;
352335 const openArgs : string [ ] = [ '-n' ] ;
353336
354- let tmpStdoutLogger : CliVerboseLogger | undefined ;
355- let tmpStderrLogger : CliVerboseLogger | undefined ;
356- let tmpStdoutName : string | undefined ;
357- let tmpStderrName : string | undefined ;
358- if ( requiresWait ) {
359- tmpStdoutName = createFileName ( tmpdir ( ) , 'code-stdout' ) ;
360- tmpStderrName = createFileName ( tmpdir ( ) , 'code-stderr' ) ;
361- tmpStdoutLogger = new CliVerboseLogger ( ) ;
362- tmpStderrLogger = new CliVerboseLogger ( ) ;
337+ if ( verbose || hasReadStdinArg || args . wait ) {
338+ openArgs . push ( '-W' ) ;
339+ }
340+
341+ if ( verbose ) {
342+ // Set up arguments to pass to open
343+ const tmpStdoutName = createFileName ( tmpdir ( ) , 'code-stdout' ) ;
344+ const tmpStderrName = createFileName ( tmpdir ( ) , 'code-stderr' ) ;
345+ const tmpStdoutLogger = new CliVerboseLogger ( ) ;
346+ const tmpStderrLogger = new CliVerboseLogger ( ) ;
363347 writeFileSync ( tmpStdoutName , '' ) ;
364348 writeFileSync ( tmpStderrName , '' ) ;
365- openArgs . push ( '-W' ) ;
366349 openArgs . push ( '--stdout' , tmpStdoutName ) ;
367350 openArgs . push ( '--stderr' , tmpStderrName ) ;
351+
352+ function createLoggerPromise ( logger : CliVerboseLogger , filename : string ) : ( child : ChildProcess ) => Promise < void > {
353+ return async ( child : ChildProcess ) => {
354+ await logger . track ( child , filename ) ;
355+ unlinkSync ( filename ) ;
356+ } ;
357+ }
358+ const stdoutPromise = createLoggerPromise ( tmpStdoutLogger ! , tmpStdoutName ! ) ;
359+ const stderrPromise = createLoggerPromise ( tmpStderrLogger ! , tmpStderrName ! ) ;
360+ processCallbacks . push ( stdoutPromise , stderrPromise ) ;
368361 }
369362 const argsArr : string [ ] = [ ] ;
370- const isDev = env [ 'VSCODE_DEV' ] ;
371363 const execPathToUse = process . execPath ;
372364 argsArr . push ( '-a' , execPathToUse ) ;
373365 argsArr . push ( ...openArgs , '--args' , ...argv . slice ( 2 ) ) ;
374- if ( isDev ) {
366+ if ( env [ 'VSCODE_DEV' ] ) {
375367 // If we're in development mode, replace the . arg with the
376368 // vscode source arg. Because the OSS app isn't bundled,
377- // it needs the vscode source arg to launch properly.
369+ // it needs the full vscode source arg to launch properly.
378370 const curdir = '.' ;
379371 const launchDirIndex = argsArr . indexOf ( curdir ) ;
380372 argsArr [ launchDirIndex ] = resolve ( curdir ) ;
381373 }
382374 child = spawn ( 'open' , argsArr , options ) ;
375+ }
383376
384- if ( requiresWait ) {
385- function createLoggerPromise ( logger : CliVerboseLogger , filename : string ) : ( child : ChildProcess ) => Promise < void > {
386- return async ( child : ChildProcess ) => {
387- await logger . track ( child , filename ) ;
388- unlinkSync ( filename ) ;
389- } ;
377+ if ( args . wait && waitMarkerFilePath ) {
378+ const waitPromise = ( child : ChildProcess ) => new Promise < void > ( resolve => {
379+ // Complete when process exits
380+ child . once ( 'exit' , ( ) => resolve ( undefined ) ) ;
381+
382+ // Or, complete when wait marker file is deleted
383+ whenDeleted ( waitMarkerFilePath ! ) . finally ( resolve ) ;
384+ } ) . then ( ( ) => {
385+ // Make sure to delete the tmp stdin file if we have any
386+ if ( stdinFilePath ) {
387+ unlinkSync ( stdinFilePath ) ;
390388 }
391- const stdoutPromise = createLoggerPromise ( tmpStdoutLogger ! , tmpStdoutName ! ) ;
392- const stderrPromise = createLoggerPromise ( tmpStderrLogger ! , tmpStderrName ! ) ;
393- processCallbacks . push ( stdoutPromise , stderrPromise ) ;
394- }
389+ } ) ;
390+ processCallbacks . push ( waitPromise ) ;
395391 }
396392
397393 return Promise . all ( processCallbacks . map ( callback => callback ( child ) ) ) ;
0 commit comments