@theia/process 1.34.2 → 1.34.3
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 +641 -641
- 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 +174 -174
- 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 +33 -33
- package/lib/node/multi-ring-buffer.d.ts +68 -68
- package/lib/node/multi-ring-buffer.js +310 -310
- 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 +113 -113
- package/lib/node/process.d.ts +95 -95
- package/lib/node/process.js +153 -153
- 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 +115 -115
- 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 +47 -47
- package/lib/node/terminal-process.d.ts +49 -49
- package/lib/node/terminal-process.js +180 -180
- package/lib/node/terminal-process.spec.d.ts +1 -1
- package/lib/node/terminal-process.spec.js +89 -89
- 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 +104 -104
- package/src/node/terminal-process.ts +198 -198
- 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,198 +1,198 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2017 Ericsson and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import { injectable, inject, named } from '@theia/core/shared/inversify';
|
|
18
|
-
import { isWindows } from '@theia/core';
|
|
19
|
-
import { ILogger } from '@theia/core/lib/common';
|
|
20
|
-
import { Process, ProcessType, ProcessOptions, /* ProcessErrorEvent */ } from './process';
|
|
21
|
-
import { ProcessManager } from './process-manager';
|
|
22
|
-
import { IPty, spawn } from 'node-pty';
|
|
23
|
-
import { MultiRingBuffer, MultiRingBufferReadableStream } from './multi-ring-buffer';
|
|
24
|
-
import { DevNullStream } from './dev-null-stream';
|
|
25
|
-
import { signame } from './utils';
|
|
26
|
-
import { PseudoPty } from './pseudo-pty';
|
|
27
|
-
import { Writable } from 'stream';
|
|
28
|
-
|
|
29
|
-
export const TerminalProcessOptions = Symbol('TerminalProcessOptions');
|
|
30
|
-
export interface TerminalProcessOptions extends ProcessOptions {
|
|
31
|
-
/**
|
|
32
|
-
* Windows only. Allow passing complex command lines already escaped for CommandLineToArgvW.
|
|
33
|
-
*/
|
|
34
|
-
commandLine?: string;
|
|
35
|
-
isPseudo?: boolean;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export const TerminalProcessFactory = Symbol('TerminalProcessFactory');
|
|
39
|
-
export interface TerminalProcessFactory {
|
|
40
|
-
(options: TerminalProcessOptions): TerminalProcess;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export enum NodePtyErrors {
|
|
44
|
-
EACCES = 'Permission denied',
|
|
45
|
-
ENOENT = 'No such file or directory'
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Run arbitrary processes inside pseudo-terminals (PTY).
|
|
50
|
-
*
|
|
51
|
-
* Note: a PTY is not a shell process (bash/pwsh/cmd...)
|
|
52
|
-
*/
|
|
53
|
-
@injectable()
|
|
54
|
-
export class TerminalProcess extends Process {
|
|
55
|
-
|
|
56
|
-
protected readonly terminal: IPty | undefined;
|
|
57
|
-
|
|
58
|
-
readonly outputStream = this.createOutputStream();
|
|
59
|
-
readonly errorStream = new DevNullStream({ autoDestroy: true });
|
|
60
|
-
readonly inputStream: Writable;
|
|
61
|
-
|
|
62
|
-
constructor( // eslint-disable-next-line @typescript-eslint/indent
|
|
63
|
-
@inject(TerminalProcessOptions) protected override readonly options: TerminalProcessOptions,
|
|
64
|
-
@inject(ProcessManager) processManager: ProcessManager,
|
|
65
|
-
@inject(MultiRingBuffer) protected readonly ringBuffer: MultiRingBuffer,
|
|
66
|
-
@inject(ILogger) @named('process') logger: ILogger
|
|
67
|
-
) {
|
|
68
|
-
super(processManager, logger, ProcessType.Terminal, options);
|
|
69
|
-
|
|
70
|
-
if (options.isPseudo) {
|
|
71
|
-
// do not need to spawn a process, new a pseudo pty instead
|
|
72
|
-
this.terminal = new PseudoPty();
|
|
73
|
-
this.inputStream = new DevNullStream({ autoDestroy: true });
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (this.isForkOptions(this.options)) {
|
|
78
|
-
throw new Error('terminal processes cannot be forked as of today');
|
|
79
|
-
}
|
|
80
|
-
this.logger.debug('Starting terminal process', JSON.stringify(options, undefined, 2));
|
|
81
|
-
|
|
82
|
-
try {
|
|
83
|
-
this.terminal = spawn(
|
|
84
|
-
options.command,
|
|
85
|
-
(isWindows && options.commandLine) || options.args || [],
|
|
86
|
-
options.options || {}
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
process.nextTick(() => this.emitOnStarted());
|
|
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));
|
|
106
|
-
}
|
|
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
|
-
});
|
|
115
|
-
|
|
116
|
-
this.terminal.on('data', (data: string) => {
|
|
117
|
-
ringBuffer.enq(data);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
this.inputStream = new Writable({
|
|
121
|
-
write: (chunk: string) => {
|
|
122
|
-
this.write(chunk);
|
|
123
|
-
},
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
} catch (error) {
|
|
127
|
-
this.inputStream = new DevNullStream({ autoDestroy: true });
|
|
128
|
-
|
|
129
|
-
// Normalize the error to make it as close as possible as what
|
|
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;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// node-pty throws exceptions on Windows.
|
|
145
|
-
// Call the client error handler, but first give them a chance to register it.
|
|
146
|
-
this.emitOnErrorAsync(error);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
createOutputStream(): MultiRingBufferReadableStream {
|
|
151
|
-
return this.ringBuffer.getStream();
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
get pid(): number {
|
|
155
|
-
this.checkTerminal();
|
|
156
|
-
return this.terminal!.pid;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
get executable(): string {
|
|
160
|
-
return (this.options as ProcessOptions).command;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
get arguments(): string[] {
|
|
164
|
-
return this.options.args || [];
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
protected onTerminalExit(code: number | undefined, signal: string | undefined): void {
|
|
168
|
-
this.emitOnExit(code, signal);
|
|
169
|
-
this.unregisterProcess();
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
unregisterProcess(): void {
|
|
173
|
-
this.processManager.unregister(this);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
kill(signal?: string): void {
|
|
177
|
-
if (this.terminal && this.killed === false) {
|
|
178
|
-
this.terminal.kill(signal);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
resize(cols: number, rows: number): void {
|
|
183
|
-
this.checkTerminal();
|
|
184
|
-
this.terminal!.resize(cols, rows);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
write(data: string): void {
|
|
188
|
-
this.checkTerminal();
|
|
189
|
-
this.terminal!.write(data);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
protected checkTerminal(): void | never {
|
|
193
|
-
if (!this.terminal) {
|
|
194
|
-
throw new Error('pty process did not start correctly');
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2017 Ericsson and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { injectable, inject, named } from '@theia/core/shared/inversify';
|
|
18
|
+
import { isWindows } from '@theia/core';
|
|
19
|
+
import { ILogger } from '@theia/core/lib/common';
|
|
20
|
+
import { Process, ProcessType, ProcessOptions, /* ProcessErrorEvent */ } from './process';
|
|
21
|
+
import { ProcessManager } from './process-manager';
|
|
22
|
+
import { IPty, spawn } from 'node-pty';
|
|
23
|
+
import { MultiRingBuffer, MultiRingBufferReadableStream } from './multi-ring-buffer';
|
|
24
|
+
import { DevNullStream } from './dev-null-stream';
|
|
25
|
+
import { signame } from './utils';
|
|
26
|
+
import { PseudoPty } from './pseudo-pty';
|
|
27
|
+
import { Writable } from 'stream';
|
|
28
|
+
|
|
29
|
+
export const TerminalProcessOptions = Symbol('TerminalProcessOptions');
|
|
30
|
+
export interface TerminalProcessOptions extends ProcessOptions {
|
|
31
|
+
/**
|
|
32
|
+
* Windows only. Allow passing complex command lines already escaped for CommandLineToArgvW.
|
|
33
|
+
*/
|
|
34
|
+
commandLine?: string;
|
|
35
|
+
isPseudo?: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const TerminalProcessFactory = Symbol('TerminalProcessFactory');
|
|
39
|
+
export interface TerminalProcessFactory {
|
|
40
|
+
(options: TerminalProcessOptions): TerminalProcess;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export enum NodePtyErrors {
|
|
44
|
+
EACCES = 'Permission denied',
|
|
45
|
+
ENOENT = 'No such file or directory'
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Run arbitrary processes inside pseudo-terminals (PTY).
|
|
50
|
+
*
|
|
51
|
+
* Note: a PTY is not a shell process (bash/pwsh/cmd...)
|
|
52
|
+
*/
|
|
53
|
+
@injectable()
|
|
54
|
+
export class TerminalProcess extends Process {
|
|
55
|
+
|
|
56
|
+
protected readonly terminal: IPty | undefined;
|
|
57
|
+
|
|
58
|
+
readonly outputStream = this.createOutputStream();
|
|
59
|
+
readonly errorStream = new DevNullStream({ autoDestroy: true });
|
|
60
|
+
readonly inputStream: Writable;
|
|
61
|
+
|
|
62
|
+
constructor( // eslint-disable-next-line @typescript-eslint/indent
|
|
63
|
+
@inject(TerminalProcessOptions) protected override readonly options: TerminalProcessOptions,
|
|
64
|
+
@inject(ProcessManager) processManager: ProcessManager,
|
|
65
|
+
@inject(MultiRingBuffer) protected readonly ringBuffer: MultiRingBuffer,
|
|
66
|
+
@inject(ILogger) @named('process') logger: ILogger
|
|
67
|
+
) {
|
|
68
|
+
super(processManager, logger, ProcessType.Terminal, options);
|
|
69
|
+
|
|
70
|
+
if (options.isPseudo) {
|
|
71
|
+
// do not need to spawn a process, new a pseudo pty instead
|
|
72
|
+
this.terminal = new PseudoPty();
|
|
73
|
+
this.inputStream = new DevNullStream({ autoDestroy: true });
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (this.isForkOptions(this.options)) {
|
|
78
|
+
throw new Error('terminal processes cannot be forked as of today');
|
|
79
|
+
}
|
|
80
|
+
this.logger.debug('Starting terminal process', JSON.stringify(options, undefined, 2));
|
|
81
|
+
|
|
82
|
+
try {
|
|
83
|
+
this.terminal = spawn(
|
|
84
|
+
options.command,
|
|
85
|
+
(isWindows && options.commandLine) || options.args || [],
|
|
86
|
+
options.options || {}
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
process.nextTick(() => this.emitOnStarted());
|
|
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));
|
|
106
|
+
}
|
|
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
|
+
});
|
|
115
|
+
|
|
116
|
+
this.terminal.on('data', (data: string) => {
|
|
117
|
+
ringBuffer.enq(data);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
this.inputStream = new Writable({
|
|
121
|
+
write: (chunk: string) => {
|
|
122
|
+
this.write(chunk);
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
} catch (error) {
|
|
127
|
+
this.inputStream = new DevNullStream({ autoDestroy: true });
|
|
128
|
+
|
|
129
|
+
// Normalize the error to make it as close as possible as what
|
|
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;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// node-pty throws exceptions on Windows.
|
|
145
|
+
// Call the client error handler, but first give them a chance to register it.
|
|
146
|
+
this.emitOnErrorAsync(error);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
createOutputStream(): MultiRingBufferReadableStream {
|
|
151
|
+
return this.ringBuffer.getStream();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
get pid(): number {
|
|
155
|
+
this.checkTerminal();
|
|
156
|
+
return this.terminal!.pid;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
get executable(): string {
|
|
160
|
+
return (this.options as ProcessOptions).command;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
get arguments(): string[] {
|
|
164
|
+
return this.options.args || [];
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
protected onTerminalExit(code: number | undefined, signal: string | undefined): void {
|
|
168
|
+
this.emitOnExit(code, signal);
|
|
169
|
+
this.unregisterProcess();
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
unregisterProcess(): void {
|
|
173
|
+
this.processManager.unregister(this);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
kill(signal?: string): void {
|
|
177
|
+
if (this.terminal && this.killed === false) {
|
|
178
|
+
this.terminal.kill(signal);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
resize(cols: number, rows: number): void {
|
|
183
|
+
this.checkTerminal();
|
|
184
|
+
this.terminal!.resize(cols, rows);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
write(data: string): void {
|
|
188
|
+
this.checkTerminal();
|
|
189
|
+
this.terminal!.write(data);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
protected checkTerminal(): void | never {
|
|
193
|
+
if (!this.terminal) {
|
|
194
|
+
throw new Error('pty process did not start correctly');
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2018 Arm and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
if (process.argv[2] === 'version') {
|
|
18
|
-
console.log('1.0.0');
|
|
19
|
-
} else {
|
|
20
|
-
process.stderr.write('Error: Argument expected')
|
|
21
|
-
process.exit(1)
|
|
22
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2018 Arm and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
if (process.argv[2] === 'version') {
|
|
18
|
+
console.log('1.0.0');
|
|
19
|
+
} else {
|
|
20
|
+
process.stderr.write('Error: Argument expected')
|
|
21
|
+
process.exit(1)
|
|
22
|
+
}
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2017 Ericsson and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
import { Container } from '@theia/core/shared/inversify';
|
|
17
|
-
import { bindLogger } from '@theia/core/lib/node/logger-backend-module';
|
|
18
|
-
import processBackendModule from '../process-backend-module';
|
|
19
|
-
|
|
20
|
-
export function createProcessTestContainer(): Container {
|
|
21
|
-
const testContainer = new Container();
|
|
22
|
-
|
|
23
|
-
bindLogger(testContainer.bind.bind(testContainer));
|
|
24
|
-
testContainer.load(processBackendModule);
|
|
25
|
-
|
|
26
|
-
return testContainer;
|
|
27
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2017 Ericsson and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
import { Container } from '@theia/core/shared/inversify';
|
|
17
|
+
import { bindLogger } from '@theia/core/lib/node/logger-backend-module';
|
|
18
|
+
import processBackendModule from '../process-backend-module';
|
|
19
|
+
|
|
20
|
+
export function createProcessTestContainer(): Container {
|
|
21
|
+
const testContainer = new Container();
|
|
22
|
+
|
|
23
|
+
bindLogger(testContainer.bind.bind(testContainer));
|
|
24
|
+
testContainer.load(processBackendModule);
|
|
25
|
+
|
|
26
|
+
return testContainer;
|
|
27
|
+
}
|
package/src/node/utils.ts
CHANGED
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2017 TypeFox and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import { isWindows } from '@theia/core';
|
|
18
|
-
import * as os from 'os';
|
|
19
|
-
const stringArgv = require('string-argv');
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Parses the given line into an array of args respecting escapes and string literals.
|
|
23
|
-
* @param line the given line to parse
|
|
24
|
-
*/
|
|
25
|
-
export function parseArgs(line: string | undefined): string[] {
|
|
26
|
-
if (line) {
|
|
27
|
-
return stringArgv(line);
|
|
28
|
-
}
|
|
29
|
-
return [];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Polyfill for Object.entries, until we upgrade to ES2017.
|
|
33
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
|
-
function objectEntries(obj: any): any[] {
|
|
35
|
-
const props = Object.keys(obj);
|
|
36
|
-
const result = new Array(props.length);
|
|
37
|
-
for (let i = 0; i < props.length; i++) {
|
|
38
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
39
|
-
result[i] = [props[i], obj[props[i]]];
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return result;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Convert a signal number to its short name (using the signal definitions of
|
|
47
|
-
* the current host). Should never be called on Windows. For Linux, this is
|
|
48
|
-
* only valid for the x86 and ARM architectures, since other architectures may
|
|
49
|
-
* use different numbers, see signal(7).
|
|
50
|
-
*/
|
|
51
|
-
export function signame(sig: number): string {
|
|
52
|
-
// We should never reach this on Windows, since signals are not a thing
|
|
53
|
-
// there.
|
|
54
|
-
if (isWindows) {
|
|
55
|
-
throw new Error('Trying to get a signal name on Windows.');
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
for (const entry of objectEntries(os.constants.signals)) {
|
|
59
|
-
if (entry[1] === sig) {
|
|
60
|
-
return entry[0];
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Don't know this signal? Return the number as a string.
|
|
65
|
-
return sig.toString(10);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Convert a code number to its short name
|
|
70
|
-
*/
|
|
71
|
-
export function codename(code: number): string {
|
|
72
|
-
for (const entry of objectEntries(os.constants.errno)) {
|
|
73
|
-
if (entry[1] === code) {
|
|
74
|
-
return entry[0];
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
// Return the number as string if we did not find a name for it.
|
|
78
|
-
return code.toString(10);
|
|
79
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2017 TypeFox and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { isWindows } from '@theia/core';
|
|
18
|
+
import * as os from 'os';
|
|
19
|
+
const stringArgv = require('string-argv');
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Parses the given line into an array of args respecting escapes and string literals.
|
|
23
|
+
* @param line the given line to parse
|
|
24
|
+
*/
|
|
25
|
+
export function parseArgs(line: string | undefined): string[] {
|
|
26
|
+
if (line) {
|
|
27
|
+
return stringArgv(line);
|
|
28
|
+
}
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Polyfill for Object.entries, until we upgrade to ES2017.
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
|
+
function objectEntries(obj: any): any[] {
|
|
35
|
+
const props = Object.keys(obj);
|
|
36
|
+
const result = new Array(props.length);
|
|
37
|
+
for (let i = 0; i < props.length; i++) {
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
39
|
+
result[i] = [props[i], obj[props[i]]];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Convert a signal number to its short name (using the signal definitions of
|
|
47
|
+
* the current host). Should never be called on Windows. For Linux, this is
|
|
48
|
+
* only valid for the x86 and ARM architectures, since other architectures may
|
|
49
|
+
* use different numbers, see signal(7).
|
|
50
|
+
*/
|
|
51
|
+
export function signame(sig: number): string {
|
|
52
|
+
// We should never reach this on Windows, since signals are not a thing
|
|
53
|
+
// there.
|
|
54
|
+
if (isWindows) {
|
|
55
|
+
throw new Error('Trying to get a signal name on Windows.');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
for (const entry of objectEntries(os.constants.signals)) {
|
|
59
|
+
if (entry[1] === sig) {
|
|
60
|
+
return entry[0];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Don't know this signal? Return the number as a string.
|
|
65
|
+
return sig.toString(10);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Convert a code number to its short name
|
|
70
|
+
*/
|
|
71
|
+
export function codename(code: number): string {
|
|
72
|
+
for (const entry of objectEntries(os.constants.errno)) {
|
|
73
|
+
if (entry[1] === code) {
|
|
74
|
+
return entry[0];
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// Return the number as string if we did not find a name for it.
|
|
78
|
+
return code.toString(10);
|
|
79
|
+
}
|