Fix issue where command output did not pipe through correctly in the middle of a Stream.

This commit is contained in:
Dillon Kearns 2024-05-02 09:05:40 -07:00
parent f9f066eece
commit e837c9538f
2 changed files with 24 additions and 4 deletions

View File

@ -100,6 +100,23 @@ b =
2
"""
)
, Stream.fromString "module A\na=0"
|> Stream.pipe (Stream.command "elm-format" [ "--stdin" ])
|> Stream.pipe (Stream.fileWrite "formatted-elm.txt")
|> Stream.run
|> BackendTask.quiet
|> BackendTask.andThen
(\() ->
Stream.fileRead "formatted-elm.txt"
|> Stream.read
|> try
)
|> test "write to file"
(\{ metadata, body } ->
body
|> Expect.equal
"module A exposing (a)\n\n\na =\n 0\n"
)
, Stream.fileRead "elm.json"
|> Stream.pipe
(Stream.command "jq"

View File

@ -798,12 +798,17 @@ function runStream(req, portsFile, context) {
const { command, args, allowNon0Status, output } = part;
/** @type {'ignore' | 'inherit'} } */
let letPrint = quiet ? "ignore" : "inherit";
let stderrKind = kind === "none" ? letPrint : "pipe";
let stderrKind = kind === "none" && isLastProcess ? letPrint : "pipe";
if (output === "Ignore") {
stderrKind = "ignore";
} else if (output === "Print") {
stderrKind = letPrint;
}
const stdoutKind =
(output === "InsteadOfStdout" || kind === "none") && isLastProcess
? letPrint
: "pipe";
/**
* @type {import('node:child_process').ChildProcess}
*/
@ -811,9 +816,7 @@ function runStream(req, portsFile, context) {
stdio: [
"pipe",
// if we are capturing stderr instead of stdout, print out stdout with `inherit`
output === "InsteadOfStdout" || kind === "none"
? letPrint
: "pipe",
stdoutKind,
stderrKind,
],
cwd: cwd,