refactor(stdio): always patch stdout and use createWorkingStdio for clean output (#14159)

This commit is contained in:
Allen Hutchison
2025-12-02 15:08:25 -08:00
committed by GitHub
parent 2d935b3798
commit 828afe113e
12 changed files with 31 additions and 24 deletions
+5 -5
View File
@@ -5,7 +5,7 @@
*/
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { patchStdio, createInkStdio } from './stdio.js';
import { patchStdio, createWorkingStdio } from './stdio.js';
import { coreEvents } from './events.js';
vi.mock('./events.js', () => ({
@@ -53,14 +53,14 @@ describe('stdio utils', () => {
expect(process.stderr.write).toBe(originalStderrWrite);
});
it('createInkStdio writes to real stdout/stderr bypassing patch', () => {
it('createWorkingStdio writes to real stdout/stderr bypassing patch', () => {
const cleanup = patchStdio();
const { stdout: inkStdout, stderr: inkStderr } = createInkStdio();
const { stdout, stderr } = createWorkingStdio();
inkStdout.write('ink stdout');
stdout.write('working stdout');
expect(coreEvents.emitOutput).not.toHaveBeenCalled();
inkStderr.write('ink stderr');
stderr.write('working stderr');
expect(coreEvents.emitOutput).not.toHaveBeenCalled();
cleanup();
+2 -2
View File
@@ -80,9 +80,9 @@ export function patchStdio(): () => void {
/**
* Creates proxies for process.stdout and process.stderr that use the real write methods
* (writeToStdout and writeToStderr) bypassing any monkey patching.
* This is used by Ink to render to the real output.
* This is used to write to the real output even when stdio is patched.
*/
export function createInkStdio() {
export function createWorkingStdio() {
const inkStdout = new Proxy(process.stdout, {
get(target, prop, receiver) {
if (prop === 'write') {