@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,48 +1,48 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// *****************************************************************************
|
|
3
|
-
// Copyright (C) 2021 SAP SE or an SAP affiliate company 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 WITH Classpath-exception-2.0
|
|
16
|
-
// *****************************************************************************
|
|
17
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
18
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
19
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
20
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
21
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
22
|
-
};
|
|
23
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.TaskTerminalProcess = exports.TaskTerminalProcessFactory = void 0;
|
|
25
|
-
const inversify_1 = require("@theia/core/shared/inversify");
|
|
26
|
-
const terminal_process_1 = require("./terminal-process");
|
|
27
|
-
exports.TaskTerminalProcessFactory = Symbol('TaskTerminalProcessFactory');
|
|
28
|
-
let TaskTerminalProcess = class TaskTerminalProcess extends terminal_process_1.TerminalProcess {
|
|
29
|
-
constructor() {
|
|
30
|
-
super(...arguments);
|
|
31
|
-
this.exited = false;
|
|
32
|
-
this.attachmentAttempted = false;
|
|
33
|
-
}
|
|
34
|
-
onTerminalExit(code, signal) {
|
|
35
|
-
this.emitOnExit(code, signal);
|
|
36
|
-
this.exited = true;
|
|
37
|
-
// Unregister process only if task terminal already attached (or failed attach),
|
|
38
|
-
// Fixes https://github.com/eclipse-theia/theia/issues/2961
|
|
39
|
-
if (this.attachmentAttempted) {
|
|
40
|
-
this.unregisterProcess();
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
TaskTerminalProcess = __decorate([
|
|
45
|
-
(0, inversify_1.injectable)()
|
|
46
|
-
], TaskTerminalProcess);
|
|
47
|
-
exports.TaskTerminalProcess = TaskTerminalProcess;
|
|
1
|
+
"use strict";
|
|
2
|
+
// *****************************************************************************
|
|
3
|
+
// Copyright (C) 2021 SAP SE or an SAP affiliate company 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 WITH Classpath-exception-2.0
|
|
16
|
+
// *****************************************************************************
|
|
17
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
18
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
19
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
20
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
21
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
22
|
+
};
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.TaskTerminalProcess = exports.TaskTerminalProcessFactory = void 0;
|
|
25
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
26
|
+
const terminal_process_1 = require("./terminal-process");
|
|
27
|
+
exports.TaskTerminalProcessFactory = Symbol('TaskTerminalProcessFactory');
|
|
28
|
+
let TaskTerminalProcess = class TaskTerminalProcess extends terminal_process_1.TerminalProcess {
|
|
29
|
+
constructor() {
|
|
30
|
+
super(...arguments);
|
|
31
|
+
this.exited = false;
|
|
32
|
+
this.attachmentAttempted = false;
|
|
33
|
+
}
|
|
34
|
+
onTerminalExit(code, signal) {
|
|
35
|
+
this.emitOnExit(code, signal);
|
|
36
|
+
this.exited = true;
|
|
37
|
+
// Unregister process only if task terminal already attached (or failed attach),
|
|
38
|
+
// Fixes https://github.com/eclipse-theia/theia/issues/2961
|
|
39
|
+
if (this.attachmentAttempted) {
|
|
40
|
+
this.unregisterProcess();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
TaskTerminalProcess = __decorate([
|
|
45
|
+
(0, inversify_1.injectable)()
|
|
46
|
+
], TaskTerminalProcess);
|
|
47
|
+
exports.TaskTerminalProcess = TaskTerminalProcess;
|
|
48
48
|
//# sourceMappingURL=task-terminal-process.js.map
|
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { ILogger } from '@theia/core/lib/common';
|
|
3
|
-
import { Process, ProcessOptions } from './process';
|
|
4
|
-
import { ProcessManager } from './process-manager';
|
|
5
|
-
import { IPty } from 'node-pty';
|
|
6
|
-
import { MultiRingBuffer, MultiRingBufferReadableStream } from './multi-ring-buffer';
|
|
7
|
-
import { DevNullStream } from './dev-null-stream';
|
|
8
|
-
import { Writable } from 'stream';
|
|
9
|
-
export declare const TerminalProcessOptions: unique symbol;
|
|
10
|
-
export interface TerminalProcessOptions extends ProcessOptions {
|
|
11
|
-
/**
|
|
12
|
-
* Windows only. Allow passing complex command lines already escaped for CommandLineToArgvW.
|
|
13
|
-
*/
|
|
14
|
-
commandLine?: string;
|
|
15
|
-
isPseudo?: boolean;
|
|
16
|
-
}
|
|
17
|
-
export declare const TerminalProcessFactory: unique symbol;
|
|
18
|
-
export interface TerminalProcessFactory {
|
|
19
|
-
(options: TerminalProcessOptions): TerminalProcess;
|
|
20
|
-
}
|
|
21
|
-
export declare enum NodePtyErrors {
|
|
22
|
-
EACCES = "Permission denied",
|
|
23
|
-
ENOENT = "No such file or directory"
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Run arbitrary processes inside pseudo-terminals (PTY).
|
|
27
|
-
*
|
|
28
|
-
* Note: a PTY is not a shell process (bash/pwsh/cmd...)
|
|
29
|
-
*/
|
|
30
|
-
export declare class TerminalProcess extends Process {
|
|
31
|
-
protected readonly options: TerminalProcessOptions;
|
|
32
|
-
protected readonly ringBuffer: MultiRingBuffer;
|
|
33
|
-
protected readonly terminal: IPty | undefined;
|
|
34
|
-
readonly outputStream: MultiRingBufferReadableStream;
|
|
35
|
-
readonly errorStream: DevNullStream;
|
|
36
|
-
readonly inputStream: Writable;
|
|
37
|
-
constructor(// eslint-disable-next-line @typescript-eslint/indent
|
|
38
|
-
options: TerminalProcessOptions, processManager: ProcessManager, ringBuffer: MultiRingBuffer, logger: ILogger);
|
|
39
|
-
createOutputStream(): MultiRingBufferReadableStream;
|
|
40
|
-
get pid(): number;
|
|
41
|
-
get executable(): string;
|
|
42
|
-
get arguments(): string[];
|
|
43
|
-
protected onTerminalExit(code: number | undefined, signal: string | undefined): void;
|
|
44
|
-
unregisterProcess(): void;
|
|
45
|
-
kill(signal?: string): void;
|
|
46
|
-
resize(cols: number, rows: number): void;
|
|
47
|
-
write(data: string): void;
|
|
48
|
-
protected checkTerminal(): void | never;
|
|
49
|
-
}
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { ILogger } from '@theia/core/lib/common';
|
|
3
|
+
import { Process, ProcessOptions } from './process';
|
|
4
|
+
import { ProcessManager } from './process-manager';
|
|
5
|
+
import { IPty } from 'node-pty';
|
|
6
|
+
import { MultiRingBuffer, MultiRingBufferReadableStream } from './multi-ring-buffer';
|
|
7
|
+
import { DevNullStream } from './dev-null-stream';
|
|
8
|
+
import { Writable } from 'stream';
|
|
9
|
+
export declare const TerminalProcessOptions: unique symbol;
|
|
10
|
+
export interface TerminalProcessOptions extends ProcessOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Windows only. Allow passing complex command lines already escaped for CommandLineToArgvW.
|
|
13
|
+
*/
|
|
14
|
+
commandLine?: string;
|
|
15
|
+
isPseudo?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare const TerminalProcessFactory: unique symbol;
|
|
18
|
+
export interface TerminalProcessFactory {
|
|
19
|
+
(options: TerminalProcessOptions): TerminalProcess;
|
|
20
|
+
}
|
|
21
|
+
export declare enum NodePtyErrors {
|
|
22
|
+
EACCES = "Permission denied",
|
|
23
|
+
ENOENT = "No such file or directory"
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Run arbitrary processes inside pseudo-terminals (PTY).
|
|
27
|
+
*
|
|
28
|
+
* Note: a PTY is not a shell process (bash/pwsh/cmd...)
|
|
29
|
+
*/
|
|
30
|
+
export declare class TerminalProcess extends Process {
|
|
31
|
+
protected readonly options: TerminalProcessOptions;
|
|
32
|
+
protected readonly ringBuffer: MultiRingBuffer;
|
|
33
|
+
protected readonly terminal: IPty | undefined;
|
|
34
|
+
readonly outputStream: MultiRingBufferReadableStream;
|
|
35
|
+
readonly errorStream: DevNullStream;
|
|
36
|
+
readonly inputStream: Writable;
|
|
37
|
+
constructor(// eslint-disable-next-line @typescript-eslint/indent
|
|
38
|
+
options: TerminalProcessOptions, processManager: ProcessManager, ringBuffer: MultiRingBuffer, logger: ILogger);
|
|
39
|
+
createOutputStream(): MultiRingBufferReadableStream;
|
|
40
|
+
get pid(): number;
|
|
41
|
+
get executable(): string;
|
|
42
|
+
get arguments(): string[];
|
|
43
|
+
protected onTerminalExit(code: number | undefined, signal: string | undefined): void;
|
|
44
|
+
unregisterProcess(): void;
|
|
45
|
+
kill(signal?: string): void;
|
|
46
|
+
resize(cols: number, rows: number): void;
|
|
47
|
+
write(data: string): void;
|
|
48
|
+
protected checkTerminal(): void | never;
|
|
49
|
+
}
|
|
50
50
|
//# sourceMappingURL=terminal-process.d.ts.map
|
|
@@ -1,181 +1,181 @@
|
|
|
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 WITH Classpath-exception-2.0
|
|
16
|
-
// *****************************************************************************
|
|
17
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
18
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
19
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
20
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
21
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
22
|
-
};
|
|
23
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
24
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
25
|
-
};
|
|
26
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
27
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
28
|
-
};
|
|
29
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.TerminalProcess = exports.NodePtyErrors = exports.TerminalProcessFactory = exports.TerminalProcessOptions = void 0;
|
|
31
|
-
const inversify_1 = require("@theia/core/shared/inversify");
|
|
32
|
-
const core_1 = require("@theia/core");
|
|
33
|
-
const common_1 = require("@theia/core/lib/common");
|
|
34
|
-
const process_1 = require("./process");
|
|
35
|
-
const process_manager_1 = require("./process-manager");
|
|
36
|
-
const node_pty_1 = require("node-pty");
|
|
37
|
-
const multi_ring_buffer_1 = require("./multi-ring-buffer");
|
|
38
|
-
const dev_null_stream_1 = require("./dev-null-stream");
|
|
39
|
-
const utils_1 = require("./utils");
|
|
40
|
-
const pseudo_pty_1 = require("./pseudo-pty");
|
|
41
|
-
const stream_1 = require("stream");
|
|
42
|
-
exports.TerminalProcessOptions = Symbol('TerminalProcessOptions');
|
|
43
|
-
exports.TerminalProcessFactory = Symbol('TerminalProcessFactory');
|
|
44
|
-
var NodePtyErrors;
|
|
45
|
-
(function (NodePtyErrors) {
|
|
46
|
-
NodePtyErrors["EACCES"] = "Permission denied";
|
|
47
|
-
NodePtyErrors["ENOENT"] = "No such file or directory";
|
|
48
|
-
})(NodePtyErrors = exports.NodePtyErrors || (exports.NodePtyErrors = {}));
|
|
49
|
-
/**
|
|
50
|
-
* Run arbitrary processes inside pseudo-terminals (PTY).
|
|
51
|
-
*
|
|
52
|
-
* Note: a PTY is not a shell process (bash/pwsh/cmd...)
|
|
53
|
-
*/
|
|
54
|
-
let TerminalProcess = class TerminalProcess extends process_1.Process {
|
|
55
|
-
constructor(// eslint-disable-next-line @typescript-eslint/indent
|
|
56
|
-
options, processManager, ringBuffer, logger) {
|
|
57
|
-
super(processManager, logger, process_1.ProcessType.Terminal, options);
|
|
58
|
-
this.options = options;
|
|
59
|
-
this.ringBuffer = ringBuffer;
|
|
60
|
-
this.outputStream = this.createOutputStream();
|
|
61
|
-
this.errorStream = new dev_null_stream_1.DevNullStream({ autoDestroy: true });
|
|
62
|
-
if (options.isPseudo) {
|
|
63
|
-
// do not need to spawn a process, new a pseudo pty instead
|
|
64
|
-
this.terminal = new pseudo_pty_1.PseudoPty();
|
|
65
|
-
this.inputStream = new dev_null_stream_1.DevNullStream({ autoDestroy: true });
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
if (this.isForkOptions(this.options)) {
|
|
69
|
-
throw new Error('terminal processes cannot be forked as of today');
|
|
70
|
-
}
|
|
71
|
-
this.logger.debug('Starting terminal process', JSON.stringify(options, undefined, 2));
|
|
72
|
-
try {
|
|
73
|
-
this.terminal = (0, node_pty_1.spawn)(options.command, (core_1.isWindows && options.commandLine) || options.args || [], options.options || {});
|
|
74
|
-
process.nextTick(() => this.emitOnStarted());
|
|
75
|
-
// node-pty actually wait for the underlying streams to be closed before emitting exit.
|
|
76
|
-
// We should emulate the `exit` and `close` sequence.
|
|
77
|
-
this.terminal.on('exit', (code, signal) => {
|
|
78
|
-
// Make sure to only pass either code or signal as !undefined, not
|
|
79
|
-
// both.
|
|
80
|
-
//
|
|
81
|
-
// node-pty quirk: On Linux/macOS, if the process exited through the
|
|
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);
|
|
88
|
-
}
|
|
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
|
-
});
|
|
109
|
-
}
|
|
110
|
-
catch (error) {
|
|
111
|
-
this.inputStream = new dev_null_stream_1.DevNullStream({ autoDestroy: true });
|
|
112
|
-
// Normalize the error to make it as close as possible as what
|
|
113
|
-
// node's child_process.spawn would generate in the same
|
|
114
|
-
// situation.
|
|
115
|
-
const message = error.message;
|
|
116
|
-
if (message.startsWith('File not found: ') || message.endsWith(NodePtyErrors.ENOENT)) {
|
|
117
|
-
error.errno = 'ENOENT';
|
|
118
|
-
error.code = 'ENOENT';
|
|
119
|
-
error.path = options.command;
|
|
120
|
-
}
|
|
121
|
-
else if (message.endsWith(NodePtyErrors.EACCES)) {
|
|
122
|
-
error.errno = 'EACCES';
|
|
123
|
-
error.code = 'EACCES';
|
|
124
|
-
error.path = options.command;
|
|
125
|
-
}
|
|
126
|
-
// node-pty throws exceptions on Windows.
|
|
127
|
-
// Call the client error handler, but first give them a chance to register it.
|
|
128
|
-
this.emitOnErrorAsync(error);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
createOutputStream() {
|
|
132
|
-
return this.ringBuffer.getStream();
|
|
133
|
-
}
|
|
134
|
-
get pid() {
|
|
135
|
-
this.checkTerminal();
|
|
136
|
-
return this.terminal.pid;
|
|
137
|
-
}
|
|
138
|
-
get executable() {
|
|
139
|
-
return this.options.command;
|
|
140
|
-
}
|
|
141
|
-
get arguments() {
|
|
142
|
-
return this.options.args || [];
|
|
143
|
-
}
|
|
144
|
-
onTerminalExit(code, signal) {
|
|
145
|
-
this.emitOnExit(code, signal);
|
|
146
|
-
this.unregisterProcess();
|
|
147
|
-
}
|
|
148
|
-
unregisterProcess() {
|
|
149
|
-
this.processManager.unregister(this);
|
|
150
|
-
}
|
|
151
|
-
kill(signal) {
|
|
152
|
-
if (this.terminal && this.killed === false) {
|
|
153
|
-
this.terminal.kill(signal);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
resize(cols, rows) {
|
|
157
|
-
this.checkTerminal();
|
|
158
|
-
this.terminal.resize(cols, rows);
|
|
159
|
-
}
|
|
160
|
-
write(data) {
|
|
161
|
-
this.checkTerminal();
|
|
162
|
-
this.terminal.write(data);
|
|
163
|
-
}
|
|
164
|
-
checkTerminal() {
|
|
165
|
-
if (!this.terminal) {
|
|
166
|
-
throw new Error('pty process did not start correctly');
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
TerminalProcess = __decorate([
|
|
171
|
-
(0, inversify_1.injectable)(),
|
|
172
|
-
__param(0, (0, inversify_1.inject)(exports.TerminalProcessOptions)),
|
|
173
|
-
__param(1, (0, inversify_1.inject)(process_manager_1.ProcessManager)),
|
|
174
|
-
__param(2, (0, inversify_1.inject)(multi_ring_buffer_1.MultiRingBuffer)),
|
|
175
|
-
__param(3, (0, inversify_1.inject)(common_1.ILogger)),
|
|
176
|
-
__param(3, (0, inversify_1.named)('process')),
|
|
177
|
-
__metadata("design:paramtypes", [Object, process_manager_1.ProcessManager,
|
|
178
|
-
multi_ring_buffer_1.MultiRingBuffer, Object])
|
|
179
|
-
], TerminalProcess);
|
|
180
|
-
exports.TerminalProcess = TerminalProcess;
|
|
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 WITH Classpath-exception-2.0
|
|
16
|
+
// *****************************************************************************
|
|
17
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
18
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
19
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
20
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
21
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
22
|
+
};
|
|
23
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
24
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
25
|
+
};
|
|
26
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
27
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
28
|
+
};
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.TerminalProcess = exports.NodePtyErrors = exports.TerminalProcessFactory = exports.TerminalProcessOptions = void 0;
|
|
31
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
32
|
+
const core_1 = require("@theia/core");
|
|
33
|
+
const common_1 = require("@theia/core/lib/common");
|
|
34
|
+
const process_1 = require("./process");
|
|
35
|
+
const process_manager_1 = require("./process-manager");
|
|
36
|
+
const node_pty_1 = require("node-pty");
|
|
37
|
+
const multi_ring_buffer_1 = require("./multi-ring-buffer");
|
|
38
|
+
const dev_null_stream_1 = require("./dev-null-stream");
|
|
39
|
+
const utils_1 = require("./utils");
|
|
40
|
+
const pseudo_pty_1 = require("./pseudo-pty");
|
|
41
|
+
const stream_1 = require("stream");
|
|
42
|
+
exports.TerminalProcessOptions = Symbol('TerminalProcessOptions');
|
|
43
|
+
exports.TerminalProcessFactory = Symbol('TerminalProcessFactory');
|
|
44
|
+
var NodePtyErrors;
|
|
45
|
+
(function (NodePtyErrors) {
|
|
46
|
+
NodePtyErrors["EACCES"] = "Permission denied";
|
|
47
|
+
NodePtyErrors["ENOENT"] = "No such file or directory";
|
|
48
|
+
})(NodePtyErrors = exports.NodePtyErrors || (exports.NodePtyErrors = {}));
|
|
49
|
+
/**
|
|
50
|
+
* Run arbitrary processes inside pseudo-terminals (PTY).
|
|
51
|
+
*
|
|
52
|
+
* Note: a PTY is not a shell process (bash/pwsh/cmd...)
|
|
53
|
+
*/
|
|
54
|
+
let TerminalProcess = class TerminalProcess extends process_1.Process {
|
|
55
|
+
constructor(// eslint-disable-next-line @typescript-eslint/indent
|
|
56
|
+
options, processManager, ringBuffer, logger) {
|
|
57
|
+
super(processManager, logger, process_1.ProcessType.Terminal, options);
|
|
58
|
+
this.options = options;
|
|
59
|
+
this.ringBuffer = ringBuffer;
|
|
60
|
+
this.outputStream = this.createOutputStream();
|
|
61
|
+
this.errorStream = new dev_null_stream_1.DevNullStream({ autoDestroy: true });
|
|
62
|
+
if (options.isPseudo) {
|
|
63
|
+
// do not need to spawn a process, new a pseudo pty instead
|
|
64
|
+
this.terminal = new pseudo_pty_1.PseudoPty();
|
|
65
|
+
this.inputStream = new dev_null_stream_1.DevNullStream({ autoDestroy: true });
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (this.isForkOptions(this.options)) {
|
|
69
|
+
throw new Error('terminal processes cannot be forked as of today');
|
|
70
|
+
}
|
|
71
|
+
this.logger.debug('Starting terminal process', JSON.stringify(options, undefined, 2));
|
|
72
|
+
try {
|
|
73
|
+
this.terminal = (0, node_pty_1.spawn)(options.command, (core_1.isWindows && options.commandLine) || options.args || [], options.options || {});
|
|
74
|
+
process.nextTick(() => this.emitOnStarted());
|
|
75
|
+
// node-pty actually wait for the underlying streams to be closed before emitting exit.
|
|
76
|
+
// We should emulate the `exit` and `close` sequence.
|
|
77
|
+
this.terminal.on('exit', (code, signal) => {
|
|
78
|
+
// Make sure to only pass either code or signal as !undefined, not
|
|
79
|
+
// both.
|
|
80
|
+
//
|
|
81
|
+
// node-pty quirk: On Linux/macOS, if the process exited through the
|
|
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);
|
|
88
|
+
}
|
|
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
|
+
});
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
this.inputStream = new dev_null_stream_1.DevNullStream({ autoDestroy: true });
|
|
112
|
+
// Normalize the error to make it as close as possible as what
|
|
113
|
+
// node's child_process.spawn would generate in the same
|
|
114
|
+
// situation.
|
|
115
|
+
const message = error.message;
|
|
116
|
+
if (message.startsWith('File not found: ') || message.endsWith(NodePtyErrors.ENOENT)) {
|
|
117
|
+
error.errno = 'ENOENT';
|
|
118
|
+
error.code = 'ENOENT';
|
|
119
|
+
error.path = options.command;
|
|
120
|
+
}
|
|
121
|
+
else if (message.endsWith(NodePtyErrors.EACCES)) {
|
|
122
|
+
error.errno = 'EACCES';
|
|
123
|
+
error.code = 'EACCES';
|
|
124
|
+
error.path = options.command;
|
|
125
|
+
}
|
|
126
|
+
// node-pty throws exceptions on Windows.
|
|
127
|
+
// Call the client error handler, but first give them a chance to register it.
|
|
128
|
+
this.emitOnErrorAsync(error);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
createOutputStream() {
|
|
132
|
+
return this.ringBuffer.getStream();
|
|
133
|
+
}
|
|
134
|
+
get pid() {
|
|
135
|
+
this.checkTerminal();
|
|
136
|
+
return this.terminal.pid;
|
|
137
|
+
}
|
|
138
|
+
get executable() {
|
|
139
|
+
return this.options.command;
|
|
140
|
+
}
|
|
141
|
+
get arguments() {
|
|
142
|
+
return this.options.args || [];
|
|
143
|
+
}
|
|
144
|
+
onTerminalExit(code, signal) {
|
|
145
|
+
this.emitOnExit(code, signal);
|
|
146
|
+
this.unregisterProcess();
|
|
147
|
+
}
|
|
148
|
+
unregisterProcess() {
|
|
149
|
+
this.processManager.unregister(this);
|
|
150
|
+
}
|
|
151
|
+
kill(signal) {
|
|
152
|
+
if (this.terminal && this.killed === false) {
|
|
153
|
+
this.terminal.kill(signal);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
resize(cols, rows) {
|
|
157
|
+
this.checkTerminal();
|
|
158
|
+
this.terminal.resize(cols, rows);
|
|
159
|
+
}
|
|
160
|
+
write(data) {
|
|
161
|
+
this.checkTerminal();
|
|
162
|
+
this.terminal.write(data);
|
|
163
|
+
}
|
|
164
|
+
checkTerminal() {
|
|
165
|
+
if (!this.terminal) {
|
|
166
|
+
throw new Error('pty process did not start correctly');
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
TerminalProcess = __decorate([
|
|
171
|
+
(0, inversify_1.injectable)(),
|
|
172
|
+
__param(0, (0, inversify_1.inject)(exports.TerminalProcessOptions)),
|
|
173
|
+
__param(1, (0, inversify_1.inject)(process_manager_1.ProcessManager)),
|
|
174
|
+
__param(2, (0, inversify_1.inject)(multi_ring_buffer_1.MultiRingBuffer)),
|
|
175
|
+
__param(3, (0, inversify_1.inject)(common_1.ILogger)),
|
|
176
|
+
__param(3, (0, inversify_1.named)('process')),
|
|
177
|
+
__metadata("design:paramtypes", [Object, process_manager_1.ProcessManager,
|
|
178
|
+
multi_ring_buffer_1.MultiRingBuffer, Object])
|
|
179
|
+
], TerminalProcess);
|
|
180
|
+
exports.TerminalProcess = TerminalProcess;
|
|
181
181
|
//# sourceMappingURL=terminal-process.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
2
2
|
//# sourceMappingURL=terminal-process.spec.d.ts.map
|