@@ -249,7 +249,7 @@ export async function installApplication(application: Application) {
249249 // If custom install command is specified, run it
250250 if ( application . install ?. command ) {
251251 const [ command , ...args ] = application . install . command . split ( ' ' ) ;
252- const { stderr, code } = await nonInteractiveSpawn (
252+ const { stdout , stderr, code } = await nonInteractiveSpawn (
253253 application . name ,
254254 command ,
255255 args ,
@@ -260,8 +260,13 @@ export async function installApplication(application: Application) {
260260 if ( code === 0 ) {
261261 return ;
262262 }
263- // otherwise, print the stderr output
264- printStderr ( application . name , stderr , 'error' ) ;
263+ if ( stdout ) {
264+ printStd ( application . name , command , stdout , 'stdout' , 'warn' ) ;
265+ }
266+
267+ if ( stderr ) {
268+ printStd ( application . name , command , stderr , 'stderr' , 'warn' ) ;
269+ }
265270 // and throw a descriptive error
266271 throw new Error (
267272 `Failed to install dependencies for ${ application . name } using custom install command: ${ application . install . command } . Exit code: ${ code } `
@@ -300,7 +305,7 @@ export async function installApplication(application: Application) {
300305 // Would result in `pnpm@7` being used as the executable.
301306 // Important note: an `npm` version should not be specifiable; the only valid npm version is the one installed alongside Node.js
302307
303- const { stderr, code } = await nonInteractiveSpawn (
308+ const { stdout , stderr, code } = await nonInteractiveSpawn (
304309 application . name ,
305310 packageManager . name ,
306311 [ 'install' ] , // All of `npm`, `yarn`, and `pnpm` support the `install` command. If we need to configure options here we may have to use some other defaults though
@@ -315,18 +320,30 @@ export async function installApplication(application: Application) {
315320
316321 // Otherwise handle failure case based on `onFail` value
317322 if ( onFail === 'error' ) {
318- // Log the stderr using the error log level (in case the user doesn't have debug level set)
319- printStderr ( packageManager . name , stderr , 'error' ) ;
323+ // Log the std outputs using the error log level (in case the user doesn't have debug level set)
324+ if ( stdout ) {
325+ printStd ( application . name , packageManager . name , stdout , 'stdout' , 'error' ) ;
326+ }
327+
328+ if ( stderr ) {
329+ printStd ( application . name , packageManager . name , stderr , 'stderr' , 'error' ) ;
330+ }
331+
320332 // And throw an error instead of continuing
321333 throw new Error (
322334 `Failed to install dependencies for ${ application . name } using ${ packageManager . name } . Exit code: ${ code } `
323335 ) ;
324336 }
325337
326- // If onFail is 'warn', print out stderr using the warn level, plus an additional message
338+ // If onFail is 'warn', print outputs using the warn level, plus an additional message
327339 if ( onFail === 'warn' ) {
328- // Log the stderr using the warn log level
329- printStderr ( packageManager . name , stderr , 'warn' ) ;
340+ if ( stdout ) {
341+ printStd ( application . name , packageManager . name , stdout , 'stdout' , 'warn' ) ;
342+ }
343+
344+ if ( stderr ) {
345+ printStd ( application . name , packageManager . name , stderr , 'stderr' , 'warn' ) ;
346+ }
330347
331348 application . logger . warn (
332349 `Failed to install dependencies for ${ application . name } using ${ packageManager . name } . Exit code: ${ code } `
@@ -337,7 +354,7 @@ export async function installApplication(application: Application) {
337354 }
338355
339356 // Finally, default to running `npm install`
340- const { stderr, code } = await nonInteractiveSpawn (
357+ const { stdout , stderr, code } = await nonInteractiveSpawn (
341358 application . name ,
342359 'npm' ,
343360 [ 'install' , '--force' ] ,
@@ -349,8 +366,14 @@ export async function installApplication(application: Application) {
349366 return ;
350367 }
351368
352- // Otherwise, print the stderr output
353- printStderr ( application . name , stderr , 'error' ) ;
369+ // Otherwise, print the stdout and stderr outputs
370+ if ( stdout ) {
371+ printStd ( application . name , 'npm' , stdout , 'stdout' , 'warn' ) ;
372+ }
373+
374+ if ( stderr ) {
375+ printStd ( application . name , 'npm' , stderr , 'stderr' , 'error' ) ;
376+ }
354377
355378 // and throw a descriptive error
356379 throw new Error ( `Failed to install dependencies for ${ application . name } using npm default. Exit code: ${ code } ` ) ;
@@ -574,15 +597,15 @@ export function nonInteractiveSpawn(
574597 clearTimeout ( timeout ) ;
575598 // Print out stderr before rejecting
576599 if ( stderr ) {
577- printStderr ( applicationName , command , stderr ) ;
600+ printStd ( applicationName , command , stderr , 'stderr' ) ;
578601 }
579602 reject ( error ) ;
580603 } ) ;
581604
582605 childProcess . on ( 'close' , ( code ) => {
583606 clearTimeout ( timeout ) ;
584607 if ( stderr ) {
585- printStderr ( applicationName , command , stderr ) ;
608+ printStd ( applicationName , command , stderr , 'stderr' ) ;
586609 }
587610 logger . loggerWithTag ( `${ applicationName } :spawn:${ command } ` ) . debug ( `Process exited with code ${ code } ` ) ;
588611 resolve ( {
@@ -606,15 +629,15 @@ export function getEnvBuiltInComponents() {
606629 return builtInComponents ;
607630}
608631
609- function printStderr (
632+ function printStd (
610633 applicationName : string ,
611634 command : string ,
612- stderr : string ,
635+ stdString : string ,
636+ stdStreamLabel : 'stdout' | 'stderr' ,
613637 level : 'debug' | 'warn' | 'error' = 'debug'
614638) {
615- const stderrLogger = logger . loggerWithTag ( `${ applicationName } :spawn:${ command } :stderr` ) ;
616- for ( const line of stderr . split ( '\n' ) ) {
617- // Intentionally using the `debug` loglevel here since many CLIs, and predominantly package managers use stderr to report progress and metadata.
618- stderrLogger [ level ] ( line ) ;
639+ const stdLogger = logger . loggerWithTag ( `${ applicationName } :spawn:${ command } :${ stdStreamLabel } ` ) ;
640+ for ( const line of stdString . split ( '\n' ) ) {
641+ stdLogger [ level ] ( line ) ;
619642 }
620643}
0 commit comments