Skip to content
Myr

output.js

This file

Path

lib/verbose/output.js

62 lines · 2.9 KiB · JavaScript

Last changed by

TweaksSindre Sorhusbefore adoption698a1b8

History of this file

Take it

The walk stopped after 200 commits: lines older than 9f65b86 point at it.

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 1–2why, one step back
1import {BINARY_ENCODINGS} from '../arguments/encoding-option.js';
2import {TRANSFORM_TYPES} from '../stdio/type.js';

Fix `result.all` and `subprocess.all` when only some file descriptors are bufferedSindre Sorhusbefore adoption758768f

line 3why, one step back
3import {isAllStream} from '../utils/standard-stream.js';

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

lines 4–5why, one step back
4import {verboseLog, serializeVerboseMessage} from './log.js';
5import {isFullVerbose} from './values.js';

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 6–11why, one step back
6
7// `ignore` opts-out of `verbose` for a specific stream.8// `ipc` cannot use piping.9// `inherit` would result in double printing.10// They can also lead to double printing when passing file descriptor integers or `process.std*`.11// This only leaves with `pipe` and `overlapped`.

Refactor `verbose` logic (#1126)ehmickybefore adoptionf9f1199

lines 12–13why, one step back
12export const shouldLogOutput = ({stdioItems, encoding, verboseInfo, fdNumber}) => fdNumber !== 'all'
13 && isFullVerbose(verboseInfo, fdNumber)

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 14why, one step back
14 && !BINARY_ENCODINGS.has(encoding)

Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d

line 15why, one step back
15 && isFdVerbose(fdNumber)

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 16why, one step back
16 && (stdioItems.some(({type, value}) => type === 'native' && PIPED_STDIO_VALUES.has(value))

Require Node.js 22 (#1243)Sindre Sorhusbefore adoption04b4454

line 17why, one step back
17 || stdioItems.every(({type}) => TRANSFORM_TYPES.has(type)));

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 18–22why, one step back
18
19// Printing input streams would be confusing.20// Files and streams can produce big outputs, which we don't want to print.21// We could print `stdio[3+]` but it often is redirected to files and streams, with the same issue.22// So we only print stdout and stderr.

Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d

line 23why, one step back
23const isFdVerbose = fdNumber => fdNumber === 1 || fdNumber === 2;

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 24–26why, one step back
24
25const PIPED_STDIO_VALUES = new Set(['pipe', 'overlapped']);26

Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe

line 27why, one step back
27// `verbose: 'full'` printing logic with async methods

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

line 28why, one step back
28export const logLines = async (linesIterable, stream, fdNumber, verboseInfo) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 29–30why, one step back
29 for await (const line of linesIterable) {
30 if (!isPipingStream(stream)) {

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

line 31why, one step back
31 logLine(line, fdNumber, verboseInfo);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 32–35why, one step back
32 }
33 }34};35

Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe

line 36why, one step back
36// `verbose: 'full'` printing logic with sync methods

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

line 37why, one step back
37export const logLinesSync = (linesArray, fdNumber, verboseInfo) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 38why, one step back
38 for (const line of linesArray) {

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

line 39why, one step back
39 logLine(line, fdNumber, verboseInfo);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 40–48why, one step back
40 }
41};4243// When `subprocess.stdout|stderr.pipe()` is called, `verbose` becomes a noop.44// This prevents the following problems:45// - `.pipe()` achieves the same result as using `stdout: 'inherit'`, `stdout: stream`, etc. which also make `verbose` a noop.46// For example, `subprocess.stdout.pipe(process.stdin)` would print each line twice.47// - When chaining subprocesses with `subprocess.pipe(otherSubprocess)`, only the last one should print its output.48// Detecting whether `.pipe()` is impossible without monkey-patching it, so we use the following undocumented property.

TweaksSindre Sorhusbefore adoption698a1b8

line 49why, one step back
49// The pipe into `subprocess.all` is done by Execa itself, so it only counts when `subprocess.all` is itself piped, e.g. `subprocess.all.pipe(process.stdout)`.

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 50why, one step back
50// This is not a critical behavior since changes of the following property would only make `verbose` more verbose.

TweaksSindre Sorhusbefore adoption698a1b8

line 51why, one step back
51const isPipingStream = stream => stream._readableState.pipes.some(pipe => !isAllStream(pipe) || isPipingStream(pipe));

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 52–53why, one step back
52
53// When `verbose` is `full`, print stdout|stderr

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

lines 54–55why, one step back
54const logLine = (line, fdNumber, verboseInfo) => {
55 const verboseMessage = serializeVerboseMessage(line);

Refactor `verbose` logic (#1126)ehmickybefore adoptionf9f1199

lines 56–57why, one step back
56 verboseLog({
57 type: 'output',

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

lines 58–59why, one step back
58 verboseMessage,
59 fdNumber,

Refactor `verbose` logic (#1126)ehmickybefore adoptionf9f1199

lines 60–61why, one step back
60 verboseInfo,
61 });

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 62why, one step back
62};