@@ -68,6 +68,22 @@ export type CommandOptions = {
6868export async function runCommandWithTimeout (
6969 argv : string [ ] ,
7070 optionsOrTimeout : number | CommandOptions ,
71+ ) : Promise < SpawnResult > {
72+ return await runCommandWithOutputEncoding ( argv , optionsOrTimeout , false ) ;
73+ }
74+
75+ /** Run a command whose stdout and stderr are defined to be UTF-8 on every platform. */
76+ export async function runUtf8CommandWithTimeout (
77+ argv : string [ ] ,
78+ optionsOrTimeout : number | CommandOptions ,
79+ ) : Promise < SpawnResult > {
80+ return await runCommandWithOutputEncoding ( argv , optionsOrTimeout , true ) ;
81+ }
82+
83+ async function runCommandWithOutputEncoding (
84+ argv : string [ ] ,
85+ optionsOrTimeout : number | CommandOptions ,
86+ forceUtf8 : boolean ,
7187) : Promise < SpawnResult > {
7288 const options : CommandOptions =
7389 typeof optionsOrTimeout === "number" ? { timeoutMs : optionsOrTimeout } : optionsOrTimeout ;
@@ -123,7 +139,7 @@ export async function runCommandWithTimeout(
123139 MAX_PRESERVED_PENDING_LINE_BYTES ,
124140 ) ;
125141 const maxPreservedOutputLines = Math . max ( 0 , Math . floor ( options . maxPreservedOutputLines ?? 16 ) ) ;
126- const windowsEncoding = resolveWindowsConsoleEncoding ( ) ;
142+ const windowsEncoding = forceUtf8 ? null : resolveWindowsConsoleEncoding ( ) ;
127143 const cancelController = new AbortController ( ) ;
128144 let termination : CommandTerminationReason | undefined ;
129145 let childExitState : { code : number | null ; signal : NodeJS . Signals | null } | undefined ;
@@ -447,16 +463,20 @@ export async function runCommandWithTimeout(
447463 }
448464 }
449465
466+ const decodeCapturedOutput = (
467+ capture : CapturedOutputBuffers ,
468+ captureMode : CommandOutputCaptureMode ,
469+ ) : string => {
470+ const buffer = finalizeCapturedOutput ( capture , captureMode , forceUtf8 ) ;
471+ return forceUtf8
472+ ? buffer . toString ( "utf8" )
473+ : decodeWindowsOutputBuffer ( { buffer, windowsEncoding } ) ;
474+ } ;
475+
450476 return {
451477 pid : child . pid ,
452- stdout : decodeWindowsOutputBuffer ( {
453- buffer : finalizeCapturedOutput ( stdoutCapture , stdoutCaptureMode ) ,
454- windowsEncoding,
455- } ) ,
456- stderr : decodeWindowsOutputBuffer ( {
457- buffer : finalizeCapturedOutput ( stderrCapture , stderrCaptureMode ) ,
458- windowsEncoding,
459- } ) ,
478+ stdout : decodeCapturedOutput ( stdoutCapture , stdoutCaptureMode ) ,
479+ stderr : decodeCapturedOutput ( stderrCapture , stderrCaptureMode ) ,
460480 stdoutTruncatedBytes : stdoutCapture . truncatedBytes || undefined ,
461481 stderrTruncatedBytes : stderrCapture . truncatedBytes || undefined ,
462482 preservedStdoutLines :
0 commit comments