Skip to content
Myr

shared.js

This file

Path

lib/convert/shared.js

46 lines · 1.3 KiB · JavaScript

Last changed by

Fix `.pipe()` and stream conversion edge casesSindre Sorhusbefore adoptiond3ec10d

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–31why, one step back
1import {finished} from 'node:stream/promises';
2import {isStreamAbort} from '../resolve/wait-stream.js';34export const safeWaitForSubprocessStdin = async subprocessStdin => {5 if (subprocessStdin === undefined) {6 return;7 }89 try {10 await waitForSubprocessStdin(subprocessStdin);11 } catch {}12};1314export const safeWaitForSubprocessStdout = async subprocessStdout => {15 if (subprocessStdout === undefined) {16 return;17 }1819 try {20 await waitForSubprocessStdout(subprocessStdout);21 } catch {}22};2324export const waitForSubprocessStdin = async subprocessStdin => {25 await finished(subprocessStdin, {cleanup: true, readable: false, writable: true});26};2728export const waitForSubprocessStdout = async subprocessStdout => {29 await finished(subprocessStdout, {cleanup: true, readable: true, writable: false});30};31

Fix `.pipe()` and stream conversion edge casesSindre Sorhusbefore adoptiond3ec10d

lines 32–34why, one step back
32// When `readable` or `writable` aborts/errors, the caller awaits the subprocess, for the reason mentioned above.
33// Then, the error passed to `stream.destroy(error)` is emitted, including when the subprocess has already ended.34export const throwDestroyError = error => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 35–46why, one step back
35 if (error) {
36 throw error;37 }38};3940export const destroyOtherStream = (stream, isOpen, error) => {41 if (error && !isStreamAbort(error)) {42 stream.destroy(error);43 } else if (isOpen) {44 stream.destroy();45 }46};