Skip to content

Commit

Permalink
only do process.stderr.write on a Windows TTY stream
Browse files Browse the repository at this point in the history
  • Loading branch information
IIIMADDINIII committed Oct 27, 2024
1 parent 9e27845 commit 735392c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/verbose/log.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import process from 'node:process';
import {writeFileSync} from 'node:fs';
import {inspect} from 'node:util';
import {escapeLines} from '../arguments/escape.js';
import {defaultVerboseFunction} from './default.js';
Expand All @@ -9,7 +10,14 @@ export const verboseLog = ({type, verboseMessage, fdNumber, verboseInfo, result}
const verboseObject = getVerboseObject({type, result, verboseInfo});
const printedLines = getPrintedLines(verboseMessage, verboseObject);
const finalLines = applyVerboseOnLines(printedLines, verboseInfo, fdNumber);
process.stderr.write(finalLines);
// On Windows when stdout is pointing to a terminal writeFileSync causes problems with multibyte Characters not displaying correctly
// When stderr is pointing to console, the write command is allway behaving synchronously
if (process.platform === 'win32' && process.stderr.isTTY) {
process.stderr.write(finalLines);
return;
}

Check warning on line 18 in lib/verbose/log.js

View check run for this annotation

Codecov / codecov/patch

lib/verbose/log.js#L16-L18

Added lines #L16 - L18 were not covered by tests

writeFileSync(STDERR_FD, finalLines);
};

const getVerboseObject = ({
Expand All @@ -35,6 +43,9 @@ const getPrintedLine = verboseObject => {
return {verboseLine, verboseObject};
};

// Unless a `verbose` function is used, print all logs on `stderr`
const STDERR_FD = 2;

// Serialize any type to a line string, for logging
export const serializeVerboseMessage = message => {
const messageString = typeof message === 'string' ? message : inspect(message);
Expand Down

0 comments on commit 735392c

Please sign in to comment.