Skip to content

Commit

Permalink
fix(node:process): implement stdout, stderr and stdin with node:tty
Browse files Browse the repository at this point in the history
  • Loading branch information
gpanders committed Jan 8, 2025
1 parent 5d6aec3 commit d1990c2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/runtime/node/process/internal/process.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -191,9 +192,9 @@ export const setMaxListeners = notImplemented<Process["setMaxListeners"]>(
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;
Expand Down
3 changes: 3 additions & 0 deletions src/runtime/node/tty/internal/read-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import type tty from "node:tty";
import { Socket } from "../../net";

export class ReadStream extends Socket implements tty.ReadStream {
constructor(fd: number) {
super();
}
isRaw = false;
setRawMode(mode: boolean) {
this.isRaw = mode;
Expand Down
3 changes: 3 additions & 0 deletions src/runtime/node/tty/internal/write-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import type tty from "node:tty";
import { Socket } from "node:net";

export class WriteStream extends Socket implements tty.WriteStream {
constructor(fd: number) {
super();
}
clearLine(dir: tty.Direction, callback?: (() => void) | undefined) {
callback && callback();
return false;
Expand Down

0 comments on commit d1990c2

Please sign in to comment.