Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove deprecated api process.binding #653

Merged
merged 2 commits into from
Mar 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 4 additions & 18 deletions src/unixTerminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -203,13 +204,13 @@ export class UnixTerminal extends Terminal {
// open
const term: IUnixOpenProcess = pty.open(cols, rows);

self._master = new PipeSocket(<number>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);
}
Expand Down Expand Up @@ -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 = (<any>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(<any>{ handle });
}
}
Loading