Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions packages/build/src/log/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,25 @@ const pushBuildCommandOutput = function (output: string, logsArray: string[]) {
logsArray.push(output)
}

const pipedPluginProcesses = new WeakMap<ChildProcess, ReturnType<typeof pipePluginOutput>>()

// Start plugin step output
export const pipePluginOutput = function (childProcess: ChildProcess, logs: Logs, standardStreams: StandardStreams) {
if (!logsAreBuffered(logs)) {
return streamOutput(childProcess, standardStreams)
export const pipePluginOutput = function (
childProcess: ChildProcess,
logs: Logs,
standardStreams: StandardStreams,
): LogsListeners | undefined {
if (pipedPluginProcesses.has(childProcess)) {
return pipedPluginProcesses.get(childProcess)
}

return pushOutputToLogs(childProcess, logs, standardStreams.outputFlusher)
const listeners = !logsAreBuffered(logs)
? streamOutput(childProcess, standardStreams)
: pushOutputToLogs(childProcess, logs, standardStreams.outputFlusher)

pipedPluginProcesses.set(childProcess, listeners)

return listeners
}

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

unpushOutputToLogs(childProcess, listeners.stdoutListener, listeners.stderrListener)

pipedPluginProcesses.delete(childProcess)
Copy link
Contributor Author

@pieh pieh Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this delete case is not hit if we return early in line 82, which would prevent from re-piping again in that case

}

// Usually, we stream stdout/stderr because it is more efficient
const streamOutput = function (childProcess: ChildProcess, standardStreams: StandardStreams) {
const streamOutput = function (childProcess: ChildProcess, standardStreams: StandardStreams): undefined {
childProcess.stdout?.pipe(standardStreams.stdout)
childProcess.stderr?.pipe(standardStreams.stderr)
}
Expand Down
Loading