Skip to content

Commit 6b47b3e

Browse files
authored
chore: remove deprecated api process.binding (microsoft#653)
* Remove deprecated API `process.binding` Originally designed to work with ancient node.js 0.12 and io.js * Fix node `net.Socket` limitations nodejs/node#37780
1 parent ced5ea6 commit 6b47b3e

File tree

1 file changed

+4
-18
lines changed

1 file changed

+4
-18
lines changed

src/unixTerminal.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
import * as net from 'net';
77
import * as path from 'path';
8+
import * as tty from 'tty';
89
import { Terminal, DEFAULT_COLS, DEFAULT_ROWS } from './terminal';
910
import { IProcessEnv, IPtyForkOptions, IPtyOpenOptions } from './interfaces';
1011
import { ArgvOrCommandLine } from './types';
@@ -113,7 +114,7 @@ export class UnixTerminal extends Terminal {
113114
// fork
114115
const term = pty.fork(file, args, parsedEnv, cwd, this._cols, this._rows, uid, gid, (encoding === 'utf8'), helperPath, onexit);
115116

116-
this._socket = new PipeSocket(term.fd);
117+
this._socket = new tty.ReadStream(term.fd);
117118
if (encoding !== null) {
118119
this._socket.setEncoding(encoding);
119120
}
@@ -203,13 +204,13 @@ export class UnixTerminal extends Terminal {
203204
// open
204205
const term: IUnixOpenProcess = pty.open(cols, rows);
205206

206-
self._master = new PipeSocket(<number>term.master);
207+
self._master = new tty.ReadStream(term.master);
207208
if (encoding !== null) {
208209
self._master.setEncoding(encoding);
209210
}
210211
self._master.resume();
211212

212-
self._slave = new PipeSocket(term.slave);
213+
self._slave = new tty.ReadStream(term.slave);
213214
if (encoding !== null) {
214215
self._slave.setEncoding(encoding);
215216
}
@@ -304,18 +305,3 @@ export class UnixTerminal extends Terminal {
304305
delete env['LINES'];
305306
}
306307
}
307-
308-
/**
309-
* Wraps net.Socket to force the handle type "PIPE" by temporarily overwriting
310-
* tty_wrap.guessHandleType.
311-
* See: https://github.com/chjj/pty.js/issues/103
312-
*/
313-
class PipeSocket extends net.Socket {
314-
constructor(fd: number) {
315-
const pipeWrap = (<any>process).binding('pipe_wrap'); // tslint:disable-line
316-
// @types/node has fd as string? https://github.com/DefinitelyTyped/DefinitelyTyped/pull/18275
317-
const handle = new pipeWrap.Pipe(pipeWrap.constants.SOCKET);
318-
handle.open(fd);
319-
super(<any>{ handle });
320-
}
321-
}

0 commit comments

Comments
 (0)