codeam-cli 2.4.30 → 2.4.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/dist/index.js +120 -85
- package/dist/vendor/node-pty/lib/conpty_console_list_agent.js +16 -0
- package/dist/vendor/node-pty/lib/eventEmitter2.js +47 -0
- package/dist/vendor/node-pty/lib/index.js +52 -0
- package/dist/vendor/node-pty/lib/interfaces.js +7 -0
- package/dist/vendor/node-pty/lib/shared/conout.js +11 -0
- package/dist/vendor/node-pty/lib/terminal.js +190 -0
- package/dist/vendor/node-pty/lib/types.js +7 -0
- package/dist/vendor/node-pty/lib/unixTerminal.js +346 -0
- package/dist/vendor/node-pty/lib/utils.js +39 -0
- package/dist/vendor/node-pty/lib/windowsConoutConnection.js +125 -0
- package/dist/vendor/node-pty/lib/windowsPtyAgent.js +320 -0
- package/dist/vendor/node-pty/lib/windowsTerminal.js +199 -0
- package/dist/vendor/node-pty/lib/worker/conoutSocketWorker.js +22 -0
- package/dist/vendor/node-pty/package.json +64 -0
- package/dist/vendor/node-pty/prebuilds/win32-arm64/conpty/OpenConsole.exe +0 -0
- package/dist/vendor/node-pty/prebuilds/win32-arm64/conpty/conpty.dll +0 -0
- package/dist/vendor/node-pty/prebuilds/win32-arm64/conpty.node +0 -0
- package/dist/vendor/node-pty/prebuilds/win32-arm64/conpty_console_list.node +0 -0
- package/dist/vendor/node-pty/prebuilds/win32-arm64/pty.node +0 -0
- package/dist/vendor/node-pty/prebuilds/win32-arm64/winpty-agent.exe +0 -0
- package/dist/vendor/node-pty/prebuilds/win32-arm64/winpty.dll +0 -0
- package/dist/vendor/node-pty/prebuilds/win32-x64/conpty/OpenConsole.exe +0 -0
- package/dist/vendor/node-pty/prebuilds/win32-x64/conpty/conpty.dll +0 -0
- package/dist/vendor/node-pty/prebuilds/win32-x64/conpty.node +0 -0
- package/dist/vendor/node-pty/prebuilds/win32-x64/conpty_console_list.node +0 -0
- package/dist/vendor/node-pty/prebuilds/win32-x64/pty.node +0 -0
- package/dist/vendor/node-pty/prebuilds/win32-x64/winpty-agent.exe +0 -0
- package/dist/vendor/node-pty/prebuilds/win32-x64/winpty.dll +0 -0
- package/package.json +3 -5
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2019, Microsoft Corporation (MIT License).
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.EventEmitter2 = void 0;
|
|
7
|
+
var EventEmitter2 = /** @class */ (function () {
|
|
8
|
+
function EventEmitter2() {
|
|
9
|
+
this._listeners = [];
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(EventEmitter2.prototype, "event", {
|
|
12
|
+
get: function () {
|
|
13
|
+
var _this = this;
|
|
14
|
+
if (!this._event) {
|
|
15
|
+
this._event = function (listener) {
|
|
16
|
+
_this._listeners.push(listener);
|
|
17
|
+
var disposable = {
|
|
18
|
+
dispose: function () {
|
|
19
|
+
for (var i = 0; i < _this._listeners.length; i++) {
|
|
20
|
+
if (_this._listeners[i] === listener) {
|
|
21
|
+
_this._listeners.splice(i, 1);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
return disposable;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return this._event;
|
|
31
|
+
},
|
|
32
|
+
enumerable: false,
|
|
33
|
+
configurable: true
|
|
34
|
+
});
|
|
35
|
+
EventEmitter2.prototype.fire = function (data) {
|
|
36
|
+
var queue = [];
|
|
37
|
+
for (var i = 0; i < this._listeners.length; i++) {
|
|
38
|
+
queue.push(this._listeners[i]);
|
|
39
|
+
}
|
|
40
|
+
for (var i = 0; i < queue.length; i++) {
|
|
41
|
+
queue[i].call(undefined, data);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
return EventEmitter2;
|
|
45
|
+
}());
|
|
46
|
+
exports.EventEmitter2 = EventEmitter2;
|
|
47
|
+
//# sourceMappingURL=eventEmitter2.js.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2012-2015, Christopher Jeffrey, Peter Sunde (MIT License)
|
|
4
|
+
* Copyright (c) 2016, Daniel Imms (MIT License).
|
|
5
|
+
* Copyright (c) 2018, Microsoft Corporation (MIT License).
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.native = exports.open = exports.createTerminal = exports.fork = exports.spawn = void 0;
|
|
9
|
+
var utils_1 = require("./utils");
|
|
10
|
+
var terminalCtor;
|
|
11
|
+
if (process.platform === 'win32') {
|
|
12
|
+
terminalCtor = require('./windowsTerminal').WindowsTerminal;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
terminalCtor = require('./unixTerminal').UnixTerminal;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Forks a process as a pseudoterminal.
|
|
19
|
+
* @param file The file to launch.
|
|
20
|
+
* @param args The file's arguments as argv (string[]) or in a pre-escaped
|
|
21
|
+
* CommandLine format (string). Note that the CommandLine option is only
|
|
22
|
+
* available on Windows and is expected to be escaped properly.
|
|
23
|
+
* @param options The options of the terminal.
|
|
24
|
+
* @throws When the file passed to spawn with does not exists.
|
|
25
|
+
* @see CommandLineToArgvW https://msdn.microsoft.com/en-us/library/windows/desktop/bb776391(v=vs.85).aspx
|
|
26
|
+
* @see Parsing C++ Comamnd-Line Arguments https://msdn.microsoft.com/en-us/library/17w5ykft.aspx
|
|
27
|
+
* @see GetCommandLine https://msdn.microsoft.com/en-us/library/windows/desktop/ms683156.aspx
|
|
28
|
+
*/
|
|
29
|
+
function spawn(file, args, opt) {
|
|
30
|
+
return new terminalCtor(file, args, opt);
|
|
31
|
+
}
|
|
32
|
+
exports.spawn = spawn;
|
|
33
|
+
/** @deprecated */
|
|
34
|
+
function fork(file, args, opt) {
|
|
35
|
+
return new terminalCtor(file, args, opt);
|
|
36
|
+
}
|
|
37
|
+
exports.fork = fork;
|
|
38
|
+
/** @deprecated */
|
|
39
|
+
function createTerminal(file, args, opt) {
|
|
40
|
+
return new terminalCtor(file, args, opt);
|
|
41
|
+
}
|
|
42
|
+
exports.createTerminal = createTerminal;
|
|
43
|
+
function open(options) {
|
|
44
|
+
return terminalCtor.open(options);
|
|
45
|
+
}
|
|
46
|
+
exports.open = open;
|
|
47
|
+
/**
|
|
48
|
+
* Expose the native API when not Windows, note that this is not public API and
|
|
49
|
+
* could be removed at any time.
|
|
50
|
+
*/
|
|
51
|
+
exports.native = (process.platform !== 'win32' ? utils_1.loadNativeModule('pty').module : null);
|
|
52
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2020, Microsoft Corporation (MIT License).
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getWorkerPipeName = void 0;
|
|
7
|
+
function getWorkerPipeName(conoutPipeName) {
|
|
8
|
+
return conoutPipeName + "-worker";
|
|
9
|
+
}
|
|
10
|
+
exports.getWorkerPipeName = getWorkerPipeName;
|
|
11
|
+
//# sourceMappingURL=conout.js.map
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2012-2015, Christopher Jeffrey (MIT License)
|
|
4
|
+
* Copyright (c) 2016, Daniel Imms (MIT License).
|
|
5
|
+
* Copyright (c) 2018, Microsoft Corporation (MIT License).
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.Terminal = exports.DEFAULT_ROWS = exports.DEFAULT_COLS = void 0;
|
|
9
|
+
var events_1 = require("events");
|
|
10
|
+
var eventEmitter2_1 = require("./eventEmitter2");
|
|
11
|
+
exports.DEFAULT_COLS = 80;
|
|
12
|
+
exports.DEFAULT_ROWS = 24;
|
|
13
|
+
/**
|
|
14
|
+
* Default messages to indicate PAUSE/RESUME for automatic flow control.
|
|
15
|
+
* To avoid conflicts with rebound XON/XOFF control codes (such as on-my-zsh),
|
|
16
|
+
* the sequences can be customized in `IPtyForkOptions`.
|
|
17
|
+
*/
|
|
18
|
+
var FLOW_CONTROL_PAUSE = '\x13'; // defaults to XOFF
|
|
19
|
+
var FLOW_CONTROL_RESUME = '\x11'; // defaults to XON
|
|
20
|
+
var Terminal = /** @class */ (function () {
|
|
21
|
+
function Terminal(opt) {
|
|
22
|
+
this._pid = 0;
|
|
23
|
+
this._fd = 0;
|
|
24
|
+
this._cols = 0;
|
|
25
|
+
this._rows = 0;
|
|
26
|
+
this._readable = false;
|
|
27
|
+
this._writable = false;
|
|
28
|
+
this._onData = new eventEmitter2_1.EventEmitter2();
|
|
29
|
+
this._onExit = new eventEmitter2_1.EventEmitter2();
|
|
30
|
+
// for 'close'
|
|
31
|
+
this._internalee = new events_1.EventEmitter();
|
|
32
|
+
// setup flow control handling
|
|
33
|
+
this.handleFlowControl = !!(opt === null || opt === void 0 ? void 0 : opt.handleFlowControl);
|
|
34
|
+
this._flowControlPause = (opt === null || opt === void 0 ? void 0 : opt.flowControlPause) || FLOW_CONTROL_PAUSE;
|
|
35
|
+
this._flowControlResume = (opt === null || opt === void 0 ? void 0 : opt.flowControlResume) || FLOW_CONTROL_RESUME;
|
|
36
|
+
if (!opt) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
// Do basic type checks here in case node-pty is being used within JavaScript. If the wrong
|
|
40
|
+
// types go through to the C++ side it can lead to hard to diagnose exceptions.
|
|
41
|
+
this._checkType('name', opt.name ? opt.name : undefined, 'string');
|
|
42
|
+
this._checkType('cols', opt.cols ? opt.cols : undefined, 'number');
|
|
43
|
+
this._checkType('rows', opt.rows ? opt.rows : undefined, 'number');
|
|
44
|
+
this._checkType('cwd', opt.cwd ? opt.cwd : undefined, 'string');
|
|
45
|
+
this._checkType('env', opt.env ? opt.env : undefined, 'object');
|
|
46
|
+
this._checkType('uid', opt.uid ? opt.uid : undefined, 'number');
|
|
47
|
+
this._checkType('gid', opt.gid ? opt.gid : undefined, 'number');
|
|
48
|
+
this._checkType('encoding', opt.encoding ? opt.encoding : undefined, 'string');
|
|
49
|
+
}
|
|
50
|
+
Object.defineProperty(Terminal.prototype, "onData", {
|
|
51
|
+
get: function () { return this._onData.event; },
|
|
52
|
+
enumerable: false,
|
|
53
|
+
configurable: true
|
|
54
|
+
});
|
|
55
|
+
Object.defineProperty(Terminal.prototype, "onExit", {
|
|
56
|
+
get: function () { return this._onExit.event; },
|
|
57
|
+
enumerable: false,
|
|
58
|
+
configurable: true
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(Terminal.prototype, "pid", {
|
|
61
|
+
get: function () { return this._pid; },
|
|
62
|
+
enumerable: false,
|
|
63
|
+
configurable: true
|
|
64
|
+
});
|
|
65
|
+
Object.defineProperty(Terminal.prototype, "cols", {
|
|
66
|
+
get: function () { return this._cols; },
|
|
67
|
+
enumerable: false,
|
|
68
|
+
configurable: true
|
|
69
|
+
});
|
|
70
|
+
Object.defineProperty(Terminal.prototype, "rows", {
|
|
71
|
+
get: function () { return this._rows; },
|
|
72
|
+
enumerable: false,
|
|
73
|
+
configurable: true
|
|
74
|
+
});
|
|
75
|
+
Terminal.prototype.write = function (data) {
|
|
76
|
+
if (this.handleFlowControl) {
|
|
77
|
+
// PAUSE/RESUME messages are not forwarded to the pty
|
|
78
|
+
if (data === this._flowControlPause) {
|
|
79
|
+
this.pause();
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (data === this._flowControlResume) {
|
|
83
|
+
this.resume();
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// everything else goes to the real pty
|
|
88
|
+
this._write(data);
|
|
89
|
+
};
|
|
90
|
+
Terminal.prototype._forwardEvents = function () {
|
|
91
|
+
var _this = this;
|
|
92
|
+
this.on('data', function (e) { return _this._onData.fire(e); });
|
|
93
|
+
this.on('exit', function (exitCode, signal) { return _this._onExit.fire({ exitCode: exitCode, signal: signal }); });
|
|
94
|
+
};
|
|
95
|
+
Terminal.prototype._checkType = function (name, value, type, allowArray) {
|
|
96
|
+
if (allowArray === void 0) { allowArray = false; }
|
|
97
|
+
if (value === undefined) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (allowArray) {
|
|
101
|
+
if (Array.isArray(value)) {
|
|
102
|
+
value.forEach(function (v, i) {
|
|
103
|
+
if (typeof v !== type) {
|
|
104
|
+
throw new Error(name + "[" + i + "] must be a " + type + " (not a " + typeof v[i] + ")");
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (typeof value !== type) {
|
|
111
|
+
throw new Error(name + " must be a " + type + " (not a " + typeof value + ")");
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
/** See net.Socket.end */
|
|
115
|
+
Terminal.prototype.end = function (data) {
|
|
116
|
+
this._socket.end(data);
|
|
117
|
+
};
|
|
118
|
+
/** See stream.Readable.pipe */
|
|
119
|
+
Terminal.prototype.pipe = function (dest, options) {
|
|
120
|
+
return this._socket.pipe(dest, options);
|
|
121
|
+
};
|
|
122
|
+
/** See net.Socket.pause */
|
|
123
|
+
Terminal.prototype.pause = function () {
|
|
124
|
+
return this._socket.pause();
|
|
125
|
+
};
|
|
126
|
+
/** See net.Socket.resume */
|
|
127
|
+
Terminal.prototype.resume = function () {
|
|
128
|
+
return this._socket.resume();
|
|
129
|
+
};
|
|
130
|
+
/** See net.Socket.setEncoding */
|
|
131
|
+
Terminal.prototype.setEncoding = function (encoding) {
|
|
132
|
+
if (this._socket._decoder) {
|
|
133
|
+
delete this._socket._decoder;
|
|
134
|
+
}
|
|
135
|
+
if (encoding) {
|
|
136
|
+
this._socket.setEncoding(encoding);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
Terminal.prototype.addListener = function (eventName, listener) { this.on(eventName, listener); };
|
|
140
|
+
Terminal.prototype.on = function (eventName, listener) {
|
|
141
|
+
if (eventName === 'close') {
|
|
142
|
+
this._internalee.on('close', listener);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
this._socket.on(eventName, listener);
|
|
146
|
+
};
|
|
147
|
+
Terminal.prototype.emit = function (eventName) {
|
|
148
|
+
var args = [];
|
|
149
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
150
|
+
args[_i - 1] = arguments[_i];
|
|
151
|
+
}
|
|
152
|
+
if (eventName === 'close') {
|
|
153
|
+
return this._internalee.emit.apply(this._internalee, arguments);
|
|
154
|
+
}
|
|
155
|
+
return this._socket.emit.apply(this._socket, arguments);
|
|
156
|
+
};
|
|
157
|
+
Terminal.prototype.listeners = function (eventName) {
|
|
158
|
+
return this._socket.listeners(eventName);
|
|
159
|
+
};
|
|
160
|
+
Terminal.prototype.removeListener = function (eventName, listener) {
|
|
161
|
+
this._socket.removeListener(eventName, listener);
|
|
162
|
+
};
|
|
163
|
+
Terminal.prototype.removeAllListeners = function (eventName) {
|
|
164
|
+
this._socket.removeAllListeners(eventName);
|
|
165
|
+
};
|
|
166
|
+
Terminal.prototype.once = function (eventName, listener) {
|
|
167
|
+
this._socket.once(eventName, listener);
|
|
168
|
+
};
|
|
169
|
+
Terminal.prototype._close = function () {
|
|
170
|
+
this._socket.readable = false;
|
|
171
|
+
this.write = function () { };
|
|
172
|
+
this.end = function () { };
|
|
173
|
+
this._writable = false;
|
|
174
|
+
this._readable = false;
|
|
175
|
+
};
|
|
176
|
+
Terminal.prototype._parseEnv = function (env) {
|
|
177
|
+
var keys = Object.keys(env || {});
|
|
178
|
+
var pairs = [];
|
|
179
|
+
for (var i = 0; i < keys.length; i++) {
|
|
180
|
+
if (keys[i] === undefined) {
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
pairs.push(keys[i] + '=' + env[keys[i]]);
|
|
184
|
+
}
|
|
185
|
+
return pairs;
|
|
186
|
+
};
|
|
187
|
+
return Terminal;
|
|
188
|
+
}());
|
|
189
|
+
exports.Terminal = Terminal;
|
|
190
|
+
//# sourceMappingURL=terminal.js.map
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
extendStatics(d, b);
|
|
11
|
+
function __() { this.constructor = d; }
|
|
12
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.UnixTerminal = void 0;
|
|
17
|
+
/**
|
|
18
|
+
* Copyright (c) 2012-2015, Christopher Jeffrey (MIT License)
|
|
19
|
+
* Copyright (c) 2016, Daniel Imms (MIT License).
|
|
20
|
+
* Copyright (c) 2018, Microsoft Corporation (MIT License).
|
|
21
|
+
*/
|
|
22
|
+
var fs = require("fs");
|
|
23
|
+
var path = require("path");
|
|
24
|
+
var tty = require("tty");
|
|
25
|
+
var terminal_1 = require("./terminal");
|
|
26
|
+
var utils_1 = require("./utils");
|
|
27
|
+
var native = utils_1.loadNativeModule('pty');
|
|
28
|
+
var pty = native.module;
|
|
29
|
+
var helperPath = native.dir + '/spawn-helper';
|
|
30
|
+
helperPath = path.resolve(__dirname, helperPath);
|
|
31
|
+
helperPath = helperPath.replace('app.asar', 'app.asar.unpacked');
|
|
32
|
+
helperPath = helperPath.replace('node_modules.asar', 'node_modules.asar.unpacked');
|
|
33
|
+
var DEFAULT_FILE = 'sh';
|
|
34
|
+
var DEFAULT_NAME = 'xterm';
|
|
35
|
+
var DESTROY_SOCKET_TIMEOUT_MS = 200;
|
|
36
|
+
var UnixTerminal = /** @class */ (function (_super) {
|
|
37
|
+
__extends(UnixTerminal, _super);
|
|
38
|
+
function UnixTerminal(file, args, opt) {
|
|
39
|
+
var _a, _b;
|
|
40
|
+
var _this = _super.call(this, opt) || this;
|
|
41
|
+
_this._boundClose = false;
|
|
42
|
+
_this._emittedClose = false;
|
|
43
|
+
if (typeof args === 'string') {
|
|
44
|
+
throw new Error('args as a string is not supported on unix.');
|
|
45
|
+
}
|
|
46
|
+
// Initialize arguments
|
|
47
|
+
args = args || [];
|
|
48
|
+
file = file || DEFAULT_FILE;
|
|
49
|
+
opt = opt || {};
|
|
50
|
+
opt.env = opt.env || process.env;
|
|
51
|
+
_this._cols = opt.cols || terminal_1.DEFAULT_COLS;
|
|
52
|
+
_this._rows = opt.rows || terminal_1.DEFAULT_ROWS;
|
|
53
|
+
var uid = (_a = opt.uid) !== null && _a !== void 0 ? _a : -1;
|
|
54
|
+
var gid = (_b = opt.gid) !== null && _b !== void 0 ? _b : -1;
|
|
55
|
+
var env = utils_1.assign({}, opt.env);
|
|
56
|
+
if (opt.env === process.env) {
|
|
57
|
+
_this._sanitizeEnv(env);
|
|
58
|
+
}
|
|
59
|
+
var cwd = opt.cwd || process.cwd();
|
|
60
|
+
env.PWD = cwd;
|
|
61
|
+
var name = opt.name || env.TERM || DEFAULT_NAME;
|
|
62
|
+
env.TERM = name;
|
|
63
|
+
var parsedEnv = _this._parseEnv(env);
|
|
64
|
+
var encoding = (opt.encoding === undefined ? 'utf8' : opt.encoding);
|
|
65
|
+
var onexit = function (code, signal) {
|
|
66
|
+
// XXX Sometimes a data event is emitted after exit. Wait til socket is
|
|
67
|
+
// destroyed.
|
|
68
|
+
if (!_this._emittedClose) {
|
|
69
|
+
if (_this._boundClose) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
_this._boundClose = true;
|
|
73
|
+
// From macOS High Sierra 10.13.2 sometimes the socket never gets
|
|
74
|
+
// closed. A timeout is applied here to avoid the terminal never being
|
|
75
|
+
// destroyed when this occurs.
|
|
76
|
+
var timeout_1 = setTimeout(function () {
|
|
77
|
+
timeout_1 = null;
|
|
78
|
+
// Destroying the socket now will cause the close event to fire
|
|
79
|
+
_this._socket.destroy();
|
|
80
|
+
}, DESTROY_SOCKET_TIMEOUT_MS);
|
|
81
|
+
_this.once('close', function () {
|
|
82
|
+
if (timeout_1 !== null) {
|
|
83
|
+
clearTimeout(timeout_1);
|
|
84
|
+
}
|
|
85
|
+
_this.emit('exit', code, signal);
|
|
86
|
+
});
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
_this.emit('exit', code, signal);
|
|
90
|
+
};
|
|
91
|
+
// fork
|
|
92
|
+
var term = pty.fork(file, args, parsedEnv, cwd, _this._cols, _this._rows, uid, gid, (encoding === 'utf8'), helperPath, onexit);
|
|
93
|
+
_this._socket = new tty.ReadStream(term.fd);
|
|
94
|
+
if (encoding !== null) {
|
|
95
|
+
_this._socket.setEncoding(encoding);
|
|
96
|
+
}
|
|
97
|
+
_this._writeStream = new CustomWriteStream(term.fd, (encoding || undefined));
|
|
98
|
+
// setup
|
|
99
|
+
_this._socket.on('error', function (err) {
|
|
100
|
+
// NOTE: fs.ReadStream gets EAGAIN twice at first:
|
|
101
|
+
if (err.code) {
|
|
102
|
+
if (~err.code.indexOf('EAGAIN')) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// close
|
|
107
|
+
_this._close();
|
|
108
|
+
// EIO on exit from fs.ReadStream:
|
|
109
|
+
if (!_this._emittedClose) {
|
|
110
|
+
_this._emittedClose = true;
|
|
111
|
+
_this.emit('close');
|
|
112
|
+
}
|
|
113
|
+
// EIO, happens when someone closes our child process: the only process in
|
|
114
|
+
// the terminal.
|
|
115
|
+
// node < 0.6.14: errno 5
|
|
116
|
+
// node >= 0.6.14: read EIO
|
|
117
|
+
if (err.code) {
|
|
118
|
+
if (~err.code.indexOf('errno 5') || ~err.code.indexOf('EIO')) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// throw anything else
|
|
123
|
+
if (_this.listeners('error').length < 2) {
|
|
124
|
+
throw err;
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
_this._pid = term.pid;
|
|
128
|
+
_this._fd = term.fd;
|
|
129
|
+
_this._pty = term.pty;
|
|
130
|
+
_this._file = file;
|
|
131
|
+
_this._name = name;
|
|
132
|
+
_this._readable = true;
|
|
133
|
+
_this._writable = true;
|
|
134
|
+
_this._socket.on('close', function () {
|
|
135
|
+
if (_this._emittedClose) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
_this._emittedClose = true;
|
|
139
|
+
_this._close();
|
|
140
|
+
_this.emit('close');
|
|
141
|
+
});
|
|
142
|
+
_this._forwardEvents();
|
|
143
|
+
return _this;
|
|
144
|
+
}
|
|
145
|
+
Object.defineProperty(UnixTerminal.prototype, "master", {
|
|
146
|
+
get: function () { return this._master; },
|
|
147
|
+
enumerable: false,
|
|
148
|
+
configurable: true
|
|
149
|
+
});
|
|
150
|
+
Object.defineProperty(UnixTerminal.prototype, "slave", {
|
|
151
|
+
get: function () { return this._slave; },
|
|
152
|
+
enumerable: false,
|
|
153
|
+
configurable: true
|
|
154
|
+
});
|
|
155
|
+
UnixTerminal.prototype._write = function (data) {
|
|
156
|
+
this._writeStream.write(data);
|
|
157
|
+
};
|
|
158
|
+
Object.defineProperty(UnixTerminal.prototype, "fd", {
|
|
159
|
+
/* Accessors */
|
|
160
|
+
get: function () { return this._fd; },
|
|
161
|
+
enumerable: false,
|
|
162
|
+
configurable: true
|
|
163
|
+
});
|
|
164
|
+
Object.defineProperty(UnixTerminal.prototype, "ptsName", {
|
|
165
|
+
get: function () { return this._pty; },
|
|
166
|
+
enumerable: false,
|
|
167
|
+
configurable: true
|
|
168
|
+
});
|
|
169
|
+
/**
|
|
170
|
+
* openpty
|
|
171
|
+
*/
|
|
172
|
+
UnixTerminal.open = function (opt) {
|
|
173
|
+
var self = Object.create(UnixTerminal.prototype);
|
|
174
|
+
opt = opt || {};
|
|
175
|
+
if (arguments.length > 1) {
|
|
176
|
+
opt = {
|
|
177
|
+
cols: arguments[1],
|
|
178
|
+
rows: arguments[2]
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
var cols = opt.cols || terminal_1.DEFAULT_COLS;
|
|
182
|
+
var rows = opt.rows || terminal_1.DEFAULT_ROWS;
|
|
183
|
+
var encoding = (opt.encoding === undefined ? 'utf8' : opt.encoding);
|
|
184
|
+
// open
|
|
185
|
+
var term = pty.open(cols, rows);
|
|
186
|
+
self._master = new tty.ReadStream(term.master);
|
|
187
|
+
if (encoding !== null) {
|
|
188
|
+
self._master.setEncoding(encoding);
|
|
189
|
+
}
|
|
190
|
+
self._master.resume();
|
|
191
|
+
self._slave = new tty.ReadStream(term.slave);
|
|
192
|
+
if (encoding !== null) {
|
|
193
|
+
self._slave.setEncoding(encoding);
|
|
194
|
+
}
|
|
195
|
+
self._slave.resume();
|
|
196
|
+
self._socket = self._master;
|
|
197
|
+
self._pid = -1;
|
|
198
|
+
self._fd = term.master;
|
|
199
|
+
self._pty = term.pty;
|
|
200
|
+
self._file = process.argv[0] || 'node';
|
|
201
|
+
self._name = process.env.TERM || '';
|
|
202
|
+
self._readable = true;
|
|
203
|
+
self._writable = true;
|
|
204
|
+
self._socket.on('error', function (err) {
|
|
205
|
+
self._close();
|
|
206
|
+
if (self.listeners('error').length < 2) {
|
|
207
|
+
throw err;
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
self._socket.on('close', function () {
|
|
211
|
+
self._close();
|
|
212
|
+
});
|
|
213
|
+
return self;
|
|
214
|
+
};
|
|
215
|
+
UnixTerminal.prototype.destroy = function () {
|
|
216
|
+
var _this = this;
|
|
217
|
+
this._close();
|
|
218
|
+
// Need to close the read stream so node stops reading a dead file
|
|
219
|
+
// descriptor. Then we can safely SIGHUP the shell.
|
|
220
|
+
this._socket.once('close', function () {
|
|
221
|
+
_this.kill('SIGHUP');
|
|
222
|
+
});
|
|
223
|
+
this._socket.destroy();
|
|
224
|
+
this._writeStream.dispose();
|
|
225
|
+
};
|
|
226
|
+
UnixTerminal.prototype.kill = function (signal) {
|
|
227
|
+
try {
|
|
228
|
+
process.kill(this.pid, signal || 'SIGHUP');
|
|
229
|
+
}
|
|
230
|
+
catch (e) { /* swallow */ }
|
|
231
|
+
};
|
|
232
|
+
Object.defineProperty(UnixTerminal.prototype, "process", {
|
|
233
|
+
/**
|
|
234
|
+
* Gets the name of the process.
|
|
235
|
+
*/
|
|
236
|
+
get: function () {
|
|
237
|
+
if (process.platform === 'darwin') {
|
|
238
|
+
var title = pty.process(this._fd);
|
|
239
|
+
return (title !== 'kernel_task') ? title : this._file;
|
|
240
|
+
}
|
|
241
|
+
return pty.process(this._fd, this._pty) || this._file;
|
|
242
|
+
},
|
|
243
|
+
enumerable: false,
|
|
244
|
+
configurable: true
|
|
245
|
+
});
|
|
246
|
+
/**
|
|
247
|
+
* TTY
|
|
248
|
+
*/
|
|
249
|
+
UnixTerminal.prototype.resize = function (cols, rows) {
|
|
250
|
+
if (cols <= 0 || rows <= 0 || isNaN(cols) || isNaN(rows) || cols === Infinity || rows === Infinity) {
|
|
251
|
+
throw new Error('resizing must be done using positive cols and rows');
|
|
252
|
+
}
|
|
253
|
+
pty.resize(this._fd, cols, rows);
|
|
254
|
+
this._cols = cols;
|
|
255
|
+
this._rows = rows;
|
|
256
|
+
};
|
|
257
|
+
UnixTerminal.prototype.clear = function () {
|
|
258
|
+
};
|
|
259
|
+
UnixTerminal.prototype._sanitizeEnv = function (env) {
|
|
260
|
+
// Make sure we didn't start our server from inside tmux.
|
|
261
|
+
delete env['TMUX'];
|
|
262
|
+
delete env['TMUX_PANE'];
|
|
263
|
+
// Make sure we didn't start our server from inside screen.
|
|
264
|
+
// http://web.mit.edu/gnu/doc/html/screen_20.html
|
|
265
|
+
delete env['STY'];
|
|
266
|
+
delete env['WINDOW'];
|
|
267
|
+
// Delete some variables that might confuse our terminal.
|
|
268
|
+
delete env['WINDOWID'];
|
|
269
|
+
delete env['TERMCAP'];
|
|
270
|
+
delete env['COLUMNS'];
|
|
271
|
+
delete env['LINES'];
|
|
272
|
+
};
|
|
273
|
+
return UnixTerminal;
|
|
274
|
+
}(terminal_1.Terminal));
|
|
275
|
+
exports.UnixTerminal = UnixTerminal;
|
|
276
|
+
/**
|
|
277
|
+
* A custom write stream that writes directly to a file descriptor with proper
|
|
278
|
+
* handling of backpressure and errors. This avoids some event loop exhaustion
|
|
279
|
+
* issues that can occur when using the standard APIs in Node.
|
|
280
|
+
*/
|
|
281
|
+
var CustomWriteStream = /** @class */ (function () {
|
|
282
|
+
function CustomWriteStream(_fd, _encoding) {
|
|
283
|
+
this._fd = _fd;
|
|
284
|
+
this._encoding = _encoding;
|
|
285
|
+
this._writeQueue = [];
|
|
286
|
+
}
|
|
287
|
+
CustomWriteStream.prototype.dispose = function () {
|
|
288
|
+
clearImmediate(this._writeImmediate);
|
|
289
|
+
this._writeImmediate = undefined;
|
|
290
|
+
};
|
|
291
|
+
CustomWriteStream.prototype.write = function (data) {
|
|
292
|
+
// Writes are put in a queue and processed asynchronously in order to handle
|
|
293
|
+
// backpressure from the kernel buffer.
|
|
294
|
+
var buffer = typeof data === 'string'
|
|
295
|
+
? Buffer.from(data, this._encoding)
|
|
296
|
+
: Buffer.from(data);
|
|
297
|
+
if (buffer.byteLength !== 0) {
|
|
298
|
+
this._writeQueue.push({ buffer: buffer, offset: 0 });
|
|
299
|
+
if (this._writeQueue.length === 1) {
|
|
300
|
+
this._processWriteQueue();
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
CustomWriteStream.prototype._processWriteQueue = function () {
|
|
305
|
+
var _this = this;
|
|
306
|
+
this._writeImmediate = undefined;
|
|
307
|
+
if (this._writeQueue.length === 0) {
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
var task = this._writeQueue[0];
|
|
311
|
+
// Write to the underlying file descriptor and handle it directly, rather
|
|
312
|
+
// than using the `net.Socket`/`tty.WriteStream` wrappers which swallow and
|
|
313
|
+
// mask errors like EAGAIN and can cause the thread to block indefinitely.
|
|
314
|
+
fs.write(this._fd, task.buffer, task.offset, function (err, written) {
|
|
315
|
+
if (err) {
|
|
316
|
+
if ('code' in err && err.code === 'EAGAIN') {
|
|
317
|
+
// `setImmediate` is used to yield to the event loop and re-attempt
|
|
318
|
+
// the write later.
|
|
319
|
+
_this._writeImmediate = setImmediate(function () { return _this._processWriteQueue(); });
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
// Stop processing immediately on unexpected error and log
|
|
323
|
+
_this._writeQueue.length = 0;
|
|
324
|
+
console.error('Unhandled pty write error', err);
|
|
325
|
+
}
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
task.offset += written;
|
|
329
|
+
if (task.offset >= task.buffer.byteLength) {
|
|
330
|
+
_this._writeQueue.shift();
|
|
331
|
+
}
|
|
332
|
+
// Since there is more room in the kernel buffer, we can continue to write
|
|
333
|
+
// until we hit EAGAIN or exhaust the queue.
|
|
334
|
+
//
|
|
335
|
+
// Note that old versions of bash, like v3.2 which ships in macOS, appears
|
|
336
|
+
// to have a bug in its readline implementation that causes data
|
|
337
|
+
// corruption when writes to the pty happens too quickly. Instead of
|
|
338
|
+
// trying to workaround that we just accept it so that large pastes are as
|
|
339
|
+
// fast as possible.
|
|
340
|
+
// Context: https://github.com/microsoft/node-pty/issues/833
|
|
341
|
+
_this._processWriteQueue();
|
|
342
|
+
});
|
|
343
|
+
};
|
|
344
|
+
return CustomWriteStream;
|
|
345
|
+
}());
|
|
346
|
+
//# sourceMappingURL=unixTerminal.js.map
|