From f80cb33a8272f613b838d2cc9405904b193466e4 Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Tue, 7 Jan 2025 16:36:24 -0600 Subject: [PATCH] fix(node:process): implement stdout, stderr and stdin with node:tty --- src/runtime/node/process/internal/process.ts | 7 ++++--- src/runtime/node/tty/internal/read-stream.ts | 5 +++++ src/runtime/node/tty/internal/write-stream.ts | 5 +++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/runtime/node/process/internal/process.ts b/src/runtime/node/process/internal/process.ts index 774a4d0a..9f94f0f2 100644 --- a/src/runtime/node/process/internal/process.ts +++ b/src/runtime/node/process/internal/process.ts @@ -1,5 +1,6 @@ // Source: https://github.com/defunctzombie/node-process/blob/77caa43cdaee4ea710aa14d11cea1705293c0ef3/browser.js import type nodeProcess from "node:process"; +import { ReadStream, WriteStream } from "node:tty"; import mock from "../../../mock/proxy"; import empty from "../../../mock/empty"; import { notImplemented } from "../../../_internal/utils"; @@ -191,9 +192,9 @@ export const setMaxListeners = notImplemented( export const setSourceMapsEnabled = notImplemented< Process["setSourceMapsEnabled"] >("process.setSourceMapsEnabled"); -export const stdout: Process["stdout"] = mock.__createMock__("process.stdout"); -export const stderr: Process["stderr"] = mock.__createMock__("process.stderr"); -export const stdin: Process["stdin"] = mock.__createMock__("process.stdin"); +export const stdin = new ReadStream(0) as Process["stdin"]; +export const stdout = new WriteStream(1) as Process["stdout"]; +export const stderr = new WriteStream(2) as Process["stderr"]; const traceDeprecation: Process["traceDeprecation"] = false; export const uptime: Process["uptime"] = () => 0; export const exitCode: Process["exitCode"] = 0; diff --git a/src/runtime/node/tty/internal/read-stream.ts b/src/runtime/node/tty/internal/read-stream.ts index 4ace7514..65096bc0 100644 --- a/src/runtime/node/tty/internal/read-stream.ts +++ b/src/runtime/node/tty/internal/read-stream.ts @@ -3,6 +3,11 @@ import type tty from "node:tty"; import { Socket } from "../../net"; export class ReadStream extends Socket implements tty.ReadStream { + fd: number; + constructor(fd: number) { + super(); + this.fd = fd; + } isRaw = false; setRawMode(mode: boolean) { this.isRaw = mode; diff --git a/src/runtime/node/tty/internal/write-stream.ts b/src/runtime/node/tty/internal/write-stream.ts index 97fea474..49932601 100644 --- a/src/runtime/node/tty/internal/write-stream.ts +++ b/src/runtime/node/tty/internal/write-stream.ts @@ -2,6 +2,11 @@ import type tty from "node:tty"; import { Socket } from "node:net"; export class WriteStream extends Socket implements tty.WriteStream { + fd: number; + constructor(fd: number) { + super(); + this.fd = fd; + } clearLine(dir: tty.Direction, callback?: (() => void) | undefined) { callback && callback(); return false;