@termiq/cli 0.1.0
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/LICENSE +54 -0
- package/README.md +61 -0
- package/dist/bin.js +102 -0
- package/dist/node_modules/node-pty/LICENSE +69 -0
- package/dist/node_modules/node-pty/README.md +165 -0
- package/dist/node_modules/node-pty/lib/conpty_console_list_agent.js +16 -0
- package/dist/node_modules/node-pty/lib/conpty_console_list_agent.js.map +1 -0
- package/dist/node_modules/node-pty/lib/eventEmitter2.js +47 -0
- package/dist/node_modules/node-pty/lib/eventEmitter2.js.map +1 -0
- package/dist/node_modules/node-pty/lib/eventEmitter2.test.js +30 -0
- package/dist/node_modules/node-pty/lib/eventEmitter2.test.js.map +1 -0
- package/dist/node_modules/node-pty/lib/index.js +52 -0
- package/dist/node_modules/node-pty/lib/index.js.map +1 -0
- package/dist/node_modules/node-pty/lib/interfaces.js +7 -0
- package/dist/node_modules/node-pty/lib/interfaces.js.map +1 -0
- package/dist/node_modules/node-pty/lib/shared/conout.js +11 -0
- package/dist/node_modules/node-pty/lib/shared/conout.js.map +1 -0
- package/dist/node_modules/node-pty/lib/terminal.js +190 -0
- package/dist/node_modules/node-pty/lib/terminal.js.map +1 -0
- package/dist/node_modules/node-pty/lib/terminal.test.js +139 -0
- package/dist/node_modules/node-pty/lib/terminal.test.js.map +1 -0
- package/dist/node_modules/node-pty/lib/testUtils.test.js +28 -0
- package/dist/node_modules/node-pty/lib/testUtils.test.js.map +1 -0
- package/dist/node_modules/node-pty/lib/types.js +7 -0
- package/dist/node_modules/node-pty/lib/types.js.map +1 -0
- package/dist/node_modules/node-pty/lib/unixTerminal.js +346 -0
- package/dist/node_modules/node-pty/lib/unixTerminal.js.map +1 -0
- package/dist/node_modules/node-pty/lib/unixTerminal.test.js +351 -0
- package/dist/node_modules/node-pty/lib/unixTerminal.test.js.map +1 -0
- package/dist/node_modules/node-pty/lib/utils.js +39 -0
- package/dist/node_modules/node-pty/lib/utils.js.map +1 -0
- package/dist/node_modules/node-pty/lib/windowsConoutConnection.js +125 -0
- package/dist/node_modules/node-pty/lib/windowsConoutConnection.js.map +1 -0
- package/dist/node_modules/node-pty/lib/windowsPtyAgent.js +320 -0
- package/dist/node_modules/node-pty/lib/windowsPtyAgent.js.map +1 -0
- package/dist/node_modules/node-pty/lib/windowsPtyAgent.test.js +90 -0
- package/dist/node_modules/node-pty/lib/windowsPtyAgent.test.js.map +1 -0
- package/dist/node_modules/node-pty/lib/windowsTerminal.js +199 -0
- package/dist/node_modules/node-pty/lib/windowsTerminal.js.map +1 -0
- package/dist/node_modules/node-pty/lib/windowsTerminal.test.js +219 -0
- package/dist/node_modules/node-pty/lib/windowsTerminal.test.js.map +1 -0
- package/dist/node_modules/node-pty/lib/worker/conoutSocketWorker.js +22 -0
- package/dist/node_modules/node-pty/lib/worker/conoutSocketWorker.js.map +1 -0
- package/dist/node_modules/node-pty/node-addon-api@7.1.1/node_modules/node-addon-api/node_addon_api_except.stamp +0 -0
- package/dist/node_modules/node-pty/package.json +64 -0
- package/dist/node_modules/node-pty/prebuilds/darwin-arm64/pty.node +0 -0
- package/dist/node_modules/node-pty/prebuilds/darwin-arm64/spawn-helper +0 -0
- package/dist/node_modules/node-pty/prebuilds/darwin-x64/pty.node +0 -0
- package/dist/node_modules/node-pty/prebuilds/darwin-x64/spawn-helper +0 -0
- package/dist/node_modules/node-pty/prebuilds/linux-x64/pty.node +0 -0
- package/dist/node_modules/node-pty/prebuilds/win32-arm64/conpty/OpenConsole.exe +0 -0
- package/dist/node_modules/node-pty/prebuilds/win32-arm64/conpty/conpty.dll +0 -0
- package/dist/node_modules/node-pty/prebuilds/win32-arm64/conpty.node +0 -0
- package/dist/node_modules/node-pty/prebuilds/win32-arm64/conpty_console_list.node +0 -0
- package/dist/node_modules/node-pty/prebuilds/win32-arm64/pty.node +0 -0
- package/dist/node_modules/node-pty/prebuilds/win32-arm64/winpty-agent.exe +0 -0
- package/dist/node_modules/node-pty/prebuilds/win32-arm64/winpty.dll +0 -0
- package/dist/node_modules/node-pty/prebuilds/win32-x64/conpty/OpenConsole.exe +0 -0
- package/dist/node_modules/node-pty/prebuilds/win32-x64/conpty/conpty.dll +0 -0
- package/dist/node_modules/node-pty/prebuilds/win32-x64/conpty.node +0 -0
- package/dist/node_modules/node-pty/prebuilds/win32-x64/conpty_console_list.node +0 -0
- package/dist/node_modules/node-pty/prebuilds/win32-x64/pty.node +0 -0
- package/dist/node_modules/node-pty/prebuilds/win32-x64/winpty-agent.exe +0 -0
- package/dist/node_modules/node-pty/prebuilds/win32-x64/winpty.dll +0 -0
- package/dist/node_modules/node-pty/typings/node-pty.d.ts +211 -0
- package/package.json +48 -0
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2017, Daniel Imms (MIT License).
|
|
4
|
+
* Copyright (c) 2018, Microsoft Corporation (MIT License).
|
|
5
|
+
*/
|
|
6
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
7
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
8
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
10
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
11
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
12
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
16
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
17
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
18
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
19
|
+
function step(op) {
|
|
20
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
21
|
+
while (_) try {
|
|
22
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
23
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
24
|
+
switch (op[0]) {
|
|
25
|
+
case 0: case 1: t = op; break;
|
|
26
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
27
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
28
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
29
|
+
default:
|
|
30
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
31
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
32
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
33
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
34
|
+
if (t[2]) _.ops.pop();
|
|
35
|
+
_.trys.pop(); continue;
|
|
36
|
+
}
|
|
37
|
+
op = body.call(thisArg, _);
|
|
38
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
39
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
+
var unixTerminal_1 = require("./unixTerminal");
|
|
44
|
+
var assert = require("assert");
|
|
45
|
+
var cp = require("child_process");
|
|
46
|
+
var path = require("path");
|
|
47
|
+
var tty = require("tty");
|
|
48
|
+
var fs = require("fs");
|
|
49
|
+
var os_1 = require("os");
|
|
50
|
+
var testUtils_test_1 = require("./testUtils.test");
|
|
51
|
+
var FIXTURES_PATH = path.normalize(path.join(__dirname, '..', 'fixtures', 'utf8-character.txt'));
|
|
52
|
+
if (process.platform !== 'win32') {
|
|
53
|
+
describe('UnixTerminal', function () {
|
|
54
|
+
describe('Constructor', function () {
|
|
55
|
+
it('should set a valid pts name', function () {
|
|
56
|
+
var term = new unixTerminal_1.UnixTerminal('/bin/bash', [], {});
|
|
57
|
+
var regExp;
|
|
58
|
+
if (process.platform === 'linux') {
|
|
59
|
+
// https://linux.die.net/man/4/pts
|
|
60
|
+
regExp = /^\/dev\/pts\/\d+$/;
|
|
61
|
+
}
|
|
62
|
+
if (process.platform === 'darwin') {
|
|
63
|
+
// https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man4/pty.4.html
|
|
64
|
+
regExp = /^\/dev\/tty[p-sP-S][a-z0-9]+$/;
|
|
65
|
+
}
|
|
66
|
+
if (regExp) {
|
|
67
|
+
assert.ok(regExp.test(term.ptsName), '"' + term.ptsName + '" should match ' + regExp.toString());
|
|
68
|
+
}
|
|
69
|
+
assert.ok(tty.isatty(term.fd));
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
describe('PtyForkEncodingOption', function () {
|
|
73
|
+
it('should default to utf8', function (done) {
|
|
74
|
+
var term = new unixTerminal_1.UnixTerminal('/bin/bash', ['-c', "cat \"" + FIXTURES_PATH + "\""]);
|
|
75
|
+
term.on('data', function (data) {
|
|
76
|
+
assert.strictEqual(typeof data, 'string');
|
|
77
|
+
assert.strictEqual(data, '\u00E6');
|
|
78
|
+
done();
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
it('should return a Buffer when encoding is null', function (done) {
|
|
82
|
+
var term = new unixTerminal_1.UnixTerminal('/bin/bash', ['-c', "cat \"" + FIXTURES_PATH + "\""], {
|
|
83
|
+
encoding: null
|
|
84
|
+
});
|
|
85
|
+
term.on('data', function (data) {
|
|
86
|
+
assert.strictEqual(typeof data, 'object');
|
|
87
|
+
assert.ok(data instanceof Buffer);
|
|
88
|
+
assert.strictEqual(0xC3, data[0]);
|
|
89
|
+
assert.strictEqual(0xA6, data[1]);
|
|
90
|
+
done();
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
it('should support other encodings', function (done) {
|
|
94
|
+
var text = 'test æ!';
|
|
95
|
+
var term = new unixTerminal_1.UnixTerminal(undefined, ['-c', 'echo "' + text + '"'], {
|
|
96
|
+
encoding: 'base64'
|
|
97
|
+
});
|
|
98
|
+
var buffer = '';
|
|
99
|
+
term.onData(function (data) {
|
|
100
|
+
assert.strictEqual(typeof data, 'string');
|
|
101
|
+
buffer += data;
|
|
102
|
+
});
|
|
103
|
+
term.onExit(function () {
|
|
104
|
+
assert.strictEqual(Buffer.alloc(8, buffer, 'base64').toString().replace('\r', '').replace('\n', ''), text);
|
|
105
|
+
done();
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
describe('open', function () {
|
|
110
|
+
var term;
|
|
111
|
+
afterEach(function () {
|
|
112
|
+
if (term) {
|
|
113
|
+
term.slave.destroy();
|
|
114
|
+
term.master.destroy();
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
it('should open a pty with access to a master and slave socket', function (done) {
|
|
118
|
+
term = unixTerminal_1.UnixTerminal.open({});
|
|
119
|
+
var slavebuf = '';
|
|
120
|
+
term.slave.on('data', function (data) {
|
|
121
|
+
slavebuf += data;
|
|
122
|
+
});
|
|
123
|
+
var masterbuf = '';
|
|
124
|
+
term.master.on('data', function (data) {
|
|
125
|
+
masterbuf += data;
|
|
126
|
+
});
|
|
127
|
+
testUtils_test_1.pollUntil(function () {
|
|
128
|
+
if (masterbuf === 'slave\r\nmaster\r\n' && slavebuf === 'master\n') {
|
|
129
|
+
done();
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
return false;
|
|
133
|
+
}, 200, 10);
|
|
134
|
+
term.slave.write('slave\n');
|
|
135
|
+
term.master.write('master\n');
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
describe('close', function () {
|
|
139
|
+
var term = new unixTerminal_1.UnixTerminal('node');
|
|
140
|
+
it('should exit when terminal is destroyed programmatically', function (done) {
|
|
141
|
+
term.on('exit', function (code, signal) {
|
|
142
|
+
assert.strictEqual(code, 0);
|
|
143
|
+
assert.strictEqual(signal, os_1.constants.signals.SIGHUP);
|
|
144
|
+
done();
|
|
145
|
+
});
|
|
146
|
+
term.destroy();
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
describe('signals in parent and child', function () {
|
|
150
|
+
it('SIGINT - custom in parent and child', function (done) {
|
|
151
|
+
// this test is cumbersome - we have to run it in a sub process to
|
|
152
|
+
// see behavior of SIGINT handlers
|
|
153
|
+
var data = "\n var pty = require('./lib/index');\n process.on('SIGINT', () => console.log('SIGINT in parent'));\n var ptyProcess = pty.spawn('node', ['-e', 'process.on(\"SIGINT\", ()=>console.log(\"SIGINT in child\"));setTimeout(() => null, 300);'], {\n name: 'xterm-color',\n cols: 80,\n rows: 30,\n cwd: process.env.HOME,\n env: process.env\n });\n ptyProcess.on('data', function (data) {\n console.log(data);\n });\n setTimeout(() => null, 500);\n console.log('ready', ptyProcess.pid);\n ";
|
|
154
|
+
var buffer = [];
|
|
155
|
+
var p = cp.spawn('node', ['-e', data]);
|
|
156
|
+
var sub = '';
|
|
157
|
+
p.stdout.on('data', function (data) {
|
|
158
|
+
if (!data.toString().indexOf('ready')) {
|
|
159
|
+
sub = data.toString().split(' ')[1].slice(0, -1);
|
|
160
|
+
setTimeout(function () {
|
|
161
|
+
process.kill(parseInt(sub), 'SIGINT'); // SIGINT to child
|
|
162
|
+
p.kill('SIGINT'); // SIGINT to parent
|
|
163
|
+
}, 200);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
buffer.push(data.toString().replace(/^\s+|\s+$/g, ''));
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
p.on('close', function () {
|
|
170
|
+
// handlers in parent and child should have been triggered
|
|
171
|
+
assert.strictEqual(buffer.indexOf('SIGINT in child') !== -1, true);
|
|
172
|
+
assert.strictEqual(buffer.indexOf('SIGINT in parent') !== -1, true);
|
|
173
|
+
done();
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
it('SIGINT - custom in parent, default in child', function (done) {
|
|
177
|
+
// this tests the original idea of the signal(...) change in pty.cc:
|
|
178
|
+
// to make sure the SIGINT handler of a pty child is reset to default
|
|
179
|
+
// and does not interfere with the handler in the parent
|
|
180
|
+
var data = "\n var pty = require('./lib/index');\n process.on('SIGINT', () => console.log('SIGINT in parent'));\n var ptyProcess = pty.spawn('node', ['-e', 'setTimeout(() => console.log(\"should not be printed\"), 300);'], {\n name: 'xterm-color',\n cols: 80,\n rows: 30,\n cwd: process.env.HOME,\n env: process.env\n });\n ptyProcess.on('data', function (data) {\n console.log(data);\n });\n setTimeout(() => null, 500);\n console.log('ready', ptyProcess.pid);\n ";
|
|
181
|
+
var buffer = [];
|
|
182
|
+
var p = cp.spawn('node', ['-e', data]);
|
|
183
|
+
var sub = '';
|
|
184
|
+
p.stdout.on('data', function (data) {
|
|
185
|
+
if (!data.toString().indexOf('ready')) {
|
|
186
|
+
sub = data.toString().split(' ')[1].slice(0, -1);
|
|
187
|
+
setTimeout(function () {
|
|
188
|
+
process.kill(parseInt(sub), 'SIGINT'); // SIGINT to child
|
|
189
|
+
p.kill('SIGINT'); // SIGINT to parent
|
|
190
|
+
}, 200);
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
buffer.push(data.toString().replace(/^\s+|\s+$/g, ''));
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
p.on('close', function () {
|
|
197
|
+
// handlers in parent and child should have been triggered
|
|
198
|
+
assert.strictEqual(buffer.indexOf('should not be printed') !== -1, false);
|
|
199
|
+
assert.strictEqual(buffer.indexOf('SIGINT in parent') !== -1, true);
|
|
200
|
+
done();
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
it('SIGHUP default (child only)', function (done) {
|
|
204
|
+
var term = new unixTerminal_1.UnixTerminal('node', ['-e', "\n console.log('ready');\n setTimeout(()=>console.log('timeout'), 200);"
|
|
205
|
+
]);
|
|
206
|
+
var buffer = '';
|
|
207
|
+
term.on('data', function (data) {
|
|
208
|
+
if (data === 'ready\r\n') {
|
|
209
|
+
term.kill();
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
buffer += data;
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
term.on('exit', function () {
|
|
216
|
+
// no timeout in buffer
|
|
217
|
+
assert.strictEqual(buffer, '');
|
|
218
|
+
done();
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
it('SIGUSR1 - custom in parent and child', function (done) {
|
|
222
|
+
var pHandlerCalled = 0;
|
|
223
|
+
var handleSigUsr = function (h) {
|
|
224
|
+
return function () {
|
|
225
|
+
pHandlerCalled += 1;
|
|
226
|
+
process.removeListener('SIGUSR1', h);
|
|
227
|
+
};
|
|
228
|
+
};
|
|
229
|
+
process.on('SIGUSR1', handleSigUsr(handleSigUsr));
|
|
230
|
+
var term = new unixTerminal_1.UnixTerminal('node', ['-e', "\n process.on('SIGUSR1', () => {\n console.log('SIGUSR1 in child');\n });\n console.log('ready');\n setTimeout(()=>null, 200);"
|
|
231
|
+
]);
|
|
232
|
+
var buffer = '';
|
|
233
|
+
term.on('data', function (data) {
|
|
234
|
+
if (data === 'ready\r\n') {
|
|
235
|
+
process.kill(process.pid, 'SIGUSR1');
|
|
236
|
+
term.kill('SIGUSR1');
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
buffer += data;
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
term.on('exit', function () {
|
|
243
|
+
// should have called both handlers and only once
|
|
244
|
+
assert.strictEqual(pHandlerCalled, 1);
|
|
245
|
+
assert.strictEqual(buffer, 'SIGUSR1 in child\r\n');
|
|
246
|
+
done();
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
describe('spawn', function () {
|
|
251
|
+
if (process.platform === 'darwin') {
|
|
252
|
+
it('should return the name of the process', function (done) {
|
|
253
|
+
var term = new unixTerminal_1.UnixTerminal('/bin/echo');
|
|
254
|
+
assert.strictEqual(term.process, '/bin/echo');
|
|
255
|
+
term.on('exit', function () { return done(); });
|
|
256
|
+
term.destroy();
|
|
257
|
+
});
|
|
258
|
+
it('should return the name of the sub process', function (done) {
|
|
259
|
+
var data = "\n var pty = require('./lib/index');\n var ptyProcess = pty.spawn('zsh', ['-c', 'python3'], {\n env: process.env\n });\n ptyProcess.on('data', function (data) {\n if (ptyProcess.process === 'Python') {\n console.log('title', ptyProcess.process);\n console.log('ready', ptyProcess.pid);\n }\n });\n ";
|
|
260
|
+
var p = cp.spawn('node', ['-e', data]);
|
|
261
|
+
var sub = '';
|
|
262
|
+
var pid = '';
|
|
263
|
+
p.stdout.on('data', function (data) {
|
|
264
|
+
if (!data.toString().indexOf('title')) {
|
|
265
|
+
sub = data.toString().split(' ')[1].slice(0, -1);
|
|
266
|
+
}
|
|
267
|
+
else if (!data.toString().indexOf('ready')) {
|
|
268
|
+
pid = data.toString().split(' ')[1].slice(0, -1);
|
|
269
|
+
process.kill(parseInt(pid), 'SIGINT');
|
|
270
|
+
p.kill('SIGINT');
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
p.on('exit', function () {
|
|
274
|
+
assert.notStrictEqual(pid, '');
|
|
275
|
+
assert.strictEqual(sub, 'Python');
|
|
276
|
+
done();
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
it('should close on exec', function (done) {
|
|
280
|
+
var data = "\n var pty = require('./lib/index');\n var ptyProcess = pty.spawn('node', ['-e', 'setTimeout(() => console.log(\"hello from terminal\"), 300);']);\n ptyProcess.on('data', function (data) {\n console.log(data);\n });\n setTimeout(() => null, 500);\n console.log('ready', ptyProcess.pid);\n ";
|
|
281
|
+
var buffer = [];
|
|
282
|
+
var readFd = fs.openSync(FIXTURES_PATH, 'r');
|
|
283
|
+
var p = cp.spawn('node', ['-e', data], {
|
|
284
|
+
stdio: ['ignore', 'pipe', 'pipe', readFd]
|
|
285
|
+
});
|
|
286
|
+
var sub = '';
|
|
287
|
+
p.stdout.on('data', function (data) {
|
|
288
|
+
if (!data.toString().indexOf('ready')) {
|
|
289
|
+
sub = data.toString().split(' ')[1].slice(0, -1);
|
|
290
|
+
try {
|
|
291
|
+
fs.statSync("/proc/" + sub + "/fd/" + readFd);
|
|
292
|
+
done('not reachable');
|
|
293
|
+
}
|
|
294
|
+
catch (error) {
|
|
295
|
+
assert.notStrictEqual(error.message.indexOf('ENOENT'), -1);
|
|
296
|
+
}
|
|
297
|
+
setTimeout(function () {
|
|
298
|
+
process.kill(parseInt(sub), 'SIGINT'); // SIGINT to child
|
|
299
|
+
p.kill('SIGINT'); // SIGINT to parent
|
|
300
|
+
}, 200);
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
buffer.push(data.toString().replace(/^\s+|\s+$/g, ''));
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
p.on('close', function () {
|
|
307
|
+
done();
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
it('should handle exec() errors', function (done) {
|
|
312
|
+
var term = new unixTerminal_1.UnixTerminal('/bin/bogus.exe', []);
|
|
313
|
+
term.on('exit', function (code, signal) {
|
|
314
|
+
assert.strictEqual(code, 1);
|
|
315
|
+
done();
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
it('should handle chdir() errors', function (done) {
|
|
319
|
+
var term = new unixTerminal_1.UnixTerminal('/bin/echo', [], { cwd: '/nowhere' });
|
|
320
|
+
term.on('exit', function (code, signal) {
|
|
321
|
+
assert.strictEqual(code, 1);
|
|
322
|
+
done();
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
it('should not leak child process', function (done) {
|
|
326
|
+
var count = cp.execSync('ps -ax | grep node | wc -l');
|
|
327
|
+
var term = new unixTerminal_1.UnixTerminal('node', ['-e', "\n console.log('ready');\n setTimeout(()=>console.log('timeout'), 200);"
|
|
328
|
+
]);
|
|
329
|
+
term.on('data', function (data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
330
|
+
var newCount;
|
|
331
|
+
return __generator(this, function (_a) {
|
|
332
|
+
switch (_a.label) {
|
|
333
|
+
case 0:
|
|
334
|
+
if (!(data === 'ready\r\n')) return [3 /*break*/, 2];
|
|
335
|
+
process.kill(term.pid, 'SIGINT');
|
|
336
|
+
return [4 /*yield*/, setTimeout(function () { return null; }, 1000)];
|
|
337
|
+
case 1:
|
|
338
|
+
_a.sent();
|
|
339
|
+
newCount = cp.execSync('ps -ax | grep node | wc -l');
|
|
340
|
+
assert.strictEqual(count.toString(), newCount.toString());
|
|
341
|
+
done();
|
|
342
|
+
_a.label = 2;
|
|
343
|
+
case 2: return [2 /*return*/];
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
}); });
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
//# sourceMappingURL=unixTerminal.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unixTerminal.test.js","sourceRoot":"","sources":["../src/unixTerminal.test.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,+CAA8C;AAC9C,+BAAiC;AACjC,kCAAoC;AACpC,2BAA6B;AAC7B,yBAA2B;AAC3B,uBAAyB;AACzB,yBAA+B;AAC/B,mDAA6C;AAG7C,IAAM,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE,oBAAoB,CAAC,CAAC,CAAC;AAEnG,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE;IAChC,QAAQ,CAAC,cAAc,EAAE;QACv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,CAAC;gBACxD,IAAM,IAAI,GAAG,IAAI,2BAAY,CAAC,MAAM,EAAE,CAAE,IAAI,EAAE,2FAEC;iBAC9C,CAAC,CAAC;gBACH,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,UAAO,IAAI;;;;;qCACrB,CAAA,IAAI,KAAK,WAAW,CAAA,EAApB,wBAAoB;gCACtB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;gCACjC,qBAAM,UAAU,CAAC,cAAM,OAAA,IAAI,EAAJ,CAAI,EAAE,IAAI,CAAC,EAAA;;gCAAlC,SAAkC,CAAC;gCAC7B,QAAQ,GAAG,EAAE,CAAC,QAAQ,CAAC,4BAA4B,CAAC,CAAC;gCAC3D,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,QAAQ,EAAE,EAAE,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC;gCAC1D,IAAI,EAAE,CAAC;;;;;qBAEV,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;CACJ"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2017, Daniel Imms (MIT License).
|
|
4
|
+
* Copyright (c) 2018, Microsoft Corporation (MIT License).
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.loadNativeModule = exports.assign = void 0;
|
|
8
|
+
function assign(target) {
|
|
9
|
+
var sources = [];
|
|
10
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
11
|
+
sources[_i - 1] = arguments[_i];
|
|
12
|
+
}
|
|
13
|
+
sources.forEach(function (source) { return Object.keys(source).forEach(function (key) { return target[key] = source[key]; }); });
|
|
14
|
+
return target;
|
|
15
|
+
}
|
|
16
|
+
exports.assign = assign;
|
|
17
|
+
function loadNativeModule(name) {
|
|
18
|
+
// Check build, debug, and then prebuilds.
|
|
19
|
+
var dirs = ['build/Release', 'build/Debug', "prebuilds/" + process.platform + "-" + process.arch];
|
|
20
|
+
// Check relative to the parent dir for unbundled and then the current dir for bundled
|
|
21
|
+
var relative = ['..', '.'];
|
|
22
|
+
var lastError;
|
|
23
|
+
for (var _i = 0, dirs_1 = dirs; _i < dirs_1.length; _i++) {
|
|
24
|
+
var d = dirs_1[_i];
|
|
25
|
+
for (var _a = 0, relative_1 = relative; _a < relative_1.length; _a++) {
|
|
26
|
+
var r = relative_1[_a];
|
|
27
|
+
var dir = r + "/" + d + "/";
|
|
28
|
+
try {
|
|
29
|
+
return { dir: dir, module: require(dir + "/" + name + ".node") };
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
lastError = e;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
throw new Error("Failed to load native module: " + name + ".node, checked: " + dirs.join(', ') + ": " + lastError);
|
|
37
|
+
}
|
|
38
|
+
exports.loadNativeModule = loadNativeModule;
|
|
39
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,SAAgB,MAAM,CAAC,MAAW;IAAE,iBAAiB;SAAjB,UAAiB,EAAjB,qBAAiB,EAAjB,IAAiB;QAAjB,gCAAiB;;IACnD,OAAO,CAAC,OAAO,CAAC,UAAA,MAAM,IAAI,OAAA,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,UAAA,GAAG,IAAI,OAAA,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,EAAzB,CAAyB,CAAC,EAA7D,CAA6D,CAAC,CAAC;IACzF,OAAO,MAAM,CAAC;AAChB,CAAC;AAHD,wBAGC;AAGD,SAAgB,gBAAgB,CAAC,IAAY;IAC3C,0CAA0C;IAC1C,IAAM,IAAI,GAAG,CAAC,eAAe,EAAE,aAAa,EAAE,eAAa,OAAO,CAAC,QAAQ,SAAI,OAAO,CAAC,IAAM,CAAC,CAAC;IAC/F,sFAAsF;IACtF,IAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAC7B,IAAI,SAAkB,CAAC;IACvB,KAAgB,UAAI,EAAJ,aAAI,EAAJ,kBAAI,EAAJ,IAAI,EAAE;QAAjB,IAAM,CAAC,aAAA;QACV,KAAgB,UAAQ,EAAR,qBAAQ,EAAR,sBAAQ,EAAR,IAAQ,EAAE;YAArB,IAAM,CAAC,iBAAA;YACV,IAAM,GAAG,GAAM,CAAC,SAAI,CAAC,MAAG,CAAC;YACzB,IAAI;gBACF,OAAO,EAAE,GAAG,KAAA,EAAE,MAAM,EAAE,OAAO,CAAI,GAAG,SAAI,IAAI,UAAO,CAAC,EAAE,CAAC;aACxD;YAAC,OAAO,CAAC,EAAE;gBACV,SAAS,GAAG,CAAC,CAAC;aACf;SACF;KACF;IACD,MAAM,IAAI,KAAK,CAAC,mCAAiC,IAAI,wBAAmB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAK,SAAW,CAAC,CAAC;AAC3G,CAAC;AAjBD,4CAiBC"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2020, Microsoft Corporation (MIT License).
|
|
4
|
+
*/
|
|
5
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
7
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
9
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
10
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
11
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
15
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
16
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
17
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
18
|
+
function step(op) {
|
|
19
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
20
|
+
while (_) try {
|
|
21
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
22
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
23
|
+
switch (op[0]) {
|
|
24
|
+
case 0: case 1: t = op; break;
|
|
25
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
26
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
27
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
28
|
+
default:
|
|
29
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
30
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
31
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
32
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
33
|
+
if (t[2]) _.ops.pop();
|
|
34
|
+
_.trys.pop(); continue;
|
|
35
|
+
}
|
|
36
|
+
op = body.call(thisArg, _);
|
|
37
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
38
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.ConoutConnection = void 0;
|
|
43
|
+
var worker_threads_1 = require("worker_threads");
|
|
44
|
+
var conout_1 = require("./shared/conout");
|
|
45
|
+
var path_1 = require("path");
|
|
46
|
+
var eventEmitter2_1 = require("./eventEmitter2");
|
|
47
|
+
/**
|
|
48
|
+
* The amount of time to wait for additional data after the conpty shell process has exited before
|
|
49
|
+
* shutting down the worker and sockets. The timer will be reset if a new data event comes in after
|
|
50
|
+
* the timer has started.
|
|
51
|
+
*/
|
|
52
|
+
var FLUSH_DATA_INTERVAL = 1000;
|
|
53
|
+
/**
|
|
54
|
+
* Connects to and manages the lifecycle of the conout socket. This socket must be drained on
|
|
55
|
+
* another thread in order to avoid deadlocks where Conpty waits for the out socket to drain
|
|
56
|
+
* when `ClosePseudoConsole` is called. This happens when data is being written to the terminal when
|
|
57
|
+
* the pty is closed.
|
|
58
|
+
*
|
|
59
|
+
* See also:
|
|
60
|
+
* - https://github.com/microsoft/node-pty/issues/375
|
|
61
|
+
* - https://github.com/microsoft/vscode/issues/76548
|
|
62
|
+
* - https://github.com/microsoft/terminal/issues/1810
|
|
63
|
+
* - https://docs.microsoft.com/en-us/windows/console/closepseudoconsole
|
|
64
|
+
*/
|
|
65
|
+
var ConoutConnection = /** @class */ (function () {
|
|
66
|
+
function ConoutConnection(_conoutPipeName, _useConptyDll) {
|
|
67
|
+
var _this = this;
|
|
68
|
+
this._conoutPipeName = _conoutPipeName;
|
|
69
|
+
this._useConptyDll = _useConptyDll;
|
|
70
|
+
this._isDisposed = false;
|
|
71
|
+
this._onReady = new eventEmitter2_1.EventEmitter2();
|
|
72
|
+
var workerData = {
|
|
73
|
+
conoutPipeName: _conoutPipeName
|
|
74
|
+
};
|
|
75
|
+
var scriptPath = __dirname.replace('node_modules.asar', 'node_modules.asar.unpacked');
|
|
76
|
+
this._worker = new worker_threads_1.Worker(path_1.join(scriptPath, 'worker/conoutSocketWorker.js'), { workerData: workerData });
|
|
77
|
+
this._worker.on('message', function (message) {
|
|
78
|
+
switch (message) {
|
|
79
|
+
case 1 /* READY */:
|
|
80
|
+
_this._onReady.fire();
|
|
81
|
+
return;
|
|
82
|
+
default:
|
|
83
|
+
console.warn('Unexpected ConoutWorkerMessage', message);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
Object.defineProperty(ConoutConnection.prototype, "onReady", {
|
|
88
|
+
get: function () { return this._onReady.event; },
|
|
89
|
+
enumerable: false,
|
|
90
|
+
configurable: true
|
|
91
|
+
});
|
|
92
|
+
ConoutConnection.prototype.dispose = function () {
|
|
93
|
+
if (!this._useConptyDll && this._isDisposed) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
this._isDisposed = true;
|
|
97
|
+
// Drain all data from the socket before closing
|
|
98
|
+
this._drainDataAndClose();
|
|
99
|
+
};
|
|
100
|
+
ConoutConnection.prototype.connectSocket = function (socket) {
|
|
101
|
+
socket.connect(conout_1.getWorkerPipeName(this._conoutPipeName));
|
|
102
|
+
};
|
|
103
|
+
ConoutConnection.prototype._drainDataAndClose = function () {
|
|
104
|
+
var _this = this;
|
|
105
|
+
if (this._drainTimeout) {
|
|
106
|
+
clearTimeout(this._drainTimeout);
|
|
107
|
+
}
|
|
108
|
+
this._drainTimeout = setTimeout(function () { return _this._destroySocket(); }, FLUSH_DATA_INTERVAL);
|
|
109
|
+
};
|
|
110
|
+
ConoutConnection.prototype._destroySocket = function () {
|
|
111
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
112
|
+
return __generator(this, function (_a) {
|
|
113
|
+
switch (_a.label) {
|
|
114
|
+
case 0: return [4 /*yield*/, this._worker.terminate()];
|
|
115
|
+
case 1:
|
|
116
|
+
_a.sent();
|
|
117
|
+
return [2 /*return*/];
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
return ConoutConnection;
|
|
123
|
+
}());
|
|
124
|
+
exports.ConoutConnection = ConoutConnection;
|
|
125
|
+
//# sourceMappingURL=windowsConoutConnection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"windowsConoutConnection.js","sourceRoot":"","sources":["../src/windowsConoutConnection.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,iDAAwC;AAGxC,0CAAsF;AACtF,6BAA4B;AAC5B,iDAAwD;AAExD;;;;GAIG;AACH,IAAM,mBAAmB,GAAG,IAAI,CAAC;AAEjC;;;;;;;;;;;GAWG;AACH;IAQE,0BACU,eAAuB,EACvB,aAAsB;QAFhC,iBAkBC;QAjBS,oBAAe,GAAf,eAAe,CAAQ;QACvB,kBAAa,GAAb,aAAa,CAAS;QAPxB,gBAAW,GAAY,KAAK,CAAC;QAE7B,aAAQ,GAAG,IAAI,6BAAa,EAAQ,CAAC;QAO3C,IAAM,UAAU,GAAgB;YAC9B,cAAc,EAAE,eAAe;SAChC,CAAC;QACF,IAAM,UAAU,GAAG,SAAS,CAAC,OAAO,CAAC,mBAAmB,EAAE,4BAA4B,CAAC,CAAC;QACxF,IAAI,CAAC,OAAO,GAAG,IAAI,uBAAM,CAAC,WAAI,CAAC,UAAU,EAAE,8BAA8B,CAAC,EAAE,EAAE,UAAU,YAAA,EAAE,CAAC,CAAC;QAC5F,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,UAAC,OAA4B;YACtD,QAAQ,OAAO,EAAE;gBACf;oBACE,KAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;oBACrB,OAAO;gBACT;oBACE,OAAO,CAAC,IAAI,CAAC,gCAAgC,EAAE,OAAO,CAAC,CAAC;aAC3D;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IApBD,sBAAW,qCAAO;aAAlB,cAA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