Socket
Socket
Sign inDemoInstall

node-pty

Package Overview
Dependencies
Maintainers
3
Versions
164
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-pty - npm Package Compare versions

Comparing version 0.7.8 to 0.8.0

src/native.d.ts

0

deps/winpty/misc/EnableExtendedFlags.txt

@@ -0,0 +0,0 @@ Note regarding ENABLE_EXTENDED_FLAGS (2016-05-30)

@@ -0,0 +0,0 @@ ==================================================================

@@ -0,0 +0,0 @@ ==================================

@@ -0,0 +0,0 @@ ==================================

@@ -0,0 +0,0 @@ =======================================

@@ -0,0 +0,0 @@ ==========================================================

@@ -0,0 +0,0 @@ =====================================

@@ -0,0 +0,0 @@ ===========================================================

@@ -0,0 +0,0 @@ The narrowest allowed console window, in pixels, on a conventional (~96dpi)

@@ -0,0 +0,0 @@ As before, avoid odd sizes in favor of even sizes.

@@ -0,0 +0,0 @@ Introduction

@@ -0,0 +0,0 @@ Test programs

@@ -0,0 +0,0 @@ # winpty

@@ -0,0 +0,0 @@ # Version 0.4.3 (2017-05-17)

@@ -5,2 +5,3 @@ "use strict";

* Copyright (c) 2016, Daniel Imms (MIT License).
* Copyright (c) 2018, Microsoft Corporation (MIT License).
*/

@@ -7,0 +8,0 @@ Object.defineProperty(exports, "__esModule", { value: true });

"use strict";
/**
* Copyright (c) 2016, Daniel Imms (MIT License).
* Copyright (c) 2018, Microsoft Corporation (MIT License).
*/
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=interfaces.js.map

11

lib/terminal.js

@@ -5,2 +5,3 @@ "use strict";

* Copyright (c) 2016, Daniel Imms (MIT License).
* Copyright (c) 2018, Microsoft Corporation (MIT License).
*/

@@ -94,12 +95,2 @@ Object.defineProperty(exports, "__esModule", { value: true });

};
// TODO: Should this be in the API?
Terminal.prototype.redraw = function () {
var _this = this;
var cols = this._cols;
var rows = this._rows;
// We could just send SIGWINCH, but most programs will ignore it if the
// size hasn't actually changed.
this.resize(cols + 1, rows + 1);
setTimeout(function () { return _this.resize(cols, rows); }, 30);
};
Terminal.prototype._close = function () {

@@ -106,0 +97,0 @@ this._socket.writable = false;

"use strict";
/**
* Copyright (c) 2017, Daniel Imms (MIT License).
* Copyright (c) 2018, Microsoft Corporation (MIT License).
*/

@@ -5,0 +6,0 @@ Object.defineProperty(exports, "__esModule", { value: true });

"use strict";
/**
* Copyright (c) 2017, Daniel Imms (MIT License).
* Copyright (c) 2018, Microsoft Corporation (MIT License).
*/
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=types.js.map

@@ -5,2 +5,3 @@ "use strict";

* Copyright (c) 2016, Daniel Imms (MIT License).
* Copyright (c) 2018, Microsoft Corporation (MIT License).
*/

@@ -19,6 +20,5 @@ var __extends = (this && this.__extends) || (function () {

var net = require("net");
var path = require("path");
var terminal_1 = require("./terminal");
var utils_1 = require("./utils");
var pty = require(path.join('..', 'build', 'Release', 'pty.node'));
var pty = utils_1.loadNative('pty');
var DEFAULT_FILE = 'sh';

@@ -25,0 +25,0 @@ var DEFAULT_NAME = 'xterm';

"use strict";
/**
* Copyright (c) 2017, Daniel Imms (MIT License).
* Copyright (c) 2018, Microsoft Corporation (MIT License).
*/

@@ -5,0 +6,0 @@ Object.defineProperty(exports, "__esModule", { value: true });

"use strict";
/**
* Copyright (c) 2017, Daniel Imms (MIT License).
* Copyright (c) 2018, Microsoft Corporation (MIT License).
*/
Object.defineProperty(exports, "__esModule", { value: true });
var path = require("path");
function assign(target) {

@@ -15,2 +17,11 @@ var sources = [];

exports.assign = assign;
function loadNative(moduleName) {
try {
return require(path.join('..', 'build', 'Release', moduleName + ".node"));
}
catch (_a) {
return require(path.join('..', 'build', 'Debug', moduleName + ".node"));
}
}
exports.loadNative = loadNative;
//# sourceMappingURL=utils.js.map

@@ -5,17 +5,39 @@ "use strict";

* Copyright (c) 2016, Daniel Imms (MIT License).
* Copyright (c) 2018, Microsoft Corporation (MIT License).
*/
Object.defineProperty(exports, "__esModule", { value: true });
var os = require("os");
var path = require("path");
var net_1 = require("net");
var pty = require(path.join('..', 'build', 'Release', 'pty.node'));
var utils_1 = require("./utils");
var conptyNative;
var winptyNative;
/**
* Agent. Internal class.
*
* Everytime a new pseudo terminal is created it is contained
* within agent.exe. When this process is started there are two
* available named pipes (control and data socket).
* The amount of time to wait for additional data after the conpty shell process has exited before
* shutting down the socket. The timer will be reset if a new data event comes in after the timer
* has started.
*/
var FLUSH_DATA_INTERVAL = 20;
/**
* This agent sits between the WindowsTerminal class and provides a common interface for both conpty
* and winpty.
*/
var WindowsPtyAgent = /** @class */ (function () {
function WindowsPtyAgent(file, args, env, cwd, cols, rows, debug) {
function WindowsPtyAgent(file, args, env, cwd, cols, rows, debug, _useConpty) {
var _this = this;
this._useConpty = _useConpty;
if (this._useConpty === undefined || this._useConpty === true) {
this._useConpty = this._getWindowsBuildNumber() >= 17692;
}
if (this._useConpty) {
if (!conptyNative) {
conptyNative = utils_1.loadNative('conpty');
}
}
else {
if (!winptyNative) {
winptyNative = utils_1.loadNative('pty');
}
}
this._ptyNative = this._useConpty ? conptyNative : winptyNative;
// Sanitize input variable.

@@ -26,7 +48,12 @@ cwd = path.resolve(cwd);

// Open pty session.
var term = pty.startProcess(file, commandLine, env, cwd, cols, rows, debug);
// Terminal pid.
this._pid = term.pid;
this._innerPid = term.innerPid;
this._innerPidHandle = term.innerPidHandle;
var term;
if (this._useConpty) {
term = this._ptyNative.startProcess(file, cols, rows, debug, this._generatePipeName());
}
else {
term = this._ptyNative.startProcess(file, commandLine, env, cwd, cols, rows, debug);
this._pid = term.pid;
this._innerPid = term.innerPid;
this._innerPidHandle = term.innerPidHandle;
}
// Not available on windows.

@@ -49,2 +76,6 @@ this._fd = term.fd;

// TODO: Wait for ready event?
if (this._useConpty) {
var connect = this._ptyNative.connect(this._pty, commandLine, cwd, env, this._$onProcessExit.bind(this));
this._innerPid = connect.pid;
}
}

@@ -77,3 +108,10 @@ Object.defineProperty(WindowsPtyAgent.prototype, "inSocket", {

WindowsPtyAgent.prototype.resize = function (cols, rows) {
pty.resize(this._pid, cols, rows);
if (this._useConpty) {
if (this._exitCode !== undefined) {
throw new Error('Cannot resize a pty that has already exited');
}
this._ptyNative.resize(this._pty, cols, rows);
return;
}
this._ptyNative.resize(this._pid, cols, rows);
};

@@ -85,22 +123,68 @@ WindowsPtyAgent.prototype.kill = function () {

this._outSocket.writable = false;
var processList = pty.getProcessList(this._pid);
// Tell the agent to kill the pty, this releases handles to the process
pty.kill(this._pid, this._innerPidHandle);
// Since pty.kill will kill most processes by itself and process IDs can be
// reused as soon as all handles to them are dropped, we want to immediately
// kill the entire console process list. If we do not force kill all
// processes here, node servers in particular seem to become detached and
// remain running (see Microsoft/vscode#26807).
processList.forEach(function (pid) {
try {
process.kill(pid);
if (this._useConpty) {
this._ptyNative.kill(this._pty);
}
else {
var processList = this._ptyNative.getProcessList(this._pid);
this._ptyNative.kill(this._pid, this._innerPidHandle);
// Since pty.kill will kill most processes by itself and process IDs can be
// reused as soon as all handles to them are dropped, we want to immediately
// kill the entire console process list. If we do not force kill all
// processes here, node servers in particular seem to become detached and
// remain running (see Microsoft/vscode#26807).
processList.forEach(function (pid) {
try {
process.kill(pid);
}
catch (e) {
// Ignore if process cannot be found (kill ESRCH error)
}
});
}
};
Object.defineProperty(WindowsPtyAgent.prototype, "exitCode", {
get: function () {
if (this._useConpty) {
return this._exitCode;
}
catch (e) {
// Ignore if process cannot be found (kill ESRCH error)
}
});
return this._ptyNative.getExitCode(this._innerPidHandle);
},
enumerable: true,
configurable: true
});
WindowsPtyAgent.prototype._getWindowsBuildNumber = function () {
var osVersion = (/(\d+)\.(\d+)\.(\d+)/g).exec(os.release());
var buildNumber = 0;
if (osVersion && osVersion.length === 4) {
buildNumber = parseInt(osVersion[3]);
}
return buildNumber;
};
WindowsPtyAgent.prototype.getExitCode = function () {
return pty.getExitCode(this._innerPidHandle);
WindowsPtyAgent.prototype._generatePipeName = function () {
return "conpty-" + Math.random() * 10000000;
};
/**
* Triggered from the native side when a contpy process exits.
*/
WindowsPtyAgent.prototype._$onProcessExit = function (exitCode) {
var _this = this;
this._exitCode = exitCode;
this._flushDataAndCleanUp();
this._outSocket.on('data', function () { return _this._flushDataAndCleanUp(); });
};
WindowsPtyAgent.prototype._flushDataAndCleanUp = function () {
var _this = this;
if (this._closeTimeout) {
clearTimeout(this._closeTimeout);
}
this._closeTimeout = setTimeout(function () { return _this._cleanUpProcess(); }, FLUSH_DATA_INTERVAL);
};
WindowsPtyAgent.prototype._cleanUpProcess = function () {
this._inSocket.readable = false;
this._inSocket.writable = false;
this._outSocket.readable = false;
this._outSocket.writable = false;
this._outSocket.destroy();
};
return WindowsPtyAgent;

@@ -107,0 +191,0 @@ }());

"use strict";
/**
* Copyright (c) 2017, Daniel Imms (MIT License).
* Copyright (c) 2018, Microsoft Corporation (MIT License).
*/

@@ -5,0 +6,0 @@ Object.defineProperty(exports, "__esModule", { value: true });

@@ -5,2 +5,3 @@ "use strict";

* Copyright (c) 2016, Daniel Imms (MIT License).
* Copyright (c) 2018, Microsoft Corporation (MIT License).
*/

@@ -46,3 +47,3 @@ var __extends = (this && this.__extends) || (function () {

// Create new termal.
_this._agent = new windowsPtyAgent_1.WindowsPtyAgent(file, args, parsedEnv, cwd, cols, rows, false);
_this._agent = new windowsPtyAgent_1.WindowsPtyAgent(file, args, parsedEnv, cwd, cols, rows, false, opt.experimentalUseConpty);
_this._socket = _this._agent.outSocket;

@@ -58,3 +59,3 @@ // Not available until `ready` event emitted.

['connect', 'data', 'end', 'timeout', 'drain'].forEach(function (event) {
_this._socket.on(event, function (data) {
_this._socket.on(event, function () {
// Wait until the first data event is fired then we can run deferreds.

@@ -97,3 +98,3 @@ if (!_this._isReady && event === 'data') {

_this._socket.on('close', function () {
_this.emit('exit', _this._agent.getExitCode());
_this.emit('exit', _this._agent.exitCode);
_this._close();

@@ -100,0 +101,0 @@ });

"use strict";
/**
* Copyright (c) 2017, Daniel Imms (MIT License).
* Copyright (c) 2018, Microsoft Corporation (MIT License).
*/

@@ -30,5 +31,7 @@ Object.defineProperty(exports, "__esModule", { value: true });

term._defer(function () {
term.on('exit', function () {
assert.throws(function () { return term.resize(1, 1); });
done();
});
term.destroy();
assert.throws(function () { return term.resize(1, 1); });
done();
});

@@ -61,2 +64,15 @@ });

});
describe('env', function () {
it('should set environment variables of the shell', function (done) {
var term = new windowsTerminal_1.WindowsTerminal('cmd.exe', '/C echo %FOO%', { env: { FOO: 'BAR' } });
var result = '';
term.on('data', function (data) {
result += data;
});
term.on('exit', function () {
assert.ok(result.indexOf('BAR') >= 0);
done();
});
});
});
describe('On close', function () {

@@ -63,0 +79,0 @@ it('should return process zero exit codes', function (done) {

@@ -5,5 +5,5 @@ {

"author": {
"name": "Daniel Imms"
"name": "Microsoft Corporation"
},
"version": "0.7.8",
"version": "0.8.0",
"license": "MIT",

@@ -10,0 +10,0 @@ "main": "./lib/index.js",

# node-pty
[![Build status](https://tyriar.visualstudio.com/_apis/public/build/definitions/2d361770-e039-4acc-b2b2-ef8396473589/1/badge)](https://tyriar.visualstudio.com/node-pty/_build/index?definitionId=1)
[![Build Status](https://dev.azure.com/vscode/node-pty/_apis/build/status/Microsoft.node-pty)](https://dev.azure.com/vscode/node-pty/_apis/build/status/Microsoft.node-pty?branchName=master)

@@ -12,3 +12,3 @@ `forkpty(3)` bindings for node.js. This allows you to fork processes with pseudoterminal file descriptors. It returns a terminal object which allows reads and writes.

`node-pty` supports Linux, macOS and Windows. Windows support is possible by utilizing the [winpty](https://github.com/rprichard/winpty) library.
`node-pty` supports Linux, macOS and Windows. Windows support is possible by utilizing the [Windows conpty API](https://blogs.msdn.microsoft.com/commandline/2018/08/02/windows-command-line-introducing-the-windows-pseudo-console-conpty/) on Windows 1809+ and the [winpty](https://github.com/rprichard/winpty) library in older version.

@@ -63,4 +63,12 @@ ## Real-world Uses

### Dependencies on Windows
## Dependencies
### Linux/Ubuntu
```
sudo apt install -y make python build-essential
```
### Windows
`npm install` requires some tools to be present in the system like Python and C++ compiler. Windows users can easily install them by running the following command in PowerShell as administrator. For more information see https://github.com/felixrieseberg/windows-build-tools:

@@ -72,2 +80,4 @@

The Windows SDK is also needed which can be [downloaded here](https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk). Only the "Desktop C++ Apps" components are needed to be installed.
## Debugging

@@ -81,2 +91,6 @@

## Thread Safety
Note that node-pty is not thread safe so running it across multiple worker threads in node.js could cause issues.
## Troubleshooting

@@ -97,2 +111,3 @@

Copyright (c) 2012-2015, Christopher Jeffrey (MIT License).<br>
Copyright (c) 2016, Daniel Imms (MIT License).
Copyright (c) 2016, Daniel Imms (MIT License).<br>
Copyright (c) 2018, Microsoft Corporation (MIT License).

@@ -7,3 +7,7 @@ 'use strict'

const p = spawn(os.platform() === 'win32' ? 'node-gyp.cmd' : 'node-gyp', ['rebuild'], {
const args = ['rebuild'];
if (process.env.NODE_PTY_DEBUG) {
args.push('--debug');
}
const p = spawn(os.platform() === 'win32' ? 'node-gyp.cmd' : 'node-gyp', args, {
cwd: path.join(__dirname, '..'),

@@ -10,0 +14,0 @@ stdio: 'inherit'

@@ -6,2 +6,4 @@ var fs = require('fs');

var BUILD_FILES = [
path.join(RELEASE_DIR, 'conpty.node'),
path.join(RELEASE_DIR, 'conpty.pdb'),
path.join(RELEASE_DIR, 'pty.node'),

@@ -8,0 +10,0 @@ path.join(RELEASE_DIR, 'pty.pdb'),

/**
* Copyright (c) 2012-2015, Christopher Jeffrey, Peter Sunde (MIT License)
* Copyright (c) 2016, Daniel Imms (MIT License).
* Copyright (c) 2018, Microsoft Corporation (MIT License).
*/

@@ -5,0 +6,0 @@

/**
* Copyright (c) 2016, Daniel Imms (MIT License).
* Copyright (c) 2018, Microsoft Corporation (MIT License).
*/

@@ -118,2 +119,3 @@

encoding?: string;
experimentalUseConpty?: boolean | undefined;
}

@@ -120,0 +122,0 @@

/**
* Copyright (c) 2017, Daniel Imms (MIT License).
* Copyright (c) 2018, Microsoft Corporation (MIT License).
*/

@@ -4,0 +5,0 @@

/**
* Copyright (c) 2012-2015, Christopher Jeffrey (MIT License)
* Copyright (c) 2016, Daniel Imms (MIT License).
* Copyright (c) 2018, Microsoft Corporation (MIT License).
*/

@@ -129,15 +130,2 @@

// TODO: Should this be in the API?
public redraw(): void {
let cols = this._cols;
let rows = this._rows;
// We could just send SIGWINCH, but most programs will ignore it if the
// size hasn't actually changed.
this.resize(cols + 1, rows + 1);
setTimeout(() => this.resize(cols, rows), 30);
}
protected _close(): void {

@@ -144,0 +132,0 @@ this._socket.writable = false;

/**
* Copyright (c) 2017, Daniel Imms (MIT License).
* Copyright (c) 2018, Microsoft Corporation (MIT License).
*/
export type ArgvOrCommandLine = string[] | string;
/**
* Copyright (c) 2017, Daniel Imms (MIT License).
* Copyright (c) 2018, Microsoft Corporation (MIT License).
*/

@@ -4,0 +5,0 @@

/**
* Copyright (c) 2012-2015, Christopher Jeffrey (MIT License)
* Copyright (c) 2016, Daniel Imms (MIT License).
* Copyright (c) 2018, Microsoft Corporation (MIT License).
*/
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';
import { assign } from './utils';
import { assign, loadNative } from './utils';
declare interface INativePty {
master: number;
slave: number;
pty: string;
}
const pty: IUnixNative = loadNative('pty');
const pty = require(path.join('..', 'build', 'Release', 'pty.node'));
const DEFAULT_FILE = 'sh';

@@ -182,3 +175,3 @@ const DEFAULT_NAME = 'xterm';

// open
const term: INativePty = pty.open(cols, rows);
const term: IUnixOpenProcess = pty.open(cols, rows);

@@ -185,0 +178,0 @@ self._master = new PipeSocket(<number>term.master);

/**
* Copyright (c) 2017, Daniel Imms (MIT License).
* Copyright (c) 2018, Microsoft Corporation (MIT License).
*/
import * as path from 'path';
export function assign(target: any, ...sources: any[]): any {

@@ -9,1 +12,9 @@ sources.forEach(source => Object.keys(source).forEach(key => target[key] = source[key]));

}
export function loadNative(moduleName: string): any {
try {
return require(path.join('..', 'build', 'Release', `${moduleName}.node`));
} catch {
return require(path.join('..', 'build', 'Debug', `${moduleName}.node`));
}
}
/**
* Copyright (c) 2017, Daniel Imms (MIT License).
* Copyright (c) 2018, Microsoft Corporation (MIT License).
*/

@@ -4,0 +5,0 @@

/**
* Copyright (c) 2012-2015, Christopher Jeffrey, Peter Sunde (MIT License)
* Copyright (c) 2016, Daniel Imms (MIT License).
* Copyright (c) 2018, Microsoft Corporation (MIT License).
*/
import * as os from 'os';
import * as path from 'path';
import { Socket } from 'net';
import { ArgvOrCommandLine } from './types';
import { loadNative } from './utils';
const pty = require(path.join('..', 'build', 'Release', 'pty.node'));
let conptyNative: IConptyNative;
let winptyNative: IWinptyNative;
/**
* Agent. Internal class.
*
* Everytime a new pseudo terminal is created it is contained
* within agent.exe. When this process is started there are two
* available named pipes (control and data socket).
* The amount of time to wait for additional data after the conpty shell process has exited before
* shutting down the socket. The timer will be reset if a new data event comes in after the timer
* has started.
*/
const FLUSH_DATA_INTERVAL = 20;
/**
* This agent sits between the WindowsTerminal class and provides a common interface for both conpty
* and winpty.
*/
export class WindowsPtyAgent {

@@ -26,5 +33,8 @@ private _inSocket: Socket;

private _innerPidHandle: number;
private _closeTimeout: NodeJS.Timer;
private _exitCode: number | undefined;
private _fd: any;
private _pty: number;
private _ptyNative: IConptyNative | IWinptyNative;

@@ -44,4 +54,19 @@ public get inSocket(): Socket { return this._inSocket; }

rows: number,
debug: boolean
debug: boolean,
private _useConpty: boolean | undefined
) {
if (this._useConpty === undefined || this._useConpty === true) {
this._useConpty = this._getWindowsBuildNumber() >= 17692;
}
if (this._useConpty) {
if (!conptyNative) {
conptyNative = loadNative('conpty');
}
} else {
if (!winptyNative) {
winptyNative = loadNative('pty');
}
}
this._ptyNative = this._useConpty ? conptyNative : winptyNative;
// Sanitize input variable.

@@ -54,9 +79,12 @@ cwd = path.resolve(cwd);

// Open pty session.
const term = pty.startProcess(file, commandLine, env, cwd, cols, rows, debug);
let term: IConptyProcess | IWinptyProcess;
if (this._useConpty) {
term = (this._ptyNative as IConptyNative).startProcess(file, cols, rows, debug, this._generatePipeName());
} else {
term = (this._ptyNative as IWinptyNative).startProcess(file, commandLine, env, cwd, cols, rows, debug);
this._pid = (term as IWinptyProcess).pid;
this._innerPid = (term as IWinptyProcess).innerPid;
this._innerPidHandle = (term as IWinptyProcess).innerPidHandle;
}
// Terminal pid.
this._pid = term.pid;
this._innerPid = term.innerPid;
this._innerPidHandle = term.innerPidHandle;
// Not available on windows.

@@ -83,6 +111,18 @@ this._fd = term.fd;

// TODO: Wait for ready event?
if (this._useConpty) {
const connect = (this._ptyNative as IConptyNative).connect(this._pty, commandLine, cwd, env, this._$onProcessExit.bind(this));
this._innerPid = connect.pid;
}
}
public resize(cols: number, rows: number): void {
pty.resize(this._pid, cols, rows);
if (this._useConpty) {
if (this._exitCode !== undefined) {
throw new Error('Cannot resize a pty that has already exited');
}
this._ptyNative.resize(this._pty, cols, rows);
return;
}
this._ptyNative.resize(this._pid, cols, rows);
}

@@ -95,22 +135,66 @@

this._outSocket.writable = false;
const processList: number[] = pty.getProcessList(this._pid);
// Tell the agent to kill the pty, this releases handles to the process
pty.kill(this._pid, this._innerPidHandle);
// Since pty.kill will kill most processes by itself and process IDs can be
// reused as soon as all handles to them are dropped, we want to immediately
// kill the entire console process list. If we do not force kill all
// processes here, node servers in particular seem to become detached and
// remain running (see Microsoft/vscode#26807).
processList.forEach(pid => {
try {
process.kill(pid);
} catch (e) {
// Ignore if process cannot be found (kill ESRCH error)
}
});
if (this._useConpty) {
(this._ptyNative as IConptyNative).kill(this._pty);
} else {
const processList: number[] = (this._ptyNative as IWinptyNative).getProcessList(this._pid);
(this._ptyNative as IWinptyNative).kill(this._pid, this._innerPidHandle);
// Since pty.kill will kill most processes by itself and process IDs can be
// reused as soon as all handles to them are dropped, we want to immediately
// kill the entire console process list. If we do not force kill all
// processes here, node servers in particular seem to become detached and
// remain running (see Microsoft/vscode#26807).
processList.forEach(pid => {
try {
process.kill(pid);
} catch (e) {
// Ignore if process cannot be found (kill ESRCH error)
}
});
}
}
public getExitCode(): number {
return pty.getExitCode(this._innerPidHandle);
public get exitCode(): number {
if (this._useConpty) {
return this._exitCode;
}
return (this._ptyNative as IWinptyNative).getExitCode(this._innerPidHandle);
}
private _getWindowsBuildNumber(): number {
const osVersion = (/(\d+)\.(\d+)\.(\d+)/g).exec(os.release());
let buildNumber: number = 0;
if (osVersion && osVersion.length === 4) {
buildNumber = parseInt(osVersion[3]);
}
return buildNumber;
}
private _generatePipeName(): string {
return `conpty-${Math.random() * 10000000}`;
}
/**
* Triggered from the native side when a contpy process exits.
*/
private _$onProcessExit(exitCode: number): void {
this._exitCode = exitCode;
this._flushDataAndCleanUp();
this._outSocket.on('data', () => this._flushDataAndCleanUp());
}
private _flushDataAndCleanUp(): void {
if (this._closeTimeout) {
clearTimeout(this._closeTimeout);
}
this._closeTimeout = setTimeout(() => this._cleanUpProcess(), FLUSH_DATA_INTERVAL);
}
private _cleanUpProcess(): void {
this._inSocket.readable = false;
this._inSocket.writable = false;
this._outSocket.readable = false;
this._outSocket.writable = false;
this._outSocket.destroy();
}
}

@@ -117,0 +201,0 @@

/**
* Copyright (c) 2017, Daniel Imms (MIT License).
* Copyright (c) 2018, Microsoft Corporation (MIT License).
*/

@@ -31,5 +32,7 @@

(<any>term)._defer(() => {
term.on('exit', () => {
assert.throws(() => term.resize(1, 1));
done();
});
term.destroy();
assert.throws(() => term.resize(1, 1));
done();
});

@@ -66,2 +69,16 @@ });

describe('env', () => {
it('should set environment variables of the shell', (done) => {
const term = new WindowsTerminal('cmd.exe', '/C echo %FOO%', { env: { FOO: 'BAR' }});
let result = '';
term.on('data', (data) => {
result += data;
});
term.on('exit', () => {
assert.ok(result.indexOf('BAR') >= 0);
done();
});
});
});
describe('On close', () => {

@@ -68,0 +85,0 @@ it('should return process zero exit codes', (done) => {

/**
* Copyright (c) 2012-2015, Christopher Jeffrey, Peter Sunde (MIT License)
* Copyright (c) 2016, Daniel Imms (MIT License).
* Copyright (c) 2018, Microsoft Corporation (MIT License).
*/
import * as path from 'path';
import { Socket } from 'net';
import { inherits } from 'util';
import { Terminal, DEFAULT_COLS, DEFAULT_ROWS } from './terminal';

@@ -50,3 +49,3 @@ import { WindowsPtyAgent } from './windowsPtyAgent';

// Create new termal.
this._agent = new WindowsPtyAgent(file, args, parsedEnv, cwd, cols, rows, false);
this._agent = new WindowsPtyAgent(file, args, parsedEnv, cwd, cols, rows, false, opt.experimentalUseConpty);
this._socket = this._agent.outSocket;

@@ -65,3 +64,3 @@

['connect', 'data', 'end', 'timeout', 'drain'].forEach(event => {
this._socket.on(event, data => {
this._socket.on(event, () => {

@@ -112,3 +111,3 @@ // Wait until the first data event is fired then we can run deferreds.

this._socket.on('close', () => {
this.emit('exit', this._agent.getExitCode());
this.emit('exit', this._agent.exitCode);
this._close();

@@ -115,0 +114,0 @@ });

/**
* Copyright (c) 2017, Daniel Imms (MIT License).
* Copyright (c) 2018, Microsoft Corporation (MIT License).
*/

@@ -28,2 +29,9 @@

encoding?: string;
/**
* Whether to use the experimental ConPTY system on Windows. When this is not set, ConPTY will
* be used when the Windows build number is >= 17692.
*
* This setting does nothing on non-Windows.
*/
experimentalUseConpty?: boolean;
}

@@ -30,0 +38,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc