From 391347926a45bb0b9e2c9a9f837adc56592b3c4b Mon Sep 17 00:00:00 2001 From: kkocdko <31189892+kkocdko@users.noreply.github.com> Date: Mon, 18 Mar 2024 21:01:50 +0800 Subject: [PATCH] chore: remove deprecated api `process.binding` (#653) * Remove deprecated API `process.binding` Originally designed to work with ancient node.js 0.12 and io.js * Fix node `net.Socket` limitations https://github.com/nodejs/node/issues/37780 --- src/unixTerminal.ts | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/src/unixTerminal.ts b/src/unixTerminal.ts index 9f8207ef1..b745d762d 100644 --- a/src/unixTerminal.ts +++ b/src/unixTerminal.ts @@ -5,6 +5,7 @@ */ import * as net from 'net'; import * as path from 'path'; +import * as tty from 'tty'; import { Terminal, DEFAULT_COLS, DEFAULT_ROWS } from './terminal'; import { IProcessEnv, IPtyForkOptions, IPtyOpenOptions } from './interfaces'; import { ArgvOrCommandLine } from './types'; @@ -113,7 +114,7 @@ export class UnixTerminal extends Terminal { // fork const term = pty.fork(file, args, parsedEnv, cwd, this._cols, this._rows, uid, gid, (encoding === 'utf8'), helperPath, onexit); - this._socket = new PipeSocket(term.fd); + this._socket = new tty.ReadStream(term.fd); if (encoding !== null) { this._socket.setEncoding(encoding); } @@ -203,13 +204,13 @@ export class UnixTerminal extends Terminal { // open const term: IUnixOpenProcess = pty.open(cols, rows); - self._master = new PipeSocket(term.master); + self._master = new tty.ReadStream(term.master); if (encoding !== null) { self._master.setEncoding(encoding); } self._master.resume(); - self._slave = new PipeSocket(term.slave); + self._slave = new tty.ReadStream(term.slave); if (encoding !== null) { self._slave.setEncoding(encoding); } @@ -304,18 +305,3 @@ export class UnixTerminal extends Terminal { delete env['LINES']; } } - -/** - * Wraps net.Socket to force the handle type "PIPE" by temporarily overwriting - * tty_wrap.guessHandleType. - * See: https://github.com/chjj/pty.js/issues/103 - */ -class PipeSocket extends net.Socket { - constructor(fd: number) { - const pipeWrap = (process).binding('pipe_wrap'); // tslint:disable-line - // @types/node has fd as string? https://github.com/DefinitelyTyped/DefinitelyTyped/pull/18275 - const handle = new pipeWrap.Pipe(pipeWrap.constants.SOCKET); - handle.open(fd); - super({ handle }); - } -}