@theia/process 1.48.0 → 1.48.1
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/README.md +30 -30
- package/lib/common/process-common-module.d.ts +3 -3
- package/lib/common/process-common-module.js +22 -22
- package/lib/common/process-manager-types.d.ts +35 -35
- package/lib/common/process-manager-types.js +23 -23
- package/lib/common/shell-command-builder.d.ts +49 -49
- package/lib/common/shell-command-builder.js +169 -169
- package/lib/common/shell-command-builder.slow-spec.d.ts +9 -9
- package/lib/common/shell-command-builder.slow-spec.js +404 -404
- package/lib/common/shell-quoting.d.ts +91 -91
- package/lib/common/shell-quoting.js +145 -145
- package/lib/common/shell-quoting.spec.d.ts +1 -1
- package/lib/common/shell-quoting.spec.js +170 -170
- package/lib/node/dev-null-stream.d.ts +17 -17
- package/lib/node/dev-null-stream.js +41 -41
- package/lib/node/index.d.ts +6 -6
- package/lib/node/index.js +24 -24
- package/lib/node/multi-ring-buffer.d.ts +68 -68
- package/lib/node/multi-ring-buffer.js +299 -299
- package/lib/node/multi-ring-buffer.spec.d.ts +1 -1
- package/lib/node/multi-ring-buffer.spec.js +422 -422
- package/lib/node/process-backend-module.d.ts +3 -3
- package/lib/node/process-backend-module.js +56 -56
- package/lib/node/process-manager.d.ts +33 -33
- package/lib/node/process-manager.js +102 -102
- package/lib/node/process.d.ts +95 -95
- package/lib/node/process.js +142 -142
- package/lib/node/pseudo-pty.d.ts +22 -22
- package/lib/node/pseudo-pty.js +38 -38
- package/lib/node/raw-process.d.ts +45 -45
- package/lib/node/raw-process.js +104 -104
- package/lib/node/raw-process.spec.d.ts +1 -1
- package/lib/node/raw-process.spec.js +164 -164
- package/lib/node/task-terminal-process.d.ts +10 -10
- package/lib/node/task-terminal-process.js +42 -42
- package/lib/node/terminal-process.d.ts +60 -60
- package/lib/node/terminal-process.js +248 -248
- package/lib/node/terminal-process.spec.d.ts +1 -1
- package/lib/node/terminal-process.spec.js +103 -103
- package/lib/node/test/process-test-container.d.ts +2 -2
- package/lib/node/test/process-test-container.js +28 -28
- package/lib/node/utils.d.ts +16 -16
- package/lib/node/utils.js +77 -77
- package/package.json +4 -4
- package/src/common/process-common-module.ts +22 -22
- package/src/common/process-manager-types.ts +58 -58
- package/src/common/shell-command-builder.slow-spec.ts +486 -486
- package/src/common/shell-command-builder.ts +187 -187
- package/src/common/shell-quoting.spec.ts +176 -176
- package/src/common/shell-quoting.ts +236 -236
- package/src/common/tests/$weird(),file=name.js +1 -1
- package/src/common/tests/white space.js +1 -1
- package/src/node/dev-null-stream.ts +47 -47
- package/src/node/index.ts +22 -22
- package/src/node/multi-ring-buffer.spec.ts +486 -486
- package/src/node/multi-ring-buffer.ts +348 -348
- package/src/node/process-backend-module.ts +67 -67
- package/src/node/process-manager.ts +107 -107
- package/src/node/process.ts +207 -207
- package/src/node/pseudo-pty.ts +54 -54
- package/src/node/raw-process.spec.ts +199 -199
- package/src/node/raw-process.ts +156 -156
- package/src/node/string-argv.d.ts +21 -21
- package/src/node/task-terminal-process.ts +41 -41
- package/src/node/terminal-process.spec.ts +121 -121
- package/src/node/terminal-process.ts +290 -290
- package/src/node/test/process-fork-test.js +22 -22
- package/src/node/test/process-test-container.ts +27 -27
- package/src/node/utils.ts +79 -79
|
@@ -1,249 +1,249 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// *****************************************************************************
|
|
3
|
-
// Copyright (C) 2017 Ericsson and others.
|
|
4
|
-
//
|
|
5
|
-
// This program and the accompanying materials are made available under the
|
|
6
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
-
//
|
|
9
|
-
// This Source Code may also be made available under the following Secondary
|
|
10
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
-
// with the GNU Classpath Exception which is available at
|
|
13
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
-
//
|
|
15
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
-
// *****************************************************************************
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.TerminalProcess = exports.NodePtyErrors = exports.TerminalProcessFactory = exports.TerminalProcessOptions = void 0;
|
|
19
|
-
const tslib_1 = require("tslib");
|
|
20
|
-
const inversify_1 = require("@theia/core/shared/inversify");
|
|
21
|
-
const core_1 = require("@theia/core");
|
|
22
|
-
const common_1 = require("@theia/core/lib/common");
|
|
23
|
-
const process_1 = require("./process");
|
|
24
|
-
const process_manager_1 = require("./process-manager");
|
|
25
|
-
const node_pty_1 = require("node-pty");
|
|
26
|
-
const multi_ring_buffer_1 = require("./multi-ring-buffer");
|
|
27
|
-
const dev_null_stream_1 = require("./dev-null-stream");
|
|
28
|
-
const utils_1 = require("./utils");
|
|
29
|
-
const pseudo_pty_1 = require("./pseudo-pty");
|
|
30
|
-
const stream_1 = require("stream");
|
|
31
|
-
exports.TerminalProcessOptions = Symbol('TerminalProcessOptions');
|
|
32
|
-
exports.TerminalProcessFactory = Symbol('TerminalProcessFactory');
|
|
33
|
-
var NodePtyErrors;
|
|
34
|
-
(function (NodePtyErrors) {
|
|
35
|
-
NodePtyErrors["EACCES"] = "Permission denied";
|
|
36
|
-
NodePtyErrors["ENOENT"] = "No such file or directory";
|
|
37
|
-
})(NodePtyErrors = exports.NodePtyErrors || (exports.NodePtyErrors = {}));
|
|
38
|
-
/**
|
|
39
|
-
* Run arbitrary processes inside pseudo-terminals (PTY).
|
|
40
|
-
*
|
|
41
|
-
* Note: a PTY is not a shell process (bash/pwsh/cmd...)
|
|
42
|
-
*/
|
|
43
|
-
let TerminalProcess = class TerminalProcess extends process_1.Process {
|
|
44
|
-
constructor(// eslint-disable-next-line @typescript-eslint/indent
|
|
45
|
-
options, processManager, ringBuffer, logger) {
|
|
46
|
-
super(processManager, logger, process_1.ProcessType.Terminal, options);
|
|
47
|
-
this.options = options;
|
|
48
|
-
this.ringBuffer = ringBuffer;
|
|
49
|
-
this.outputStream = this.createOutputStream();
|
|
50
|
-
this.errorStream = new dev_null_stream_1.DevNullStream({ autoDestroy: true });
|
|
51
|
-
if (options.isPseudo) {
|
|
52
|
-
// do not need to spawn a process, new a pseudo pty instead
|
|
53
|
-
this.terminal = new pseudo_pty_1.PseudoPty();
|
|
54
|
-
this.inputStream = new dev_null_stream_1.DevNullStream({ autoDestroy: true });
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
if (this.isForkOptions(this.options)) {
|
|
58
|
-
throw new Error('terminal processes cannot be forked as of today');
|
|
59
|
-
}
|
|
60
|
-
this.logger.debug('Starting terminal process', JSON.stringify(options, undefined, 2));
|
|
61
|
-
// Delay resizes to avoid conpty not respecting very early resize calls
|
|
62
|
-
// see https://github.com/microsoft/vscode/blob/a1c783c/src/vs/platform/terminal/node/terminalProcess.ts#L177
|
|
63
|
-
if (core_1.isWindows) {
|
|
64
|
-
this._delayedResizer = new DelayedResizer();
|
|
65
|
-
this._delayedResizer.onTrigger(dimensions => {
|
|
66
|
-
var _a;
|
|
67
|
-
(_a = this._delayedResizer) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
68
|
-
this._delayedResizer = undefined;
|
|
69
|
-
if (dimensions.cols && dimensions.rows) {
|
|
70
|
-
this.resize(dimensions.cols, dimensions.rows);
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
const startTerminal = (command) => {
|
|
75
|
-
try {
|
|
76
|
-
return this.createPseudoTerminal(command, options, ringBuffer);
|
|
77
|
-
}
|
|
78
|
-
catch (error) {
|
|
79
|
-
// Normalize the error to make it as close as possible as what
|
|
80
|
-
// node's child_process.spawn would generate in the same
|
|
81
|
-
// situation.
|
|
82
|
-
const message = error.message;
|
|
83
|
-
if (message.startsWith('File not found: ') || message.endsWith(NodePtyErrors.ENOENT)) {
|
|
84
|
-
if (core_1.isWindows && command && !command.toLowerCase().endsWith('.exe')) {
|
|
85
|
-
const commandExe = command + '.exe';
|
|
86
|
-
this.logger.debug(`Trying terminal command '${commandExe}' because '${command}' was not found.`);
|
|
87
|
-
return startTerminal(commandExe);
|
|
88
|
-
}
|
|
89
|
-
// Proceed with failure, reporting the original command because it was
|
|
90
|
-
// the intended command and it was not found
|
|
91
|
-
error.errno = 'ENOENT';
|
|
92
|
-
error.code = 'ENOENT';
|
|
93
|
-
error.path = options.command;
|
|
94
|
-
}
|
|
95
|
-
else if (message.endsWith(NodePtyErrors.EACCES)) {
|
|
96
|
-
// The shell program exists but was not accessible, so just fail
|
|
97
|
-
error.errno = 'EACCES';
|
|
98
|
-
error.code = 'EACCES';
|
|
99
|
-
error.path = options.command;
|
|
100
|
-
}
|
|
101
|
-
// node-pty throws exceptions on Windows.
|
|
102
|
-
// Call the client error handler, but first give them a chance to register it.
|
|
103
|
-
this.emitOnErrorAsync(error);
|
|
104
|
-
return { terminal: undefined, inputStream: new dev_null_stream_1.DevNullStream({ autoDestroy: true }) };
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
const { terminal, inputStream } = startTerminal(options.command);
|
|
108
|
-
this.terminal = terminal;
|
|
109
|
-
this.inputStream = inputStream;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Helper for the constructor to attempt to create the pseudo-terminal encapsulating the shell process.
|
|
113
|
-
*
|
|
114
|
-
* @param command the shell command to launch
|
|
115
|
-
* @param options options for the shell process
|
|
116
|
-
* @param ringBuffer a ring buffer in which to collect terminal output
|
|
117
|
-
* @returns the terminal PTY and a stream by which it may be sent input
|
|
118
|
-
*/
|
|
119
|
-
createPseudoTerminal(command, options, ringBuffer) {
|
|
120
|
-
const terminal = (0, node_pty_1.spawn)(command, (core_1.isWindows && options.commandLine) || options.args || [], options.options || {});
|
|
121
|
-
process.nextTick(() => this.emitOnStarted());
|
|
122
|
-
// node-pty actually wait for the underlying streams to be closed before emitting exit.
|
|
123
|
-
// We should emulate the `exit` and `close` sequence.
|
|
124
|
-
terminal.onExit(({ exitCode, signal }) => {
|
|
125
|
-
// Make sure to only pass either code or signal as !undefined, not
|
|
126
|
-
// both.
|
|
127
|
-
//
|
|
128
|
-
// node-pty quirk: On Linux/macOS, if the process exited through the
|
|
129
|
-
// exit syscall (with an exit code), signal will be 0 (an invalid
|
|
130
|
-
// signal value). If it was terminated because of a signal, the
|
|
131
|
-
// signal parameter will hold the signal number and code should
|
|
132
|
-
// be ignored.
|
|
133
|
-
this._exitCode = exitCode;
|
|
134
|
-
if (signal === undefined || signal === 0) {
|
|
135
|
-
this.onTerminalExit(exitCode, undefined);
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
this.onTerminalExit(undefined, (0, utils_1.signame)(signal));
|
|
139
|
-
}
|
|
140
|
-
process.nextTick(() => {
|
|
141
|
-
if (signal === undefined || signal === 0) {
|
|
142
|
-
this.emitOnClose(exitCode, undefined);
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
this.emitOnClose(undefined, (0, utils_1.signame)(signal));
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
terminal.onData((data) => {
|
|
150
|
-
ringBuffer.enq(data);
|
|
151
|
-
});
|
|
152
|
-
const inputStream = new stream_1.Writable({
|
|
153
|
-
write: (chunk) => {
|
|
154
|
-
this.write(chunk);
|
|
155
|
-
},
|
|
156
|
-
});
|
|
157
|
-
return { terminal, inputStream };
|
|
158
|
-
}
|
|
159
|
-
createOutputStream() {
|
|
160
|
-
return this.ringBuffer.getStream();
|
|
161
|
-
}
|
|
162
|
-
get pid() {
|
|
163
|
-
this.checkTerminal();
|
|
164
|
-
return this.terminal.pid;
|
|
165
|
-
}
|
|
166
|
-
get executable() {
|
|
167
|
-
return this.options.command;
|
|
168
|
-
}
|
|
169
|
-
get arguments() {
|
|
170
|
-
return this.options.args || [];
|
|
171
|
-
}
|
|
172
|
-
onTerminalExit(code, signal) {
|
|
173
|
-
this.emitOnExit(code, signal);
|
|
174
|
-
this.unregisterProcess();
|
|
175
|
-
}
|
|
176
|
-
unregisterProcess() {
|
|
177
|
-
this.processManager.unregister(this);
|
|
178
|
-
}
|
|
179
|
-
kill(signal) {
|
|
180
|
-
if (this.terminal && this.killed === false) {
|
|
181
|
-
this.terminal.kill(signal);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
resize(cols, rows) {
|
|
185
|
-
if (typeof cols !== 'number' || typeof rows !== 'number' || isNaN(cols) || isNaN(rows)) {
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
this.checkTerminal();
|
|
189
|
-
try {
|
|
190
|
-
// Ensure that cols and rows are always >= 1, this prevents a native exception in winpty.
|
|
191
|
-
cols = Math.max(cols, 1);
|
|
192
|
-
rows = Math.max(rows, 1);
|
|
193
|
-
// Delay resize if needed
|
|
194
|
-
if (this._delayedResizer) {
|
|
195
|
-
this._delayedResizer.cols = cols;
|
|
196
|
-
this._delayedResizer.rows = rows;
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
this.terminal.resize(cols, rows);
|
|
200
|
-
}
|
|
201
|
-
catch (error) {
|
|
202
|
-
// swallow error if the pty has already exited
|
|
203
|
-
// see also https://github.com/microsoft/vscode/blob/a1c783c/src/vs/platform/terminal/node/terminalProcess.ts#L549
|
|
204
|
-
if (this._exitCode !== undefined &&
|
|
205
|
-
error.message !== 'ioctl(2) failed, EBADF' &&
|
|
206
|
-
error.message !== 'Cannot resize a pty that has already exited') {
|
|
207
|
-
throw error;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
write(data) {
|
|
212
|
-
this.checkTerminal();
|
|
213
|
-
this.terminal.write(data);
|
|
214
|
-
}
|
|
215
|
-
checkTerminal() {
|
|
216
|
-
if (!this.terminal) {
|
|
217
|
-
throw new Error('pty process did not start correctly');
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
TerminalProcess = (0, tslib_1.__decorate)([
|
|
222
|
-
(0, inversify_1.injectable)(),
|
|
223
|
-
(0, tslib_1.__param)(0, (0, inversify_1.inject)(exports.TerminalProcessOptions)),
|
|
224
|
-
(0, tslib_1.__param)(1, (0, inversify_1.inject)(process_manager_1.ProcessManager)),
|
|
225
|
-
(0, tslib_1.__param)(2, (0, inversify_1.inject)(multi_ring_buffer_1.MultiRingBuffer)),
|
|
226
|
-
(0, tslib_1.__param)(3, (0, inversify_1.inject)(common_1.ILogger)),
|
|
227
|
-
(0, tslib_1.__param)(3, (0, inversify_1.named)('process')),
|
|
228
|
-
(0, tslib_1.__metadata)("design:paramtypes", [Object, process_manager_1.ProcessManager,
|
|
229
|
-
multi_ring_buffer_1.MultiRingBuffer, Object])
|
|
230
|
-
], TerminalProcess);
|
|
231
|
-
exports.TerminalProcess = TerminalProcess;
|
|
232
|
-
/**
|
|
233
|
-
* Tracks the latest resize event to be trigger at a later point.
|
|
234
|
-
*/
|
|
235
|
-
class DelayedResizer extends core_1.DisposableCollection {
|
|
236
|
-
constructor() {
|
|
237
|
-
super();
|
|
238
|
-
this._onTrigger = new core_1.Emitter();
|
|
239
|
-
this.push(this._onTrigger);
|
|
240
|
-
this._timeout = setTimeout(() => this._onTrigger.fire({ rows: this.rows, cols: this.cols }), 1000);
|
|
241
|
-
this.push(core_1.Disposable.create(() => clearTimeout(this._timeout)));
|
|
242
|
-
}
|
|
243
|
-
get onTrigger() { return this._onTrigger.event; }
|
|
244
|
-
dispose() {
|
|
245
|
-
super.dispose();
|
|
246
|
-
clearTimeout(this._timeout);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
// *****************************************************************************
|
|
3
|
+
// Copyright (C) 2017 Ericsson and others.
|
|
4
|
+
//
|
|
5
|
+
// This program and the accompanying materials are made available under the
|
|
6
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
+
//
|
|
9
|
+
// This Source Code may also be made available under the following Secondary
|
|
10
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
+
// with the GNU Classpath Exception which is available at
|
|
13
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
+
// *****************************************************************************
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.TerminalProcess = exports.NodePtyErrors = exports.TerminalProcessFactory = exports.TerminalProcessOptions = void 0;
|
|
19
|
+
const tslib_1 = require("tslib");
|
|
20
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
21
|
+
const core_1 = require("@theia/core");
|
|
22
|
+
const common_1 = require("@theia/core/lib/common");
|
|
23
|
+
const process_1 = require("./process");
|
|
24
|
+
const process_manager_1 = require("./process-manager");
|
|
25
|
+
const node_pty_1 = require("node-pty");
|
|
26
|
+
const multi_ring_buffer_1 = require("./multi-ring-buffer");
|
|
27
|
+
const dev_null_stream_1 = require("./dev-null-stream");
|
|
28
|
+
const utils_1 = require("./utils");
|
|
29
|
+
const pseudo_pty_1 = require("./pseudo-pty");
|
|
30
|
+
const stream_1 = require("stream");
|
|
31
|
+
exports.TerminalProcessOptions = Symbol('TerminalProcessOptions');
|
|
32
|
+
exports.TerminalProcessFactory = Symbol('TerminalProcessFactory');
|
|
33
|
+
var NodePtyErrors;
|
|
34
|
+
(function (NodePtyErrors) {
|
|
35
|
+
NodePtyErrors["EACCES"] = "Permission denied";
|
|
36
|
+
NodePtyErrors["ENOENT"] = "No such file or directory";
|
|
37
|
+
})(NodePtyErrors = exports.NodePtyErrors || (exports.NodePtyErrors = {}));
|
|
38
|
+
/**
|
|
39
|
+
* Run arbitrary processes inside pseudo-terminals (PTY).
|
|
40
|
+
*
|
|
41
|
+
* Note: a PTY is not a shell process (bash/pwsh/cmd...)
|
|
42
|
+
*/
|
|
43
|
+
let TerminalProcess = class TerminalProcess extends process_1.Process {
|
|
44
|
+
constructor(// eslint-disable-next-line @typescript-eslint/indent
|
|
45
|
+
options, processManager, ringBuffer, logger) {
|
|
46
|
+
super(processManager, logger, process_1.ProcessType.Terminal, options);
|
|
47
|
+
this.options = options;
|
|
48
|
+
this.ringBuffer = ringBuffer;
|
|
49
|
+
this.outputStream = this.createOutputStream();
|
|
50
|
+
this.errorStream = new dev_null_stream_1.DevNullStream({ autoDestroy: true });
|
|
51
|
+
if (options.isPseudo) {
|
|
52
|
+
// do not need to spawn a process, new a pseudo pty instead
|
|
53
|
+
this.terminal = new pseudo_pty_1.PseudoPty();
|
|
54
|
+
this.inputStream = new dev_null_stream_1.DevNullStream({ autoDestroy: true });
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (this.isForkOptions(this.options)) {
|
|
58
|
+
throw new Error('terminal processes cannot be forked as of today');
|
|
59
|
+
}
|
|
60
|
+
this.logger.debug('Starting terminal process', JSON.stringify(options, undefined, 2));
|
|
61
|
+
// Delay resizes to avoid conpty not respecting very early resize calls
|
|
62
|
+
// see https://github.com/microsoft/vscode/blob/a1c783c/src/vs/platform/terminal/node/terminalProcess.ts#L177
|
|
63
|
+
if (core_1.isWindows) {
|
|
64
|
+
this._delayedResizer = new DelayedResizer();
|
|
65
|
+
this._delayedResizer.onTrigger(dimensions => {
|
|
66
|
+
var _a;
|
|
67
|
+
(_a = this._delayedResizer) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
68
|
+
this._delayedResizer = undefined;
|
|
69
|
+
if (dimensions.cols && dimensions.rows) {
|
|
70
|
+
this.resize(dimensions.cols, dimensions.rows);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
const startTerminal = (command) => {
|
|
75
|
+
try {
|
|
76
|
+
return this.createPseudoTerminal(command, options, ringBuffer);
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
// Normalize the error to make it as close as possible as what
|
|
80
|
+
// node's child_process.spawn would generate in the same
|
|
81
|
+
// situation.
|
|
82
|
+
const message = error.message;
|
|
83
|
+
if (message.startsWith('File not found: ') || message.endsWith(NodePtyErrors.ENOENT)) {
|
|
84
|
+
if (core_1.isWindows && command && !command.toLowerCase().endsWith('.exe')) {
|
|
85
|
+
const commandExe = command + '.exe';
|
|
86
|
+
this.logger.debug(`Trying terminal command '${commandExe}' because '${command}' was not found.`);
|
|
87
|
+
return startTerminal(commandExe);
|
|
88
|
+
}
|
|
89
|
+
// Proceed with failure, reporting the original command because it was
|
|
90
|
+
// the intended command and it was not found
|
|
91
|
+
error.errno = 'ENOENT';
|
|
92
|
+
error.code = 'ENOENT';
|
|
93
|
+
error.path = options.command;
|
|
94
|
+
}
|
|
95
|
+
else if (message.endsWith(NodePtyErrors.EACCES)) {
|
|
96
|
+
// The shell program exists but was not accessible, so just fail
|
|
97
|
+
error.errno = 'EACCES';
|
|
98
|
+
error.code = 'EACCES';
|
|
99
|
+
error.path = options.command;
|
|
100
|
+
}
|
|
101
|
+
// node-pty throws exceptions on Windows.
|
|
102
|
+
// Call the client error handler, but first give them a chance to register it.
|
|
103
|
+
this.emitOnErrorAsync(error);
|
|
104
|
+
return { terminal: undefined, inputStream: new dev_null_stream_1.DevNullStream({ autoDestroy: true }) };
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const { terminal, inputStream } = startTerminal(options.command);
|
|
108
|
+
this.terminal = terminal;
|
|
109
|
+
this.inputStream = inputStream;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Helper for the constructor to attempt to create the pseudo-terminal encapsulating the shell process.
|
|
113
|
+
*
|
|
114
|
+
* @param command the shell command to launch
|
|
115
|
+
* @param options options for the shell process
|
|
116
|
+
* @param ringBuffer a ring buffer in which to collect terminal output
|
|
117
|
+
* @returns the terminal PTY and a stream by which it may be sent input
|
|
118
|
+
*/
|
|
119
|
+
createPseudoTerminal(command, options, ringBuffer) {
|
|
120
|
+
const terminal = (0, node_pty_1.spawn)(command, (core_1.isWindows && options.commandLine) || options.args || [], options.options || {});
|
|
121
|
+
process.nextTick(() => this.emitOnStarted());
|
|
122
|
+
// node-pty actually wait for the underlying streams to be closed before emitting exit.
|
|
123
|
+
// We should emulate the `exit` and `close` sequence.
|
|
124
|
+
terminal.onExit(({ exitCode, signal }) => {
|
|
125
|
+
// Make sure to only pass either code or signal as !undefined, not
|
|
126
|
+
// both.
|
|
127
|
+
//
|
|
128
|
+
// node-pty quirk: On Linux/macOS, if the process exited through the
|
|
129
|
+
// exit syscall (with an exit code), signal will be 0 (an invalid
|
|
130
|
+
// signal value). If it was terminated because of a signal, the
|
|
131
|
+
// signal parameter will hold the signal number and code should
|
|
132
|
+
// be ignored.
|
|
133
|
+
this._exitCode = exitCode;
|
|
134
|
+
if (signal === undefined || signal === 0) {
|
|
135
|
+
this.onTerminalExit(exitCode, undefined);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
this.onTerminalExit(undefined, (0, utils_1.signame)(signal));
|
|
139
|
+
}
|
|
140
|
+
process.nextTick(() => {
|
|
141
|
+
if (signal === undefined || signal === 0) {
|
|
142
|
+
this.emitOnClose(exitCode, undefined);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
this.emitOnClose(undefined, (0, utils_1.signame)(signal));
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
terminal.onData((data) => {
|
|
150
|
+
ringBuffer.enq(data);
|
|
151
|
+
});
|
|
152
|
+
const inputStream = new stream_1.Writable({
|
|
153
|
+
write: (chunk) => {
|
|
154
|
+
this.write(chunk);
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
return { terminal, inputStream };
|
|
158
|
+
}
|
|
159
|
+
createOutputStream() {
|
|
160
|
+
return this.ringBuffer.getStream();
|
|
161
|
+
}
|
|
162
|
+
get pid() {
|
|
163
|
+
this.checkTerminal();
|
|
164
|
+
return this.terminal.pid;
|
|
165
|
+
}
|
|
166
|
+
get executable() {
|
|
167
|
+
return this.options.command;
|
|
168
|
+
}
|
|
169
|
+
get arguments() {
|
|
170
|
+
return this.options.args || [];
|
|
171
|
+
}
|
|
172
|
+
onTerminalExit(code, signal) {
|
|
173
|
+
this.emitOnExit(code, signal);
|
|
174
|
+
this.unregisterProcess();
|
|
175
|
+
}
|
|
176
|
+
unregisterProcess() {
|
|
177
|
+
this.processManager.unregister(this);
|
|
178
|
+
}
|
|
179
|
+
kill(signal) {
|
|
180
|
+
if (this.terminal && this.killed === false) {
|
|
181
|
+
this.terminal.kill(signal);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
resize(cols, rows) {
|
|
185
|
+
if (typeof cols !== 'number' || typeof rows !== 'number' || isNaN(cols) || isNaN(rows)) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
this.checkTerminal();
|
|
189
|
+
try {
|
|
190
|
+
// Ensure that cols and rows are always >= 1, this prevents a native exception in winpty.
|
|
191
|
+
cols = Math.max(cols, 1);
|
|
192
|
+
rows = Math.max(rows, 1);
|
|
193
|
+
// Delay resize if needed
|
|
194
|
+
if (this._delayedResizer) {
|
|
195
|
+
this._delayedResizer.cols = cols;
|
|
196
|
+
this._delayedResizer.rows = rows;
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
this.terminal.resize(cols, rows);
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
// swallow error if the pty has already exited
|
|
203
|
+
// see also https://github.com/microsoft/vscode/blob/a1c783c/src/vs/platform/terminal/node/terminalProcess.ts#L549
|
|
204
|
+
if (this._exitCode !== undefined &&
|
|
205
|
+
error.message !== 'ioctl(2) failed, EBADF' &&
|
|
206
|
+
error.message !== 'Cannot resize a pty that has already exited') {
|
|
207
|
+
throw error;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
write(data) {
|
|
212
|
+
this.checkTerminal();
|
|
213
|
+
this.terminal.write(data);
|
|
214
|
+
}
|
|
215
|
+
checkTerminal() {
|
|
216
|
+
if (!this.terminal) {
|
|
217
|
+
throw new Error('pty process did not start correctly');
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
TerminalProcess = (0, tslib_1.__decorate)([
|
|
222
|
+
(0, inversify_1.injectable)(),
|
|
223
|
+
(0, tslib_1.__param)(0, (0, inversify_1.inject)(exports.TerminalProcessOptions)),
|
|
224
|
+
(0, tslib_1.__param)(1, (0, inversify_1.inject)(process_manager_1.ProcessManager)),
|
|
225
|
+
(0, tslib_1.__param)(2, (0, inversify_1.inject)(multi_ring_buffer_1.MultiRingBuffer)),
|
|
226
|
+
(0, tslib_1.__param)(3, (0, inversify_1.inject)(common_1.ILogger)),
|
|
227
|
+
(0, tslib_1.__param)(3, (0, inversify_1.named)('process')),
|
|
228
|
+
(0, tslib_1.__metadata)("design:paramtypes", [Object, process_manager_1.ProcessManager,
|
|
229
|
+
multi_ring_buffer_1.MultiRingBuffer, Object])
|
|
230
|
+
], TerminalProcess);
|
|
231
|
+
exports.TerminalProcess = TerminalProcess;
|
|
232
|
+
/**
|
|
233
|
+
* Tracks the latest resize event to be trigger at a later point.
|
|
234
|
+
*/
|
|
235
|
+
class DelayedResizer extends core_1.DisposableCollection {
|
|
236
|
+
constructor() {
|
|
237
|
+
super();
|
|
238
|
+
this._onTrigger = new core_1.Emitter();
|
|
239
|
+
this.push(this._onTrigger);
|
|
240
|
+
this._timeout = setTimeout(() => this._onTrigger.fire({ rows: this.rows, cols: this.cols }), 1000);
|
|
241
|
+
this.push(core_1.Disposable.create(() => clearTimeout(this._timeout)));
|
|
242
|
+
}
|
|
243
|
+
get onTrigger() { return this._onTrigger.event; }
|
|
244
|
+
dispose() {
|
|
245
|
+
super.dispose();
|
|
246
|
+
clearTimeout(this._timeout);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
249
|
//# sourceMappingURL=terminal-process.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
2
2
|
//# sourceMappingURL=terminal-process.spec.d.ts.map
|