Skip to content

Commit 08dad8d

Browse files
authored
fix: don't pipe plugin output more than once at the time (#6765)
1 parent d06afd6 commit 08dad8d

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

packages/build/src/log/stream.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,25 @@ const pushBuildCommandOutput = function (output: string, logsArray: string[]) {
4747
logsArray.push(output)
4848
}
4949

50+
const pipedPluginProcesses = new WeakMap<ChildProcess, ReturnType<typeof pipePluginOutput>>()
51+
5052
// Start plugin step output
51-
export const pipePluginOutput = function (childProcess: ChildProcess, logs: Logs, standardStreams: StandardStreams) {
52-
if (!logsAreBuffered(logs)) {
53-
return streamOutput(childProcess, standardStreams)
53+
export const pipePluginOutput = function (
54+
childProcess: ChildProcess,
55+
logs: Logs,
56+
standardStreams: StandardStreams,
57+
): LogsListeners | undefined {
58+
if (pipedPluginProcesses.has(childProcess)) {
59+
return pipedPluginProcesses.get(childProcess)
5460
}
5561

56-
return pushOutputToLogs(childProcess, logs, standardStreams.outputFlusher)
62+
const listeners = !logsAreBuffered(logs)
63+
? streamOutput(childProcess, standardStreams)
64+
: pushOutputToLogs(childProcess, logs, standardStreams.outputFlusher)
65+
66+
pipedPluginProcesses.set(childProcess, listeners)
67+
68+
return listeners
5769
}
5870

5971
// Stop streaming/buffering plugin step output
@@ -71,10 +83,12 @@ export const unpipePluginOutput = async function (
7183
}
7284

7385
unpushOutputToLogs(childProcess, listeners.stdoutListener, listeners.stderrListener)
86+
87+
pipedPluginProcesses.delete(childProcess)
7488
}
7589

7690
// Usually, we stream stdout/stderr because it is more efficient
77-
const streamOutput = function (childProcess: ChildProcess, standardStreams: StandardStreams) {
91+
const streamOutput = function (childProcess: ChildProcess, standardStreams: StandardStreams): undefined {
7892
childProcess.stdout?.pipe(standardStreams.stdout)
7993
childProcess.stderr?.pipe(standardStreams.stderr)
8094
}

0 commit comments

Comments
 (0)