@theia/process 1.40.1 → 1.41.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/lib/node/terminal-process.d.ts +11 -0
- package/lib/node/terminal-process.d.ts.map +1 -1
- package/lib/node/terminal-process.js +133 -54
- package/lib/node/terminal-process.js.map +1 -1
- package/lib/node/terminal-process.spec.js +14 -0
- package/lib/node/terminal-process.spec.js.map +1 -1
- package/package.json +4 -4
- package/src/node/terminal-process.spec.ts +17 -0
- package/src/node/terminal-process.ts +152 -60
|
@@ -31,11 +31,22 @@ export declare class TerminalProcess extends Process {
|
|
|
31
31
|
protected readonly options: TerminalProcessOptions;
|
|
32
32
|
protected readonly ringBuffer: MultiRingBuffer;
|
|
33
33
|
protected readonly terminal: IPty | undefined;
|
|
34
|
+
private _delayedResizer;
|
|
35
|
+
private _exitCode;
|
|
34
36
|
readonly outputStream: MultiRingBufferReadableStream;
|
|
35
37
|
readonly errorStream: DevNullStream;
|
|
36
38
|
readonly inputStream: Writable;
|
|
37
39
|
constructor(// eslint-disable-next-line @typescript-eslint/indent
|
|
38
40
|
options: TerminalProcessOptions, processManager: ProcessManager, ringBuffer: MultiRingBuffer, logger: ILogger);
|
|
41
|
+
/**
|
|
42
|
+
* Helper for the constructor to attempt to create the pseudo-terminal encapsulating the shell process.
|
|
43
|
+
*
|
|
44
|
+
* @param command the shell command to launch
|
|
45
|
+
* @param options options for the shell process
|
|
46
|
+
* @param ringBuffer a ring buffer in which to collect terminal output
|
|
47
|
+
* @returns the terminal PTY and a stream by which it may be sent input
|
|
48
|
+
*/
|
|
49
|
+
private createPseudoTerminal;
|
|
39
50
|
createOutputStream(): MultiRingBufferReadableStream;
|
|
40
51
|
get pid(): number;
|
|
41
52
|
get executable(): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"terminal-process.d.ts","sourceRoot":"","sources":["../../src/node/terminal-process.ts"],"names":[],"mappings":";AAkBA,OAAO,EAAE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B,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IA6BxC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAKzB,SAAS,CAAC,aAAa,IAAI,IAAI,GAAG,KAAK;CAM1C"}
|
|
@@ -69,64 +69,103 @@ let TerminalProcess = class TerminalProcess extends process_1.Process {
|
|
|
69
69
|
throw new Error('terminal processes cannot be forked as of today');
|
|
70
70
|
}
|
|
71
71
|
this.logger.debug('Starting terminal process', JSON.stringify(options, undefined, 2));
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
// exit syscall (with an exit code), signal will be 0 (an invalid
|
|
83
|
-
// signal value). If it was terminated because of a signal, the
|
|
84
|
-
// signal parameter will hold the signal number and code should
|
|
85
|
-
// be ignored.
|
|
86
|
-
if (signal === undefined || signal === 0) {
|
|
87
|
-
this.onTerminalExit(code, undefined);
|
|
72
|
+
// Delay resizes to avoid conpty not respecting very early resize calls
|
|
73
|
+
// see https://github.com/microsoft/vscode/blob/a1c783c/src/vs/platform/terminal/node/terminalProcess.ts#L177
|
|
74
|
+
if (core_1.isWindows) {
|
|
75
|
+
this._delayedResizer = new DelayedResizer();
|
|
76
|
+
this._delayedResizer.onTrigger(dimensions => {
|
|
77
|
+
var _a;
|
|
78
|
+
(_a = this._delayedResizer) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
79
|
+
this._delayedResizer = undefined;
|
|
80
|
+
if (dimensions.cols && dimensions.rows) {
|
|
81
|
+
this.resize(dimensions.cols, dimensions.rows);
|
|
88
82
|
}
|
|
89
|
-
else {
|
|
90
|
-
this.onTerminalExit(undefined, (0, utils_1.signame)(signal));
|
|
91
|
-
}
|
|
92
|
-
process.nextTick(() => {
|
|
93
|
-
if (signal === undefined || signal === 0) {
|
|
94
|
-
this.emitOnClose(code, undefined);
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
this.emitOnClose(undefined, (0, utils_1.signame)(signal));
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
this.terminal.on('data', (data) => {
|
|
102
|
-
ringBuffer.enq(data);
|
|
103
|
-
});
|
|
104
|
-
this.inputStream = new stream_1.Writable({
|
|
105
|
-
write: (chunk) => {
|
|
106
|
-
this.write(chunk);
|
|
107
|
-
},
|
|
108
83
|
});
|
|
109
84
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
85
|
+
const startTerminal = (command) => {
|
|
86
|
+
try {
|
|
87
|
+
return this.createPseudoTerminal(command, options, ringBuffer);
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
// Normalize the error to make it as close as possible as what
|
|
91
|
+
// node's child_process.spawn would generate in the same
|
|
92
|
+
// situation.
|
|
93
|
+
const message = error.message;
|
|
94
|
+
if (message.startsWith('File not found: ') || message.endsWith(NodePtyErrors.ENOENT)) {
|
|
95
|
+
if (core_1.isWindows && command && !command.toLowerCase().endsWith('.exe')) {
|
|
96
|
+
const commandExe = command + '.exe';
|
|
97
|
+
this.logger.debug(`Trying terminal command '${commandExe}' because '${command}' was not found.`);
|
|
98
|
+
return startTerminal(commandExe);
|
|
99
|
+
}
|
|
100
|
+
// Proceed with failure, reporting the original command because it was
|
|
101
|
+
// the intended command and it was not found
|
|
102
|
+
error.errno = 'ENOENT';
|
|
103
|
+
error.code = 'ENOENT';
|
|
104
|
+
error.path = options.command;
|
|
105
|
+
}
|
|
106
|
+
else if (message.endsWith(NodePtyErrors.EACCES)) {
|
|
107
|
+
// The shell program exists but was not accessible, so just fail
|
|
108
|
+
error.errno = 'EACCES';
|
|
109
|
+
error.code = 'EACCES';
|
|
110
|
+
error.path = options.command;
|
|
111
|
+
}
|
|
112
|
+
// node-pty throws exceptions on Windows.
|
|
113
|
+
// Call the client error handler, but first give them a chance to register it.
|
|
114
|
+
this.emitOnErrorAsync(error);
|
|
115
|
+
return { terminal: undefined, inputStream: new dev_null_stream_1.DevNullStream({ autoDestroy: true }) };
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
const { terminal, inputStream } = startTerminal(options.command);
|
|
119
|
+
this.terminal = terminal;
|
|
120
|
+
this.inputStream = inputStream;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Helper for the constructor to attempt to create the pseudo-terminal encapsulating the shell process.
|
|
124
|
+
*
|
|
125
|
+
* @param command the shell command to launch
|
|
126
|
+
* @param options options for the shell process
|
|
127
|
+
* @param ringBuffer a ring buffer in which to collect terminal output
|
|
128
|
+
* @returns the terminal PTY and a stream by which it may be sent input
|
|
129
|
+
*/
|
|
130
|
+
createPseudoTerminal(command, options, ringBuffer) {
|
|
131
|
+
const terminal = (0, node_pty_1.spawn)(command, (core_1.isWindows && options.commandLine) || options.args || [], options.options || {});
|
|
132
|
+
process.nextTick(() => this.emitOnStarted());
|
|
133
|
+
// node-pty actually wait for the underlying streams to be closed before emitting exit.
|
|
134
|
+
// We should emulate the `exit` and `close` sequence.
|
|
135
|
+
terminal.onExit(({ exitCode, signal }) => {
|
|
136
|
+
// Make sure to only pass either code or signal as !undefined, not
|
|
137
|
+
// both.
|
|
138
|
+
//
|
|
139
|
+
// node-pty quirk: On Linux/macOS, if the process exited through the
|
|
140
|
+
// exit syscall (with an exit code), signal will be 0 (an invalid
|
|
141
|
+
// signal value). If it was terminated because of a signal, the
|
|
142
|
+
// signal parameter will hold the signal number and code should
|
|
143
|
+
// be ignored.
|
|
144
|
+
this._exitCode = exitCode;
|
|
145
|
+
if (signal === undefined || signal === 0) {
|
|
146
|
+
this.onTerminalExit(exitCode, undefined);
|
|
120
147
|
}
|
|
121
|
-
else
|
|
122
|
-
|
|
123
|
-
error.code = 'EACCES';
|
|
124
|
-
error.path = options.command;
|
|
148
|
+
else {
|
|
149
|
+
this.onTerminalExit(undefined, (0, utils_1.signame)(signal));
|
|
125
150
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
151
|
+
process.nextTick(() => {
|
|
152
|
+
if (signal === undefined || signal === 0) {
|
|
153
|
+
this.emitOnClose(exitCode, undefined);
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
this.emitOnClose(undefined, (0, utils_1.signame)(signal));
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
terminal.onData((data) => {
|
|
161
|
+
ringBuffer.enq(data);
|
|
162
|
+
});
|
|
163
|
+
const inputStream = new stream_1.Writable({
|
|
164
|
+
write: (chunk) => {
|
|
165
|
+
this.write(chunk);
|
|
166
|
+
},
|
|
167
|
+
});
|
|
168
|
+
return { terminal, inputStream };
|
|
130
169
|
}
|
|
131
170
|
createOutputStream() {
|
|
132
171
|
return this.ringBuffer.getStream();
|
|
@@ -154,8 +193,31 @@ let TerminalProcess = class TerminalProcess extends process_1.Process {
|
|
|
154
193
|
}
|
|
155
194
|
}
|
|
156
195
|
resize(cols, rows) {
|
|
196
|
+
if (typeof cols !== 'number' || typeof rows !== 'number' || isNaN(cols) || isNaN(rows)) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
157
199
|
this.checkTerminal();
|
|
158
|
-
|
|
200
|
+
try {
|
|
201
|
+
// Ensure that cols and rows are always >= 1, this prevents a native exception in winpty.
|
|
202
|
+
cols = Math.max(cols, 1);
|
|
203
|
+
rows = Math.max(rows, 1);
|
|
204
|
+
// Delay resize if needed
|
|
205
|
+
if (this._delayedResizer) {
|
|
206
|
+
this._delayedResizer.cols = cols;
|
|
207
|
+
this._delayedResizer.rows = rows;
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
this.terminal.resize(cols, rows);
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
// swallow error if the pty has already exited
|
|
214
|
+
// see also https://github.com/microsoft/vscode/blob/a1c783c/src/vs/platform/terminal/node/terminalProcess.ts#L549
|
|
215
|
+
if (this._exitCode !== undefined &&
|
|
216
|
+
error.message !== 'ioctl(2) failed, EBADF' &&
|
|
217
|
+
error.message !== 'Cannot resize a pty that has already exited') {
|
|
218
|
+
throw error;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
159
221
|
}
|
|
160
222
|
write(data) {
|
|
161
223
|
this.checkTerminal();
|
|
@@ -178,4 +240,21 @@ TerminalProcess = __decorate([
|
|
|
178
240
|
multi_ring_buffer_1.MultiRingBuffer, Object])
|
|
179
241
|
], TerminalProcess);
|
|
180
242
|
exports.TerminalProcess = TerminalProcess;
|
|
243
|
+
/**
|
|
244
|
+
* Tracks the latest resize event to be trigger at a later point.
|
|
245
|
+
*/
|
|
246
|
+
class DelayedResizer extends core_1.DisposableCollection {
|
|
247
|
+
constructor() {
|
|
248
|
+
super();
|
|
249
|
+
this._onTrigger = new core_1.Emitter();
|
|
250
|
+
this.push(this._onTrigger);
|
|
251
|
+
this._timeout = setTimeout(() => this._onTrigger.fire({ rows: this.rows, cols: this.cols }), 1000);
|
|
252
|
+
this.push(core_1.Disposable.create(() => clearTimeout(this._timeout)));
|
|
253
|
+
}
|
|
254
|
+
get onTrigger() { return this._onTrigger.event; }
|
|
255
|
+
dispose() {
|
|
256
|
+
super.dispose();
|
|
257
|
+
clearTimeout(this._timeout);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
181
260
|
//# sourceMappingURL=terminal-process.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"terminal-process.js","sourceRoot":"","sources":["../../src/node/terminal-process.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,0CAA0C;AAC1C,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;;;;;;;;;;;;;AAEhF,4DAAyE;AACzE,
|
|
1
|
+
{"version":3,"file":"terminal-process.js","sourceRoot":"","sources":["../../src/node/terminal-process.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,0CAA0C;AAC1C,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;;;;;;;;;;;;;AAEhF,4DAAyE;AACzE,sCAA0F;AAC1F,mDAAiD;AACjD,uCAA0F;AAC1F,uDAAmD;AACnD,uCAAuC;AACvC,2DAAqF;AACrF,uDAAkD;AAClD,mCAAkC;AAClC,6CAAyC;AACzC,mCAAkC;AAErB,QAAA,sBAAsB,GAAG,MAAM,CAAC,wBAAwB,CAAC,CAAC;AAS1D,QAAA,sBAAsB,GAAG,MAAM,CAAC,wBAAwB,CAAC,CAAC;AAKvE,IAAY,aAGX;AAHD,WAAY,aAAa;IACrB,6CAA4B,CAAA;IAC5B,qDAAoC,CAAA;AACxC,CAAC,EAHW,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAGxB;AAED;;;;GAIG;AAEH,IAAa,eAAe,GAA5B,MAAa,eAAgB,SAAQ,iBAAO;IAUxC,YAAa,qDAAqD;IACF,OAA+B,EACnE,cAA8B,EACV,UAA2B,EACpC,MAAe;QAElD,KAAK,CAAC,cAAc,EAAE,MAAM,EAAE,qBAAW,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QALD,YAAO,GAAP,OAAO,CAAwB;QAE/C,eAAU,GAAV,UAAU,CAAiB;QAPlE,iBAAY,GAAG,IAAI,CAAC,kBAAkB,EAAE,CAAC;QACzC,gBAAW,GAAG,IAAI,+BAAa,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,C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FM,gCAAc;QACE,mCAAe;GAblE,eAAe,CAoN3B;AApNY,0CAAe;AAsN5B;;GAEG;AACH,MAAM,cAAe,SAAQ,2BAAoB;IAQ7C;QACI,KAAK,EAAE,CAAC;QAJK,eAAU,GAAG,IAAI,cAAO,EAAoC,CAAC;QAK1E,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC3B,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;QACnG,IAAI,CAAC,IAAI,CAAC,iBAAU,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IACpE,CAAC;IAPD,IAAI,SAAS,KAA8C,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;IASjF,OAAO;QACZ,KAAK,CAAC,OAAO,EAAE,CAAC;QAChB,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAChC,CAAC;CACJ"}
|
|
@@ -40,6 +40,20 @@ describe('TerminalProcess', function () {
|
|
|
40
40
|
});
|
|
41
41
|
expect(error.code).eq('ENOENT');
|
|
42
42
|
});
|
|
43
|
+
it('test implicit .exe (Windows only)', async function () {
|
|
44
|
+
const match = /^(.+)\.exe$/.exec(process.execPath);
|
|
45
|
+
if (!os_1.isWindows || !match) {
|
|
46
|
+
this.skip();
|
|
47
|
+
}
|
|
48
|
+
const command = match[1];
|
|
49
|
+
const args = ['--version'];
|
|
50
|
+
const terminal = await new Promise((resolve, reject) => {
|
|
51
|
+
const proc = terminalProcessFactory({ command, args });
|
|
52
|
+
proc.onExit(resolve);
|
|
53
|
+
proc.onError(reject);
|
|
54
|
+
});
|
|
55
|
+
expect(terminal.code).to.exist;
|
|
56
|
+
});
|
|
43
57
|
it('test error on trying to execute a directory', async function () {
|
|
44
58
|
const error = await new Promise((resolve, reject) => {
|
|
45
59
|
const proc = terminalProcessFactory({ command: __dirname });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"terminal-process.spec.js","sourceRoot":"","sources":["../../src/node/terminal-process.spec.ts"],"names":[],"mappings":";;AAAA,gFAAgF;AAChF,0CAA0C;AAC1C,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;AAChF,6BAA6B;AAC7B,mCAAmC;AACnC,iCAAiC;AACjC,0EAA2E;AAC3E,yDAA4D;AAE5D,kDAAsD;AAEtD;;GAEG;AAEH,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;AAE3B,IAAI,sBAA8C,CAAC;AAEnD,UAAU,CAAC,GAAG,EAAE;IACZ,sBAAsB,GAAG,IAAA,mDAA0B,GAAE,CAAC,GAAG,CAAyB,yCAAsB,CAAC,CAAC;AAC9G,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,iBAAiB,EAAE;IAExB,IAAI,CAAC,OAAO,CAAC,KAAM,CAAC,CAAC;IAErB,EAAE,CAAC,iCAAiC,EAAE,KAAK;QACvC,MAAM,KAAK,GAAG,MAAM,IAAI,OAAO,CAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACnE,MAAM,IAAI,GAAG,sBAAsB,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC,CAAC;YAClE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YACrB,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACtB,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACxB,CAAC,CAA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AAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theia/process",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.41.0",
|
|
4
4
|
"description": "Theia process support.",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@theia/core": "1.
|
|
6
|
+
"@theia/core": "1.41.0",
|
|
7
7
|
"node-pty": "0.11.0-beta17",
|
|
8
8
|
"string-argv": "^0.1.1"
|
|
9
9
|
},
|
|
@@ -44,10 +44,10 @@
|
|
|
44
44
|
"watch": "theiaext watch"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@theia/ext-scripts": "1.
|
|
47
|
+
"@theia/ext-scripts": "1.41.0"
|
|
48
48
|
},
|
|
49
49
|
"nyc": {
|
|
50
50
|
"extends": "../../configs/nyc.json"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "180103ad086fc0a5e4e5fc01b5fcb43f06019eb1"
|
|
53
53
|
}
|
|
@@ -48,6 +48,23 @@ describe('TerminalProcess', function (): void {
|
|
|
48
48
|
expect(error.code).eq('ENOENT');
|
|
49
49
|
});
|
|
50
50
|
|
|
51
|
+
it('test implicit .exe (Windows only)', async function (): Promise<void> {
|
|
52
|
+
const match = /^(.+)\.exe$/.exec(process.execPath);
|
|
53
|
+
if (!isWindows || !match) {
|
|
54
|
+
this.skip();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const command = match[1];
|
|
58
|
+
const args = ['--version'];
|
|
59
|
+
const terminal = await new Promise<IProcessExitEvent>((resolve, reject) => {
|
|
60
|
+
const proc = terminalProcessFactory({ command, args });
|
|
61
|
+
proc.onExit(resolve);
|
|
62
|
+
proc.onError(reject);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
expect(terminal.code).to.exist;
|
|
66
|
+
});
|
|
67
|
+
|
|
51
68
|
it('test error on trying to execute a directory', async function (): Promise<void> {
|
|
52
69
|
const error = await new Promise<ProcessErrorEvent>((resolve, reject) => {
|
|
53
70
|
const proc = terminalProcessFactory({ command: __dirname });
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
// *****************************************************************************
|
|
16
16
|
|
|
17
17
|
import { injectable, inject, named } from '@theia/core/shared/inversify';
|
|
18
|
-
import { isWindows } from '@theia/core';
|
|
18
|
+
import { Disposable, DisposableCollection, Emitter, Event, isWindows } from '@theia/core';
|
|
19
19
|
import { ILogger } from '@theia/core/lib/common';
|
|
20
20
|
import { Process, ProcessType, ProcessOptions, /* ProcessErrorEvent */ } from './process';
|
|
21
21
|
import { ProcessManager } from './process-manager';
|
|
@@ -54,6 +54,8 @@ export enum NodePtyErrors {
|
|
|
54
54
|
export class TerminalProcess extends Process {
|
|
55
55
|
|
|
56
56
|
protected readonly terminal: IPty | undefined;
|
|
57
|
+
private _delayedResizer: DelayedResizer | undefined;
|
|
58
|
+
private _exitCode: number | undefined;
|
|
57
59
|
|
|
58
60
|
readonly outputStream = this.createOutputStream();
|
|
59
61
|
readonly errorStream = new DevNullStream({ autoDestroy: true });
|
|
@@ -79,72 +81,114 @@ export class TerminalProcess extends Process {
|
|
|
79
81
|
}
|
|
80
82
|
this.logger.debug('Starting terminal process', JSON.stringify(options, undefined, 2));
|
|
81
83
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
// node-pty actually wait for the underlying streams to be closed before emitting exit.
|
|
92
|
-
// We should emulate the `exit` and `close` sequence.
|
|
93
|
-
this.terminal.on('exit', (code, signal) => {
|
|
94
|
-
// Make sure to only pass either code or signal as !undefined, not
|
|
95
|
-
// both.
|
|
96
|
-
//
|
|
97
|
-
// node-pty quirk: On Linux/macOS, if the process exited through the
|
|
98
|
-
// exit syscall (with an exit code), signal will be 0 (an invalid
|
|
99
|
-
// signal value). If it was terminated because of a signal, the
|
|
100
|
-
// signal parameter will hold the signal number and code should
|
|
101
|
-
// be ignored.
|
|
102
|
-
if (signal === undefined || signal === 0) {
|
|
103
|
-
this.onTerminalExit(code, undefined);
|
|
104
|
-
} else {
|
|
105
|
-
this.onTerminalExit(undefined, signame(signal));
|
|
84
|
+
// Delay resizes to avoid conpty not respecting very early resize calls
|
|
85
|
+
// see https://github.com/microsoft/vscode/blob/a1c783c/src/vs/platform/terminal/node/terminalProcess.ts#L177
|
|
86
|
+
if (isWindows) {
|
|
87
|
+
this._delayedResizer = new DelayedResizer();
|
|
88
|
+
this._delayedResizer.onTrigger(dimensions => {
|
|
89
|
+
this._delayedResizer?.dispose();
|
|
90
|
+
this._delayedResizer = undefined;
|
|
91
|
+
if (dimensions.cols && dimensions.rows) {
|
|
92
|
+
this.resize(dimensions.cols, dimensions.rows);
|
|
106
93
|
}
|
|
107
|
-
process.nextTick(() => {
|
|
108
|
-
if (signal === undefined || signal === 0) {
|
|
109
|
-
this.emitOnClose(code, undefined);
|
|
110
|
-
} else {
|
|
111
|
-
this.emitOnClose(undefined, signame(signal));
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
94
|
});
|
|
95
|
+
}
|
|
115
96
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
97
|
+
const startTerminal = (command: string): { terminal: IPty | undefined, inputStream: Writable } => {
|
|
98
|
+
try {
|
|
99
|
+
return this.createPseudoTerminal(command, options, ringBuffer);
|
|
100
|
+
} catch (error) {
|
|
101
|
+
// Normalize the error to make it as close as possible as what
|
|
102
|
+
// node's child_process.spawn would generate in the same
|
|
103
|
+
// situation.
|
|
104
|
+
const message: string = error.message;
|
|
119
105
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
106
|
+
if (message.startsWith('File not found: ') || message.endsWith(NodePtyErrors.ENOENT)) {
|
|
107
|
+
if (isWindows && command && !command.toLowerCase().endsWith('.exe')) {
|
|
108
|
+
const commandExe = command + '.exe';
|
|
109
|
+
this.logger.debug(`Trying terminal command '${commandExe}' because '${command}' was not found.`);
|
|
110
|
+
return startTerminal(commandExe);
|
|
111
|
+
}
|
|
125
112
|
|
|
126
|
-
|
|
127
|
-
|
|
113
|
+
// Proceed with failure, reporting the original command because it was
|
|
114
|
+
// the intended command and it was not found
|
|
115
|
+
error.errno = 'ENOENT';
|
|
116
|
+
error.code = 'ENOENT';
|
|
117
|
+
error.path = options.command;
|
|
118
|
+
} else if (message.endsWith(NodePtyErrors.EACCES)) {
|
|
119
|
+
// The shell program exists but was not accessible, so just fail
|
|
120
|
+
error.errno = 'EACCES';
|
|
121
|
+
error.code = 'EACCES';
|
|
122
|
+
error.path = options.command;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// node-pty throws exceptions on Windows.
|
|
126
|
+
// Call the client error handler, but first give them a chance to register it.
|
|
127
|
+
this.emitOnErrorAsync(error);
|
|
128
128
|
|
|
129
|
-
|
|
130
|
-
// node's child_process.spawn would generate in the same
|
|
131
|
-
// situation.
|
|
132
|
-
const message: string = error.message;
|
|
133
|
-
|
|
134
|
-
if (message.startsWith('File not found: ') || message.endsWith(NodePtyErrors.ENOENT)) {
|
|
135
|
-
error.errno = 'ENOENT';
|
|
136
|
-
error.code = 'ENOENT';
|
|
137
|
-
error.path = options.command;
|
|
138
|
-
} else if (message.endsWith(NodePtyErrors.EACCES)) {
|
|
139
|
-
error.errno = 'EACCES';
|
|
140
|
-
error.code = 'EACCES';
|
|
141
|
-
error.path = options.command;
|
|
129
|
+
return { terminal: undefined, inputStream: new DevNullStream({ autoDestroy: true }) };
|
|
142
130
|
}
|
|
131
|
+
};
|
|
143
132
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
133
|
+
const { terminal, inputStream } = startTerminal(options.command);
|
|
134
|
+
this.terminal = terminal;
|
|
135
|
+
this.inputStream = inputStream;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Helper for the constructor to attempt to create the pseudo-terminal encapsulating the shell process.
|
|
140
|
+
*
|
|
141
|
+
* @param command the shell command to launch
|
|
142
|
+
* @param options options for the shell process
|
|
143
|
+
* @param ringBuffer a ring buffer in which to collect terminal output
|
|
144
|
+
* @returns the terminal PTY and a stream by which it may be sent input
|
|
145
|
+
*/
|
|
146
|
+
private createPseudoTerminal(command: string, options: TerminalProcessOptions, ringBuffer: MultiRingBuffer): { terminal: IPty | undefined, inputStream: Writable } {
|
|
147
|
+
const terminal = spawn(
|
|
148
|
+
command,
|
|
149
|
+
(isWindows && options.commandLine) || options.args || [],
|
|
150
|
+
options.options || {}
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
process.nextTick(() => this.emitOnStarted());
|
|
154
|
+
|
|
155
|
+
// node-pty actually wait for the underlying streams to be closed before emitting exit.
|
|
156
|
+
// We should emulate the `exit` and `close` sequence.
|
|
157
|
+
terminal.onExit(({ exitCode, signal }) => {
|
|
158
|
+
// Make sure to only pass either code or signal as !undefined, not
|
|
159
|
+
// both.
|
|
160
|
+
//
|
|
161
|
+
// node-pty quirk: On Linux/macOS, if the process exited through the
|
|
162
|
+
// exit syscall (with an exit code), signal will be 0 (an invalid
|
|
163
|
+
// signal value). If it was terminated because of a signal, the
|
|
164
|
+
// signal parameter will hold the signal number and code should
|
|
165
|
+
// be ignored.
|
|
166
|
+
this._exitCode = exitCode;
|
|
167
|
+
if (signal === undefined || signal === 0) {
|
|
168
|
+
this.onTerminalExit(exitCode, undefined);
|
|
169
|
+
} else {
|
|
170
|
+
this.onTerminalExit(undefined, signame(signal));
|
|
171
|
+
}
|
|
172
|
+
process.nextTick(() => {
|
|
173
|
+
if (signal === undefined || signal === 0) {
|
|
174
|
+
this.emitOnClose(exitCode, undefined);
|
|
175
|
+
} else {
|
|
176
|
+
this.emitOnClose(undefined, signame(signal));
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
terminal.onData((data: string) => {
|
|
182
|
+
ringBuffer.enq(data);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
const inputStream = new Writable({
|
|
186
|
+
write: (chunk: string) => {
|
|
187
|
+
this.write(chunk);
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
return { terminal, inputStream };
|
|
148
192
|
}
|
|
149
193
|
|
|
150
194
|
createOutputStream(): MultiRingBufferReadableStream {
|
|
@@ -180,8 +224,32 @@ export class TerminalProcess extends Process {
|
|
|
180
224
|
}
|
|
181
225
|
|
|
182
226
|
resize(cols: number, rows: number): void {
|
|
227
|
+
if (typeof cols !== 'number' || typeof rows !== 'number' || isNaN(cols) || isNaN(rows)) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
183
230
|
this.checkTerminal();
|
|
184
|
-
|
|
231
|
+
try {
|
|
232
|
+
// Ensure that cols and rows are always >= 1, this prevents a native exception in winpty.
|
|
233
|
+
cols = Math.max(cols, 1);
|
|
234
|
+
rows = Math.max(rows, 1);
|
|
235
|
+
|
|
236
|
+
// Delay resize if needed
|
|
237
|
+
if (this._delayedResizer) {
|
|
238
|
+
this._delayedResizer.cols = cols;
|
|
239
|
+
this._delayedResizer.rows = rows;
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
this.terminal!.resize(cols, rows);
|
|
244
|
+
} catch (error) {
|
|
245
|
+
// swallow error if the pty has already exited
|
|
246
|
+
// see also https://github.com/microsoft/vscode/blob/a1c783c/src/vs/platform/terminal/node/terminalProcess.ts#L549
|
|
247
|
+
if (this._exitCode !== undefined &&
|
|
248
|
+
error.message !== 'ioctl(2) failed, EBADF' &&
|
|
249
|
+
error.message !== 'Cannot resize a pty that has already exited') {
|
|
250
|
+
throw error;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
185
253
|
}
|
|
186
254
|
|
|
187
255
|
write(data: string): void {
|
|
@@ -196,3 +264,27 @@ export class TerminalProcess extends Process {
|
|
|
196
264
|
}
|
|
197
265
|
|
|
198
266
|
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Tracks the latest resize event to be trigger at a later point.
|
|
270
|
+
*/
|
|
271
|
+
class DelayedResizer extends DisposableCollection {
|
|
272
|
+
rows: number | undefined;
|
|
273
|
+
cols: number | undefined;
|
|
274
|
+
private _timeout: NodeJS.Timeout;
|
|
275
|
+
|
|
276
|
+
private readonly _onTrigger = new Emitter<{ rows?: number; cols?: number }>();
|
|
277
|
+
get onTrigger(): Event<{ rows?: number; cols?: number }> { return this._onTrigger.event; }
|
|
278
|
+
|
|
279
|
+
constructor() {
|
|
280
|
+
super();
|
|
281
|
+
this.push(this._onTrigger);
|
|
282
|
+
this._timeout = setTimeout(() => this._onTrigger.fire({ rows: this.rows, cols: this.cols }), 1000);
|
|
283
|
+
this.push(Disposable.create(() => clearTimeout(this._timeout)));
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
override dispose(): void {
|
|
287
|
+
super.dispose();
|
|
288
|
+
clearTimeout(this._timeout);
|
|
289
|
+
}
|
|
290
|
+
}
|