import capcon from 'capture-console' ; export async function captureStdout < T > ( fn , quiet = true ) { let output = '' ; try { capcon . startCapture ( process . stdout , { quiet } , function ( stdout ) { output += stdout ; } ) ; const result = await fn ( ) ; capcon . stopCapture ( process . stdout ) ; return { stdout : output , result } ; } catch ( e ) { console . log ( 'CAUGHT' ) ; capcon . stopCapture ( process . stdout ) ; console . log ( output ) ; console . log ( e ) ; throw e ; } }