@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.
Files changed (66) hide show
  1. package/LICENSE +54 -0
  2. package/README.md +61 -0
  3. package/dist/bin.js +102 -0
  4. package/dist/node_modules/node-pty/LICENSE +69 -0
  5. package/dist/node_modules/node-pty/README.md +165 -0
  6. package/dist/node_modules/node-pty/lib/conpty_console_list_agent.js +16 -0
  7. package/dist/node_modules/node-pty/lib/conpty_console_list_agent.js.map +1 -0
  8. package/dist/node_modules/node-pty/lib/eventEmitter2.js +47 -0
  9. package/dist/node_modules/node-pty/lib/eventEmitter2.js.map +1 -0
  10. package/dist/node_modules/node-pty/lib/eventEmitter2.test.js +30 -0
  11. package/dist/node_modules/node-pty/lib/eventEmitter2.test.js.map +1 -0
  12. package/dist/node_modules/node-pty/lib/index.js +52 -0
  13. package/dist/node_modules/node-pty/lib/index.js.map +1 -0
  14. package/dist/node_modules/node-pty/lib/interfaces.js +7 -0
  15. package/dist/node_modules/node-pty/lib/interfaces.js.map +1 -0
  16. package/dist/node_modules/node-pty/lib/shared/conout.js +11 -0
  17. package/dist/node_modules/node-pty/lib/shared/conout.js.map +1 -0
  18. package/dist/node_modules/node-pty/lib/terminal.js +190 -0
  19. package/dist/node_modules/node-pty/lib/terminal.js.map +1 -0
  20. package/dist/node_modules/node-pty/lib/terminal.test.js +139 -0
  21. package/dist/node_modules/node-pty/lib/terminal.test.js.map +1 -0
  22. package/dist/node_modules/node-pty/lib/testUtils.test.js +28 -0
  23. package/dist/node_modules/node-pty/lib/testUtils.test.js.map +1 -0
  24. package/dist/node_modules/node-pty/lib/types.js +7 -0
  25. package/dist/node_modules/node-pty/lib/types.js.map +1 -0
  26. package/dist/node_modules/node-pty/lib/unixTerminal.js +346 -0
  27. package/dist/node_modules/node-pty/lib/unixTerminal.js.map +1 -0
  28. package/dist/node_modules/node-pty/lib/unixTerminal.test.js +351 -0
  29. package/dist/node_modules/node-pty/lib/unixTerminal.test.js.map +1 -0
  30. package/dist/node_modules/node-pty/lib/utils.js +39 -0
  31. package/dist/node_modules/node-pty/lib/utils.js.map +1 -0
  32. package/dist/node_modules/node-pty/lib/windowsConoutConnection.js +125 -0
  33. package/dist/node_modules/node-pty/lib/windowsConoutConnection.js.map +1 -0
  34. package/dist/node_modules/node-pty/lib/windowsPtyAgent.js +320 -0
  35. package/dist/node_modules/node-pty/lib/windowsPtyAgent.js.map +1 -0
  36. package/dist/node_modules/node-pty/lib/windowsPtyAgent.test.js +90 -0
  37. package/dist/node_modules/node-pty/lib/windowsPtyAgent.test.js.map +1 -0
  38. package/dist/node_modules/node-pty/lib/windowsTerminal.js +199 -0
  39. package/dist/node_modules/node-pty/lib/windowsTerminal.js.map +1 -0
  40. package/dist/node_modules/node-pty/lib/windowsTerminal.test.js +219 -0
  41. package/dist/node_modules/node-pty/lib/windowsTerminal.test.js.map +1 -0
  42. package/dist/node_modules/node-pty/lib/worker/conoutSocketWorker.js +22 -0
  43. package/dist/node_modules/node-pty/lib/worker/conoutSocketWorker.js.map +1 -0
  44. package/dist/node_modules/node-pty/node-addon-api@7.1.1/node_modules/node-addon-api/node_addon_api_except.stamp +0 -0
  45. package/dist/node_modules/node-pty/package.json +64 -0
  46. package/dist/node_modules/node-pty/prebuilds/darwin-arm64/pty.node +0 -0
  47. package/dist/node_modules/node-pty/prebuilds/darwin-arm64/spawn-helper +0 -0
  48. package/dist/node_modules/node-pty/prebuilds/darwin-x64/pty.node +0 -0
  49. package/dist/node_modules/node-pty/prebuilds/darwin-x64/spawn-helper +0 -0
  50. package/dist/node_modules/node-pty/prebuilds/linux-x64/pty.node +0 -0
  51. package/dist/node_modules/node-pty/prebuilds/win32-arm64/conpty/OpenConsole.exe +0 -0
  52. package/dist/node_modules/node-pty/prebuilds/win32-arm64/conpty/conpty.dll +0 -0
  53. package/dist/node_modules/node-pty/prebuilds/win32-arm64/conpty.node +0 -0
  54. package/dist/node_modules/node-pty/prebuilds/win32-arm64/conpty_console_list.node +0 -0
  55. package/dist/node_modules/node-pty/prebuilds/win32-arm64/pty.node +0 -0
  56. package/dist/node_modules/node-pty/prebuilds/win32-arm64/winpty-agent.exe +0 -0
  57. package/dist/node_modules/node-pty/prebuilds/win32-arm64/winpty.dll +0 -0
  58. package/dist/node_modules/node-pty/prebuilds/win32-x64/conpty/OpenConsole.exe +0 -0
  59. package/dist/node_modules/node-pty/prebuilds/win32-x64/conpty/conpty.dll +0 -0
  60. package/dist/node_modules/node-pty/prebuilds/win32-x64/conpty.node +0 -0
  61. package/dist/node_modules/node-pty/prebuilds/win32-x64/conpty_console_list.node +0 -0
  62. package/dist/node_modules/node-pty/prebuilds/win32-x64/pty.node +0 -0
  63. package/dist/node_modules/node-pty/prebuilds/win32-x64/winpty-agent.exe +0 -0
  64. package/dist/node_modules/node-pty/prebuilds/win32-x64/winpty.dll +0 -0
  65. package/dist/node_modules/node-pty/typings/node-pty.d.ts +211 -0
  66. package/package.json +48 -0
@@ -0,0 +1,320 @@
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.argsToCommandLine = exports.WindowsPtyAgent = void 0;
9
+ var fs = require("fs");
10
+ var os = require("os");
11
+ var path = require("path");
12
+ var child_process_1 = require("child_process");
13
+ var net_1 = require("net");
14
+ var windowsConoutConnection_1 = require("./windowsConoutConnection");
15
+ var utils_1 = require("./utils");
16
+ var conptyNative;
17
+ var winptyNative;
18
+ /**
19
+ * The amount of time to wait for additional data after the conpty shell process has exited before
20
+ * shutting down the socket. The timer will be reset if a new data event comes in after the timer
21
+ * has started.
22
+ */
23
+ var FLUSH_DATA_INTERVAL = 1000;
24
+ /**
25
+ * This agent sits between the WindowsTerminal class and provides a common interface for both conpty
26
+ * and winpty.
27
+ */
28
+ var WindowsPtyAgent = /** @class */ (function () {
29
+ function WindowsPtyAgent(file, args, env, cwd, cols, rows, debug, _useConpty, _useConptyDll, conptyInheritCursor) {
30
+ var _this = this;
31
+ if (_useConptyDll === void 0) { _useConptyDll = false; }
32
+ if (conptyInheritCursor === void 0) { conptyInheritCursor = false; }
33
+ this._useConpty = _useConpty;
34
+ this._useConptyDll = _useConptyDll;
35
+ this._pid = 0;
36
+ this._innerPid = 0;
37
+ if (this._useConpty === undefined || this._useConpty === true) {
38
+ this._useConpty = this._getWindowsBuildNumber() >= 18309;
39
+ }
40
+ if (this._useConpty) {
41
+ if (!conptyNative) {
42
+ conptyNative = utils_1.loadNativeModule('conpty').module;
43
+ }
44
+ }
45
+ else {
46
+ if (!winptyNative) {
47
+ winptyNative = utils_1.loadNativeModule('pty').module;
48
+ }
49
+ }
50
+ this._ptyNative = this._useConpty ? conptyNative : winptyNative;
51
+ // Sanitize input variable.
52
+ cwd = path.resolve(cwd);
53
+ // Compose command line
54
+ var commandLine = argsToCommandLine(file, args);
55
+ // Open pty session.
56
+ var term;
57
+ if (this._useConpty) {
58
+ term = this._ptyNative.startProcess(file, cols, rows, debug, this._generatePipeName(), conptyInheritCursor, this._useConptyDll);
59
+ }
60
+ else {
61
+ term = this._ptyNative.startProcess(file, commandLine, env, cwd, cols, rows, debug);
62
+ this._pid = term.pid;
63
+ this._innerPid = term.innerPid;
64
+ }
65
+ // Not available on windows.
66
+ this._fd = term.fd;
67
+ // Generated incremental number that has no real purpose besides using it
68
+ // as a terminal id.
69
+ this._pty = term.pty;
70
+ // Create terminal pipe IPC channel and forward to a local unix socket.
71
+ this._outSocket = new net_1.Socket();
72
+ this._outSocket.setEncoding('utf8');
73
+ // The conout socket must be ready out on another thread to avoid deadlocks
74
+ this._conoutSocketWorker = new windowsConoutConnection_1.ConoutConnection(term.conout, this._useConptyDll);
75
+ this._conoutSocketWorker.onReady(function () {
76
+ _this._conoutSocketWorker.connectSocket(_this._outSocket);
77
+ });
78
+ this._outSocket.on('connect', function () {
79
+ _this._outSocket.emit('ready_datapipe');
80
+ });
81
+ var inSocketFD = fs.openSync(term.conin, 'w');
82
+ this._inSocket = new net_1.Socket({
83
+ fd: inSocketFD,
84
+ readable: false,
85
+ writable: true
86
+ });
87
+ this._inSocket.setEncoding('utf8');
88
+ if (this._useConpty) {
89
+ var connect = this._ptyNative.connect(this._pty, commandLine, cwd, env, this._useConptyDll, function (c) { return _this._$onProcessExit(c); });
90
+ this._innerPid = connect.pid;
91
+ }
92
+ }
93
+ Object.defineProperty(WindowsPtyAgent.prototype, "inSocket", {
94
+ get: function () { return this._inSocket; },
95
+ enumerable: false,
96
+ configurable: true
97
+ });
98
+ Object.defineProperty(WindowsPtyAgent.prototype, "outSocket", {
99
+ get: function () { return this._outSocket; },
100
+ enumerable: false,
101
+ configurable: true
102
+ });
103
+ Object.defineProperty(WindowsPtyAgent.prototype, "fd", {
104
+ get: function () { return this._fd; },
105
+ enumerable: false,
106
+ configurable: true
107
+ });
108
+ Object.defineProperty(WindowsPtyAgent.prototype, "innerPid", {
109
+ get: function () { return this._innerPid; },
110
+ enumerable: false,
111
+ configurable: true
112
+ });
113
+ Object.defineProperty(WindowsPtyAgent.prototype, "pty", {
114
+ get: function () { return this._pty; },
115
+ enumerable: false,
116
+ configurable: true
117
+ });
118
+ WindowsPtyAgent.prototype.resize = function (cols, rows) {
119
+ if (this._useConpty) {
120
+ if (this._exitCode !== undefined) {
121
+ throw new Error('Cannot resize a pty that has already exited');
122
+ }
123
+ this._ptyNative.resize(this._pty, cols, rows, this._useConptyDll);
124
+ return;
125
+ }
126
+ this._ptyNative.resize(this._pid, cols, rows);
127
+ };
128
+ WindowsPtyAgent.prototype.clear = function () {
129
+ if (this._useConpty) {
130
+ this._ptyNative.clear(this._pty, this._useConptyDll);
131
+ }
132
+ };
133
+ WindowsPtyAgent.prototype.kill = function () {
134
+ var _this = this;
135
+ // Tell the agent to kill the pty, this releases handles to the process
136
+ if (this._useConpty) {
137
+ if (!this._useConptyDll) {
138
+ this._inSocket.readable = false;
139
+ this._outSocket.readable = false;
140
+ this._getConsoleProcessList().then(function (consoleProcessList) {
141
+ consoleProcessList.forEach(function (pid) {
142
+ try {
143
+ process.kill(pid);
144
+ }
145
+ catch (e) {
146
+ // Ignore if process cannot be found (kill ESRCH error)
147
+ }
148
+ });
149
+ });
150
+ this._ptyNative.kill(this._pty, this._useConptyDll);
151
+ this._conoutSocketWorker.dispose();
152
+ }
153
+ else {
154
+ // Close the input write handle to signal the end of session.
155
+ this._inSocket.destroy();
156
+ this._ptyNative.kill(this._pty, this._useConptyDll);
157
+ this._outSocket.on('data', function () {
158
+ _this._conoutSocketWorker.dispose();
159
+ });
160
+ }
161
+ }
162
+ else {
163
+ // Because pty.kill closes the handle, it will kill most processes by itself.
164
+ // Process IDs can be reused as soon as all handles to them are
165
+ // dropped, so we want to immediately kill the entire console process list.
166
+ // If we do not force kill all processes here, node servers in particular
167
+ // seem to become detached and remain running (see
168
+ // Microsoft/vscode#26807).
169
+ var processList = this._ptyNative.getProcessList(this._pid);
170
+ this._ptyNative.kill(this._pid, this._innerPid);
171
+ processList.forEach(function (pid) {
172
+ try {
173
+ process.kill(pid);
174
+ }
175
+ catch (e) {
176
+ // Ignore if process cannot be found (kill ESRCH error)
177
+ }
178
+ });
179
+ }
180
+ };
181
+ WindowsPtyAgent.prototype._getConsoleProcessList = function () {
182
+ var _this = this;
183
+ return new Promise(function (resolve) {
184
+ var agent = child_process_1.fork(path.join(__dirname, 'conpty_console_list_agent'), [_this._innerPid.toString()]);
185
+ agent.on('message', function (message) {
186
+ clearTimeout(timeout);
187
+ resolve(message.consoleProcessList);
188
+ });
189
+ var timeout = setTimeout(function () {
190
+ // Something went wrong, just send back the shell PID
191
+ agent.kill();
192
+ resolve([_this._innerPid]);
193
+ }, 5000);
194
+ });
195
+ };
196
+ Object.defineProperty(WindowsPtyAgent.prototype, "exitCode", {
197
+ get: function () {
198
+ if (this._useConpty) {
199
+ return this._exitCode;
200
+ }
201
+ var winptyExitCode = this._ptyNative.getExitCode(this._innerPid);
202
+ return winptyExitCode === -1 ? undefined : winptyExitCode;
203
+ },
204
+ enumerable: false,
205
+ configurable: true
206
+ });
207
+ WindowsPtyAgent.prototype._getWindowsBuildNumber = function () {
208
+ var osVersion = (/(\d+)\.(\d+)\.(\d+)/g).exec(os.release());
209
+ var buildNumber = 0;
210
+ if (osVersion && osVersion.length === 4) {
211
+ buildNumber = parseInt(osVersion[3]);
212
+ }
213
+ return buildNumber;
214
+ };
215
+ WindowsPtyAgent.prototype._generatePipeName = function () {
216
+ return "conpty-" + Math.random() * 10000000;
217
+ };
218
+ /**
219
+ * Triggered from the native side when a contpy process exits.
220
+ */
221
+ WindowsPtyAgent.prototype._$onProcessExit = function (exitCode) {
222
+ var _this = this;
223
+ this._exitCode = exitCode;
224
+ if (!this._useConptyDll) {
225
+ this._flushDataAndCleanUp();
226
+ this._outSocket.on('data', function () { return _this._flushDataAndCleanUp(); });
227
+ }
228
+ };
229
+ WindowsPtyAgent.prototype._flushDataAndCleanUp = function () {
230
+ var _this = this;
231
+ if (this._useConptyDll) {
232
+ return;
233
+ }
234
+ if (this._closeTimeout) {
235
+ clearTimeout(this._closeTimeout);
236
+ }
237
+ this._closeTimeout = setTimeout(function () { return _this._cleanUpProcess(); }, FLUSH_DATA_INTERVAL);
238
+ };
239
+ WindowsPtyAgent.prototype._cleanUpProcess = function () {
240
+ if (this._useConptyDll) {
241
+ return;
242
+ }
243
+ this._inSocket.readable = false;
244
+ this._outSocket.readable = false;
245
+ this._outSocket.destroy();
246
+ };
247
+ return WindowsPtyAgent;
248
+ }());
249
+ exports.WindowsPtyAgent = WindowsPtyAgent;
250
+ // Convert argc/argv into a Win32 command-line following the escaping convention
251
+ // documented on MSDN (e.g. see CommandLineToArgvW documentation). Copied from
252
+ // winpty project.
253
+ function argsToCommandLine(file, args) {
254
+ if (isCommandLine(args)) {
255
+ if (args.length === 0) {
256
+ return file;
257
+ }
258
+ return argsToCommandLine(file, []) + " " + args;
259
+ }
260
+ var argv = [file];
261
+ Array.prototype.push.apply(argv, args);
262
+ var result = '';
263
+ for (var argIndex = 0; argIndex < argv.length; argIndex++) {
264
+ if (argIndex > 0) {
265
+ result += ' ';
266
+ }
267
+ var arg = argv[argIndex];
268
+ // if it is empty or it contains whitespace and is not already quoted
269
+ var hasLopsidedEnclosingQuote = xOr((arg[0] !== '"'), (arg[arg.length - 1] !== '"'));
270
+ var hasNoEnclosingQuotes = ((arg[0] !== '"') && (arg[arg.length - 1] !== '"'));
271
+ var quote = arg === '' ||
272
+ (arg.indexOf(' ') !== -1 ||
273
+ arg.indexOf('\t') !== -1) &&
274
+ ((arg.length > 1) &&
275
+ (hasLopsidedEnclosingQuote || hasNoEnclosingQuotes));
276
+ if (quote) {
277
+ result += '\"';
278
+ }
279
+ var bsCount = 0;
280
+ for (var i = 0; i < arg.length; i++) {
281
+ var p = arg[i];
282
+ if (p === '\\') {
283
+ bsCount++;
284
+ }
285
+ else if (p === '"') {
286
+ result += repeatText('\\', bsCount * 2 + 1);
287
+ result += '"';
288
+ bsCount = 0;
289
+ }
290
+ else {
291
+ result += repeatText('\\', bsCount);
292
+ bsCount = 0;
293
+ result += p;
294
+ }
295
+ }
296
+ if (quote) {
297
+ result += repeatText('\\', bsCount * 2);
298
+ result += '\"';
299
+ }
300
+ else {
301
+ result += repeatText('\\', bsCount);
302
+ }
303
+ }
304
+ return result;
305
+ }
306
+ exports.argsToCommandLine = argsToCommandLine;
307
+ function isCommandLine(args) {
308
+ return typeof args === 'string';
309
+ }
310
+ function repeatText(text, count) {
311
+ var result = '';
312
+ for (var i = 0; i < count; i++) {
313
+ result += text;
314
+ }
315
+ return result;
316
+ }
317
+ function xOr(arg1, arg2) {
318
+ return ((arg1 && !arg2) || (!arg1 && arg2));
319
+ }
320
+ //# sourceMappingURL=windowsPtyAgent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"windowsPtyAgent.js","sourceRoot":"","s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Z,MAAM,IAAI,CAAC,CAAC;aACb;SACF;QACD,IAAI,KAAK,EAAE;YACT,MAAM,IAAI,UAAU,CAAC,IAAI,EAAE,OAAO,GAAG,CAAC,CAAC,CAAC;YACxC,MAAM,IAAI,IAAI,CAAC;SAChB;aAAM;YACL,MAAM,IAAI,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;SACrC;KACF;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAlDD,8CAkDC;AAED,SAAS,aAAa,CAAC,IAAuB;IAC5C,OAAO,OAAO,IAAI,KAAK,QAAQ,CAAC;AAClC,CAAC;AAED,SAAS,UAAU,CAAC,IAAY,EAAE,KAAa;IAC7C,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE;QAC9B,MAAM,IAAI,IAAI,CAAC;KAChB;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,GAAG,CAAC,IAAa,EAAE,IAAa;IACvC,OAAO,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC;AAC9C,CAAC"}
@@ -0,0 +1,90 @@
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
+ var assert = require("assert");
8
+ var windowsPtyAgent_1 = require("./windowsPtyAgent");
9
+ function check(file, args, expected) {
10
+ assert.equal(windowsPtyAgent_1.argsToCommandLine(file, args), expected);
11
+ }
12
+ if (process.platform === 'win32') {
13
+ describe('argsToCommandLine', function () {
14
+ describe('Plain strings', function () {
15
+ it('doesn\'t quote plain string', function () {
16
+ check('asdf', [], 'asdf');
17
+ });
18
+ it('doesn\'t escape backslashes', function () {
19
+ check('\\asdf\\qwer\\', [], '\\asdf\\qwer\\');
20
+ });
21
+ it('doesn\'t escape multiple backslashes', function () {
22
+ check('asdf\\\\qwer', [], 'asdf\\\\qwer');
23
+ });
24
+ it('adds backslashes before quotes', function () {
25
+ check('"asdf"qwer"', [], '\\"asdf\\"qwer\\"');
26
+ });
27
+ it('escapes backslashes before quotes', function () {
28
+ check('asdf\\"qwer', [], 'asdf\\\\\\"qwer');
29
+ });
30
+ });
31
+ describe('Quoted strings', function () {
32
+ it('quotes string with spaces', function () {
33
+ check('asdf qwer', [], '"asdf qwer"');
34
+ });
35
+ it('quotes empty string', function () {
36
+ check('', [], '""');
37
+ });
38
+ it('quotes string with tabs', function () {
39
+ check('asdf\tqwer', [], '"asdf\tqwer"');
40
+ });
41
+ it('escapes only the last backslash', function () {
42
+ check('\\asdf \\qwer\\', [], '"\\asdf \\qwer\\\\"');
43
+ });
44
+ it('doesn\'t escape multiple backslashes', function () {
45
+ check('asdf \\\\qwer', [], '"asdf \\\\qwer"');
46
+ });
47
+ it('escapes backslashes before quotes', function () {
48
+ check('asdf \\"qwer', [], '"asdf \\\\\\"qwer"');
49
+ });
50
+ it('escapes multiple backslashes at the end', function () {
51
+ check('asdf qwer\\\\', [], '"asdf qwer\\\\\\\\"');
52
+ });
53
+ });
54
+ describe('Multiple arguments', function () {
55
+ it('joins arguments with spaces', function () {
56
+ check('asdf', ['qwer zxcv', '', '"'], 'asdf "qwer zxcv" "" \\"');
57
+ });
58
+ it('array argument all in quotes', function () {
59
+ check('asdf', ['"surounded by quotes"'], 'asdf \\"surounded by quotes\\"');
60
+ });
61
+ it('array argument quotes in the middle', function () {
62
+ check('asdf', ['quotes "in the" middle'], 'asdf "quotes \\"in the\\" middle"');
63
+ });
64
+ it('array argument quotes near start', function () {
65
+ check('asdf', ['"quotes" near start'], 'asdf "\\"quotes\\" near start"');
66
+ });
67
+ it('array argument quotes near end', function () {
68
+ check('asdf', ['quotes "near end"'], 'asdf "quotes \\"near end\\""');
69
+ });
70
+ });
71
+ describe('Args as CommandLine', function () {
72
+ it('should handle empty string', function () {
73
+ check('file', '', 'file');
74
+ });
75
+ it('should not change args', function () {
76
+ check('file', 'foo bar baz', 'file foo bar baz');
77
+ check('file', 'foo \\ba"r \baz', 'file foo \\ba"r \baz');
78
+ });
79
+ });
80
+ describe('Real-world cases', function () {
81
+ it('quotes within quotes', function () {
82
+ check('cmd.exe', ['/c', 'powershell -noexit -command \'Set-location \"C:\\user\"\''], 'cmd.exe /c "powershell -noexit -command \'Set-location \\\"C:\\user\\"\'"');
83
+ });
84
+ it('space within quotes', function () {
85
+ check('cmd.exe', ['/k', '"C:\\Users\\alros\\Desktop\\test script.bat"'], 'cmd.exe /k \\"C:\\Users\\alros\\Desktop\\test script.bat\\"');
86
+ });
87
+ });
88
+ });
89
+ }
90
+ //# sourceMappingURL=windowsPtyAgent.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"windowsPtyAgent.test.js","sourceRoot":"","sources":["../src/windowsPtyAgent.test.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAEH,+BAAiC;AACjC,qDAAsD;AAEtD,SAAS,KAAK,CAAC,IAAY,EAAE,IAAuB,EAAE,QAAgB;IACpE,MAAM,CAAC,KAAK,CAAC,mCAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,QAAQ,CAAC,CAAC;AACxD,CAAC;AAED,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE;IAChC,QAAQ,CAAC,mBAAmB,EAAE;QAC5B,QAAQ,CAAC,eAAe,EAAE;YACxB,EAAE,CAAC,6BAA6B,EAAE;gBAChC,KAAK,CAAC,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC;YAC5B,CAAC,CAAC,CAAC;YACH,EAAE,CAAC,6BAA6B,EAAE;gBAChC,KAAK,CAAC,gBAAgB,EAAE,EAAE,EAAE,gBAAgB,CAAC,CAAC;YAChD,CAAC,CAAC,CAAC;YACH,EAAE,CAAC,sCAAsC,EAAE;gBACzC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AE,2DAA2D,CAAC,EAAE,2EAA2E,CAAC,CAAC;YACrK,CAAC,CAAC,CAAC;YACH,EAAE,CAAC,qBAAqB,EAAE;gBACxB,KAAK,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,8CAA8C,CAAC,EAAE,6DAA6D,CAAC,CAAC;YAC1I,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;CACJ"}
@@ -0,0 +1,199 @@
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
+ var __extends = (this && this.__extends) || (function () {
8
+ var extendStatics = function (d, b) {
9
+ extendStatics = Object.setPrototypeOf ||
10
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
11
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
12
+ return extendStatics(d, b);
13
+ };
14
+ return function (d, b) {
15
+ extendStatics(d, b);
16
+ function __() { this.constructor = d; }
17
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
18
+ };
19
+ })();
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.WindowsTerminal = void 0;
22
+ var terminal_1 = require("./terminal");
23
+ var windowsPtyAgent_1 = require("./windowsPtyAgent");
24
+ var utils_1 = require("./utils");
25
+ var DEFAULT_FILE = 'cmd.exe';
26
+ var DEFAULT_NAME = 'Windows Shell';
27
+ var WindowsTerminal = /** @class */ (function (_super) {
28
+ __extends(WindowsTerminal, _super);
29
+ function WindowsTerminal(file, args, opt) {
30
+ var _this = _super.call(this, opt) || this;
31
+ _this._checkType('args', args, 'string', true);
32
+ // Initialize arguments
33
+ args = args || [];
34
+ file = file || DEFAULT_FILE;
35
+ opt = opt || {};
36
+ opt.env = opt.env || process.env;
37
+ if (opt.encoding) {
38
+ console.warn('Setting encoding on Windows is not supported');
39
+ }
40
+ var env = utils_1.assign({}, opt.env);
41
+ _this._cols = opt.cols || terminal_1.DEFAULT_COLS;
42
+ _this._rows = opt.rows || terminal_1.DEFAULT_ROWS;
43
+ var cwd = opt.cwd || process.cwd();
44
+ var name = opt.name || env.TERM || DEFAULT_NAME;
45
+ var parsedEnv = _this._parseEnv(env);
46
+ // If the terminal is ready
47
+ _this._isReady = false;
48
+ // Functions that need to run after `ready` event is emitted.
49
+ _this._deferreds = [];
50
+ // Create new termal.
51
+ _this._agent = new windowsPtyAgent_1.WindowsPtyAgent(file, args, parsedEnv, cwd, _this._cols, _this._rows, false, opt.useConpty, opt.useConptyDll, opt.conptyInheritCursor);
52
+ _this._socket = _this._agent.outSocket;
53
+ // Not available until `ready` event emitted.
54
+ _this._pid = _this._agent.innerPid;
55
+ _this._fd = _this._agent.fd;
56
+ _this._pty = _this._agent.pty;
57
+ // The forked windows terminal is not available until `ready` event is
58
+ // emitted.
59
+ _this._socket.on('ready_datapipe', function () {
60
+ // Run deferreds and set ready state once the first data event is received.
61
+ _this._socket.once('data', function () {
62
+ // Wait until the first data event is fired then we can run deferreds.
63
+ if (!_this._isReady) {
64
+ // Terminal is now ready and we can avoid having to defer method
65
+ // calls.
66
+ _this._isReady = true;
67
+ // Execute all deferred methods
68
+ _this._deferreds.forEach(function (fn) {
69
+ // NB! In order to ensure that `this` has all its references
70
+ // updated any variable that need to be available in `this` before
71
+ // the deferred is run has to be declared above this forEach
72
+ // statement.
73
+ fn.run();
74
+ });
75
+ // Reset
76
+ _this._deferreds = [];
77
+ }
78
+ });
79
+ // Shutdown if `error` event is emitted.
80
+ _this._socket.on('error', function (err) {
81
+ // Close terminal session.
82
+ _this._close();
83
+ // EIO, happens when someone closes our child process: the only process
84
+ // in the terminal.
85
+ // node < 0.6.14: errno 5
86
+ // node >= 0.6.14: read EIO
87
+ if (err.code) {
88
+ if (~err.code.indexOf('errno 5') || ~err.code.indexOf('EIO'))
89
+ return;
90
+ }
91
+ // Throw anything else.
92
+ if (_this.listeners('error').length < 2) {
93
+ throw err;
94
+ }
95
+ });
96
+ // Cleanup after the socket is closed.
97
+ _this._socket.on('close', function () {
98
+ _this.emit('exit', _this._agent.exitCode);
99
+ _this._close();
100
+ });
101
+ });
102
+ _this._file = file;
103
+ _this._name = name;
104
+ _this._readable = true;
105
+ _this._writable = true;
106
+ _this._forwardEvents();
107
+ return _this;
108
+ }
109
+ WindowsTerminal.prototype._write = function (data) {
110
+ this._defer(this._doWrite, data);
111
+ };
112
+ WindowsTerminal.prototype._doWrite = function (data) {
113
+ this._agent.inSocket.write(data);
114
+ };
115
+ /**
116
+ * openpty
117
+ */
118
+ WindowsTerminal.open = function (options) {
119
+ throw new Error('open() not supported on windows, use Fork() instead.');
120
+ };
121
+ /**
122
+ * TTY
123
+ */
124
+ WindowsTerminal.prototype.resize = function (cols, rows) {
125
+ var _this = this;
126
+ if (cols <= 0 || rows <= 0 || isNaN(cols) || isNaN(rows) || cols === Infinity || rows === Infinity) {
127
+ throw new Error('resizing must be done using positive cols and rows');
128
+ }
129
+ this._deferNoArgs(function () {
130
+ _this._agent.resize(cols, rows);
131
+ _this._cols = cols;
132
+ _this._rows = rows;
133
+ });
134
+ };
135
+ WindowsTerminal.prototype.clear = function () {
136
+ var _this = this;
137
+ this._deferNoArgs(function () {
138
+ _this._agent.clear();
139
+ });
140
+ };
141
+ WindowsTerminal.prototype.destroy = function () {
142
+ var _this = this;
143
+ this._deferNoArgs(function () {
144
+ _this.kill();
145
+ });
146
+ };
147
+ WindowsTerminal.prototype.kill = function (signal) {
148
+ var _this = this;
149
+ this._deferNoArgs(function () {
150
+ if (signal) {
151
+ throw new Error('Signals not supported on windows.');
152
+ }
153
+ _this._close();
154
+ _this._agent.kill();
155
+ });
156
+ };
157
+ WindowsTerminal.prototype._deferNoArgs = function (deferredFn) {
158
+ var _this = this;
159
+ // If the terminal is ready, execute.
160
+ if (this._isReady) {
161
+ deferredFn.call(this);
162
+ return;
163
+ }
164
+ // Queue until terminal is ready.
165
+ this._deferreds.push({
166
+ run: function () { return deferredFn.call(_this); }
167
+ });
168
+ };
169
+ WindowsTerminal.prototype._defer = function (deferredFn, arg) {
170
+ var _this = this;
171
+ // If the terminal is ready, execute.
172
+ if (this._isReady) {
173
+ deferredFn.call(this, arg);
174
+ return;
175
+ }
176
+ // Queue until terminal is ready.
177
+ this._deferreds.push({
178
+ run: function () { return deferredFn.call(_this, arg); }
179
+ });
180
+ };
181
+ Object.defineProperty(WindowsTerminal.prototype, "process", {
182
+ get: function () { return this._name; },
183
+ enumerable: false,
184
+ configurable: true
185
+ });
186
+ Object.defineProperty(WindowsTerminal.prototype, "master", {
187
+ get: function () { throw new Error('master is not supported on Windows'); },
188
+ enumerable: false,
189
+ configurable: true
190
+ });
191
+ Object.defineProperty(WindowsTerminal.prototype, "slave", {
192
+ get: function () { throw new Error('slave is not supported on Windows'); },
193
+ enumerable: false,
194
+ configurable: true
195
+ });
196
+ return WindowsTerminal;
197
+ }(terminal_1.Terminal));
198
+ exports.WindowsTerminal = WindowsTerminal;
199
+ //# sourceMappingURL=windowsTerminal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"windowsTerminal.js","sourceRoot":"","sources":["../src/windowsTerminal.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;;;;;AAGH,uCAAkE;AAClE,qDAAoD;AAGpD,iCAAiC;AAEjC,IAAM,YAAY,GAAG,SAAS,CAAC;AAC/B,IAAM,YAAY,GAAG,eAAe,CAAC;AAErC;IAAqC,mCAAQ;IAK3C,yBAAY,IAAa,EAAE,IAAwB,EAAE,GAA4B;QAAjF,YACE,kBAAM,GAAG,CAAC,SAgGX;QA9FC,KAAI,CAAC,UAAU,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;QAE9C,uBAAuB;QACvB,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;QAClB,IAAI,GAAG,IAA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