@theia/process 1.53.0-next.55 → 1.53.0-next.64

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.
@@ -1,156 +1,156 @@
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-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { injectable, inject, named } from '@theia/core/shared/inversify';
18
- import { ProcessManager } from './process-manager';
19
- import { ILogger } from '@theia/core/lib/common';
20
- import { Process, ProcessType, ProcessOptions, ForkOptions, ProcessErrorEvent } from './process';
21
- import { ChildProcess, spawn, fork } from 'child_process';
22
- import * as stream from 'stream';
23
-
24
- // The class was here before, exporting to not break anything.
25
- export { DevNullStream } from './dev-null-stream';
26
- import { DevNullStream } from './dev-null-stream';
27
-
28
- export const RawProcessOptions = Symbol('RawProcessOptions');
29
-
30
- /**
31
- * Options to spawn a new process (`spawn`).
32
- *
33
- * For more information please refer to the spawn function of Node's
34
- * child_process module:
35
- *
36
- * https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options
37
- */
38
- export interface RawProcessOptions extends ProcessOptions {
39
- }
40
-
41
- /**
42
- * Options to fork a new process using the current Node interpreter (`fork`).
43
- *
44
- * For more information please refer to the fork function of Node's
45
- * `child_process` module:
46
- *
47
- * https://nodejs.org/api/child_process.html#child_process_child_process_fork_modulepath_args_options
48
- */
49
- export interface RawForkOptions extends ForkOptions {
50
- }
51
-
52
- export const RawProcessFactory = Symbol('RawProcessFactory');
53
- export interface RawProcessFactory {
54
- (options: RawProcessOptions | RawForkOptions): RawProcess;
55
- }
56
-
57
- @injectable()
58
- export class RawProcess extends Process {
59
-
60
- /**
61
- * If the process fails to launch, it will be undefined.
62
- */
63
- readonly process: ChildProcess | undefined;
64
-
65
- readonly outputStream: stream.Readable;
66
- readonly errorStream: stream.Readable;
67
- readonly inputStream: stream.Writable;
68
-
69
- constructor( // eslint-disable-next-line @typescript-eslint/indent
70
- @inject(RawProcessOptions) options: RawProcessOptions | RawForkOptions,
71
- @inject(ProcessManager) processManager: ProcessManager,
72
- @inject(ILogger) @named('process') logger: ILogger
73
- ) {
74
- super(processManager, logger, ProcessType.Raw, options);
75
- const executable = this.isForkOptions(options) ? options.modulePath : options.command;
76
-
77
- this.logger.debug(`Starting raw process: ${executable},`
78
- + ` with args: ${options.args ? options.args.join(' ') : ''}, `
79
- + ` with options: ${JSON.stringify(options.options)}`);
80
-
81
- // About catching errors: spawn will sometimes throw directly
82
- // (EACCES on Linux), sometimes return a Process object with the pid
83
- // property undefined (ENOENT on Linux) and then emit an 'error' event.
84
- // For now, we try to normalize that into always emitting an 'error'
85
- // event.
86
- try {
87
- if (this.isForkOptions(options)) {
88
- this.process = fork(
89
- options.modulePath,
90
- options.args || [],
91
- options.options || {});
92
- } else {
93
- this.process = spawn(
94
- options.command,
95
- options.args || [],
96
- options.options || {});
97
- }
98
-
99
- this.process.on('error', (error: NodeJS.ErrnoException) => {
100
- error.code = error.code || 'Unknown error';
101
- this.emitOnError(error as ProcessErrorEvent);
102
- });
103
-
104
- // When no stdio option is passed, it is null by default.
105
- this.outputStream = this.process.stdout || new DevNullStream({ autoDestroy: true });
106
- this.inputStream = this.process.stdin || new DevNullStream({ autoDestroy: true });
107
- this.errorStream = this.process.stderr || new DevNullStream({ autoDestroy: true });
108
-
109
- this.process.on('exit', (exitCode, signal) => {
110
- // node's child_process exit sets the unused parameter to null,
111
- // but we want it to be undefined instead.
112
- this.emitOnExit(
113
- typeof exitCode === 'number' ? exitCode : undefined,
114
- typeof signal === 'string' ? signal : undefined,
115
- );
116
- this.processManager.unregister(this);
117
- });
118
-
119
- this.process.on('close', (exitCode, signal) => {
120
- // node's child_process exit sets the unused parameter to null,
121
- // but we want it to be undefined instead.
122
- this.emitOnClose(
123
- typeof exitCode === 'number' ? exitCode : undefined,
124
- typeof signal === 'string' ? signal : undefined,
125
- );
126
- });
127
-
128
- if (this.process.pid !== undefined) {
129
- process.nextTick(this.emitOnStarted.bind(this));
130
- }
131
- } catch (error) {
132
- /* When an error is thrown, set up some fake streams, so the client
133
- code doesn't break because these field are undefined. */
134
- this.outputStream = new DevNullStream({ autoDestroy: true });
135
- this.inputStream = new DevNullStream({ autoDestroy: true });
136
- this.errorStream = new DevNullStream({ autoDestroy: true });
137
-
138
- /* Call the client error handler, but first give them a chance to register it. */
139
- this.emitOnErrorAsync(error);
140
- }
141
- }
142
-
143
- get pid(): number {
144
- if (!this.process || !this.process.pid) {
145
- throw new Error('process did not start correctly');
146
- }
147
- return this.process.pid;
148
- }
149
-
150
- kill(signal?: string): void {
151
- if (this.process && this.killed === false) {
152
- this.process.kill(signal as NodeJS.Signals);
153
- }
154
- }
155
-
156
- }
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-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { injectable, inject, named } from '@theia/core/shared/inversify';
18
+ import { ProcessManager } from './process-manager';
19
+ import { ILogger } from '@theia/core/lib/common';
20
+ import { Process, ProcessType, ProcessOptions, ForkOptions, ProcessErrorEvent } from './process';
21
+ import { ChildProcess, spawn, fork } from 'child_process';
22
+ import * as stream from 'stream';
23
+
24
+ // The class was here before, exporting to not break anything.
25
+ export { DevNullStream } from './dev-null-stream';
26
+ import { DevNullStream } from './dev-null-stream';
27
+
28
+ export const RawProcessOptions = Symbol('RawProcessOptions');
29
+
30
+ /**
31
+ * Options to spawn a new process (`spawn`).
32
+ *
33
+ * For more information please refer to the spawn function of Node's
34
+ * child_process module:
35
+ *
36
+ * https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options
37
+ */
38
+ export interface RawProcessOptions extends ProcessOptions {
39
+ }
40
+
41
+ /**
42
+ * Options to fork a new process using the current Node interpreter (`fork`).
43
+ *
44
+ * For more information please refer to the fork function of Node's
45
+ * `child_process` module:
46
+ *
47
+ * https://nodejs.org/api/child_process.html#child_process_child_process_fork_modulepath_args_options
48
+ */
49
+ export interface RawForkOptions extends ForkOptions {
50
+ }
51
+
52
+ export const RawProcessFactory = Symbol('RawProcessFactory');
53
+ export interface RawProcessFactory {
54
+ (options: RawProcessOptions | RawForkOptions): RawProcess;
55
+ }
56
+
57
+ @injectable()
58
+ export class RawProcess extends Process {
59
+
60
+ /**
61
+ * If the process fails to launch, it will be undefined.
62
+ */
63
+ readonly process: ChildProcess | undefined;
64
+
65
+ readonly outputStream: stream.Readable;
66
+ readonly errorStream: stream.Readable;
67
+ readonly inputStream: stream.Writable;
68
+
69
+ constructor( // eslint-disable-next-line @typescript-eslint/indent
70
+ @inject(RawProcessOptions) options: RawProcessOptions | RawForkOptions,
71
+ @inject(ProcessManager) processManager: ProcessManager,
72
+ @inject(ILogger) @named('process') logger: ILogger
73
+ ) {
74
+ super(processManager, logger, ProcessType.Raw, options);
75
+ const executable = this.isForkOptions(options) ? options.modulePath : options.command;
76
+
77
+ this.logger.debug(`Starting raw process: ${executable},`
78
+ + ` with args: ${options.args ? options.args.join(' ') : ''}, `
79
+ + ` with options: ${JSON.stringify(options.options)}`);
80
+
81
+ // About catching errors: spawn will sometimes throw directly
82
+ // (EACCES on Linux), sometimes return a Process object with the pid
83
+ // property undefined (ENOENT on Linux) and then emit an 'error' event.
84
+ // For now, we try to normalize that into always emitting an 'error'
85
+ // event.
86
+ try {
87
+ if (this.isForkOptions(options)) {
88
+ this.process = fork(
89
+ options.modulePath,
90
+ options.args || [],
91
+ options.options || {});
92
+ } else {
93
+ this.process = spawn(
94
+ options.command,
95
+ options.args || [],
96
+ options.options || {});
97
+ }
98
+
99
+ this.process.on('error', (error: NodeJS.ErrnoException) => {
100
+ error.code = error.code || 'Unknown error';
101
+ this.emitOnError(error as ProcessErrorEvent);
102
+ });
103
+
104
+ // When no stdio option is passed, it is null by default.
105
+ this.outputStream = this.process.stdout || new DevNullStream({ autoDestroy: true });
106
+ this.inputStream = this.process.stdin || new DevNullStream({ autoDestroy: true });
107
+ this.errorStream = this.process.stderr || new DevNullStream({ autoDestroy: true });
108
+
109
+ this.process.on('exit', (exitCode, signal) => {
110
+ // node's child_process exit sets the unused parameter to null,
111
+ // but we want it to be undefined instead.
112
+ this.emitOnExit(
113
+ typeof exitCode === 'number' ? exitCode : undefined,
114
+ typeof signal === 'string' ? signal : undefined,
115
+ );
116
+ this.processManager.unregister(this);
117
+ });
118
+
119
+ this.process.on('close', (exitCode, signal) => {
120
+ // node's child_process exit sets the unused parameter to null,
121
+ // but we want it to be undefined instead.
122
+ this.emitOnClose(
123
+ typeof exitCode === 'number' ? exitCode : undefined,
124
+ typeof signal === 'string' ? signal : undefined,
125
+ );
126
+ });
127
+
128
+ if (this.process.pid !== undefined) {
129
+ process.nextTick(this.emitOnStarted.bind(this));
130
+ }
131
+ } catch (error) {
132
+ /* When an error is thrown, set up some fake streams, so the client
133
+ code doesn't break because these field are undefined. */
134
+ this.outputStream = new DevNullStream({ autoDestroy: true });
135
+ this.inputStream = new DevNullStream({ autoDestroy: true });
136
+ this.errorStream = new DevNullStream({ autoDestroy: true });
137
+
138
+ /* Call the client error handler, but first give them a chance to register it. */
139
+ this.emitOnErrorAsync(error);
140
+ }
141
+ }
142
+
143
+ get pid(): number {
144
+ if (!this.process || !this.process.pid) {
145
+ throw new Error('process did not start correctly');
146
+ }
147
+ return this.process.pid;
148
+ }
149
+
150
+ kill(signal?: string): void {
151
+ if (this.process && this.killed === false) {
152
+ this.process.kill(signal as NodeJS.Signals);
153
+ }
154
+ }
155
+
156
+ }
@@ -1,21 +1,21 @@
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-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- declare module 'string-argv' {
18
- function stringArgv(...args: string[]): string[];
19
- export = stringArgv;
20
- }
21
-
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-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ declare module 'string-argv' {
18
+ function stringArgv(...args: string[]): string[];
19
+ export = stringArgv;
20
+ }
21
+
@@ -1,41 +1,41 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2021 SAP SE or an SAP affiliate company 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-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { injectable } from '@theia/core/shared/inversify';
18
- import { TerminalProcess, TerminalProcessOptions } from './terminal-process';
19
-
20
- export const TaskTerminalProcessFactory = Symbol('TaskTerminalProcessFactory');
21
- export interface TaskTerminalProcessFactory {
22
- (options: TerminalProcessOptions): TaskTerminalProcess;
23
- }
24
-
25
- @injectable()
26
- export class TaskTerminalProcess extends TerminalProcess {
27
-
28
- public exited = false;
29
- public attachmentAttempted = false;
30
-
31
- protected override onTerminalExit(code: number | undefined, signal: string | undefined): void {
32
- this.emitOnExit(code, signal);
33
- this.exited = true;
34
- // Unregister process only if task terminal already attached (or failed attach),
35
- // Fixes https://github.com/eclipse-theia/theia/issues/2961
36
- if (this.attachmentAttempted) {
37
- this.unregisterProcess();
38
- }
39
- }
40
-
41
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2021 SAP SE or an SAP affiliate company 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-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { injectable } from '@theia/core/shared/inversify';
18
+ import { TerminalProcess, TerminalProcessOptions } from './terminal-process';
19
+
20
+ export const TaskTerminalProcessFactory = Symbol('TaskTerminalProcessFactory');
21
+ export interface TaskTerminalProcessFactory {
22
+ (options: TerminalProcessOptions): TaskTerminalProcess;
23
+ }
24
+
25
+ @injectable()
26
+ export class TaskTerminalProcess extends TerminalProcess {
27
+
28
+ public exited = false;
29
+ public attachmentAttempted = false;
30
+
31
+ protected override onTerminalExit(code: number | undefined, signal: string | undefined): void {
32
+ this.emitOnExit(code, signal);
33
+ this.exited = true;
34
+ // Unregister process only if task terminal already attached (or failed attach),
35
+ // Fixes https://github.com/eclipse-theia/theia/issues/2961
36
+ if (this.attachmentAttempted) {
37
+ this.unregisterProcess();
38
+ }
39
+ }
40
+
41
+ }