@theia/process 1.48.1 → 1.48.2

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.
Files changed (69) hide show
  1. package/README.md +30 -30
  2. package/lib/common/process-common-module.d.ts +3 -3
  3. package/lib/common/process-common-module.js +22 -22
  4. package/lib/common/process-manager-types.d.ts +35 -35
  5. package/lib/common/process-manager-types.js +23 -23
  6. package/lib/common/shell-command-builder.d.ts +49 -49
  7. package/lib/common/shell-command-builder.js +169 -169
  8. package/lib/common/shell-command-builder.slow-spec.d.ts +9 -9
  9. package/lib/common/shell-command-builder.slow-spec.js +404 -404
  10. package/lib/common/shell-quoting.d.ts +91 -91
  11. package/lib/common/shell-quoting.js +145 -145
  12. package/lib/common/shell-quoting.spec.d.ts +1 -1
  13. package/lib/common/shell-quoting.spec.js +170 -170
  14. package/lib/node/dev-null-stream.d.ts +17 -17
  15. package/lib/node/dev-null-stream.js +41 -41
  16. package/lib/node/index.d.ts +6 -6
  17. package/lib/node/index.js +24 -24
  18. package/lib/node/multi-ring-buffer.d.ts +68 -68
  19. package/lib/node/multi-ring-buffer.js +299 -299
  20. package/lib/node/multi-ring-buffer.spec.d.ts +1 -1
  21. package/lib/node/multi-ring-buffer.spec.js +422 -422
  22. package/lib/node/process-backend-module.d.ts +3 -3
  23. package/lib/node/process-backend-module.js +56 -56
  24. package/lib/node/process-manager.d.ts +33 -33
  25. package/lib/node/process-manager.js +102 -102
  26. package/lib/node/process.d.ts +95 -95
  27. package/lib/node/process.js +142 -142
  28. package/lib/node/pseudo-pty.d.ts +22 -22
  29. package/lib/node/pseudo-pty.js +38 -38
  30. package/lib/node/raw-process.d.ts +45 -45
  31. package/lib/node/raw-process.js +104 -104
  32. package/lib/node/raw-process.spec.d.ts +1 -1
  33. package/lib/node/raw-process.spec.js +164 -164
  34. package/lib/node/task-terminal-process.d.ts +10 -10
  35. package/lib/node/task-terminal-process.js +42 -42
  36. package/lib/node/terminal-process.d.ts +60 -60
  37. package/lib/node/terminal-process.js +248 -248
  38. package/lib/node/terminal-process.spec.d.ts +1 -1
  39. package/lib/node/terminal-process.spec.js +103 -103
  40. package/lib/node/test/process-test-container.d.ts +2 -2
  41. package/lib/node/test/process-test-container.js +28 -28
  42. package/lib/node/utils.d.ts +16 -16
  43. package/lib/node/utils.js +77 -77
  44. package/package.json +4 -4
  45. package/src/common/process-common-module.ts +22 -22
  46. package/src/common/process-manager-types.ts +58 -58
  47. package/src/common/shell-command-builder.slow-spec.ts +486 -486
  48. package/src/common/shell-command-builder.ts +187 -187
  49. package/src/common/shell-quoting.spec.ts +176 -176
  50. package/src/common/shell-quoting.ts +236 -236
  51. package/src/common/tests/$weird(),file=name.js +1 -1
  52. package/src/common/tests/white space.js +1 -1
  53. package/src/node/dev-null-stream.ts +47 -47
  54. package/src/node/index.ts +22 -22
  55. package/src/node/multi-ring-buffer.spec.ts +486 -486
  56. package/src/node/multi-ring-buffer.ts +348 -348
  57. package/src/node/process-backend-module.ts +67 -67
  58. package/src/node/process-manager.ts +107 -107
  59. package/src/node/process.ts +207 -207
  60. package/src/node/pseudo-pty.ts +54 -54
  61. package/src/node/raw-process.spec.ts +199 -199
  62. package/src/node/raw-process.ts +156 -156
  63. package/src/node/string-argv.d.ts +21 -21
  64. package/src/node/task-terminal-process.ts +41 -41
  65. package/src/node/terminal-process.spec.ts +121 -121
  66. package/src/node/terminal-process.ts +290 -290
  67. package/src/node/test/process-fork-test.js +22 -22
  68. package/src/node/test/process-test-container.ts +27 -27
  69. package/src/node/utils.ts +79 -79
@@ -1,67 +1,67 @@
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 { ContainerModule, Container } from '@theia/core/shared/inversify';
18
- import { RawProcess, RawProcessOptions, RawProcessFactory, RawForkOptions } from './raw-process';
19
- import { TerminalProcess, TerminalProcessOptions, TerminalProcessFactory } from './terminal-process';
20
- import { TaskTerminalProcess, TaskTerminalProcessFactory } from './task-terminal-process';
21
- import { BackendApplicationContribution } from '@theia/core/lib/node';
22
- import { ProcessManager } from './process-manager';
23
- import { ILogger } from '@theia/core/lib/common';
24
- import { MultiRingBuffer, MultiRingBufferOptions } from './multi-ring-buffer';
25
-
26
- export default new ContainerModule(bind => {
27
- bind(RawProcess).toSelf().inTransientScope();
28
- bind(ProcessManager).toSelf().inSingletonScope();
29
- bind(BackendApplicationContribution).toService(ProcessManager);
30
- bind(ILogger).toDynamicValue(ctx => {
31
- const parentLogger = ctx.container.get<ILogger>(ILogger);
32
- return parentLogger.child('process');
33
- }).inSingletonScope().whenTargetNamed('process');
34
- bind(RawProcessFactory).toFactory(ctx =>
35
- (options: RawProcessOptions | RawForkOptions) => {
36
- const child = new Container({ defaultScope: 'Singleton' });
37
- child.parent = ctx.container;
38
-
39
- child.bind(RawProcessOptions).toConstantValue(options);
40
- return child.get(RawProcess);
41
- }
42
- );
43
-
44
- bind(TerminalProcess).toSelf().inTransientScope();
45
- bind(TerminalProcessFactory).toFactory(ctx =>
46
- (options: TerminalProcessOptions) => {
47
- const child = new Container({ defaultScope: 'Singleton' });
48
- child.parent = ctx.container;
49
-
50
- child.bind(TerminalProcessOptions).toConstantValue(options);
51
- return child.get(TerminalProcess);
52
- }
53
- );
54
-
55
- bind(TaskTerminalProcess).toSelf().inTransientScope();
56
- bind(TaskTerminalProcessFactory).toFactory(ctx =>
57
- (options: TerminalProcessOptions) => {
58
- const child = ctx.container.createChild();
59
- child.bind(TerminalProcessOptions).toConstantValue(options);
60
- return child.get(TaskTerminalProcess);
61
- }
62
- );
63
-
64
- bind(MultiRingBuffer).toSelf().inTransientScope();
65
- /* 1MB size, TODO should be a user preference. */
66
- bind(MultiRingBufferOptions).toConstantValue({ size: 1048576 });
67
- });
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 { ContainerModule, Container } from '@theia/core/shared/inversify';
18
+ import { RawProcess, RawProcessOptions, RawProcessFactory, RawForkOptions } from './raw-process';
19
+ import { TerminalProcess, TerminalProcessOptions, TerminalProcessFactory } from './terminal-process';
20
+ import { TaskTerminalProcess, TaskTerminalProcessFactory } from './task-terminal-process';
21
+ import { BackendApplicationContribution } from '@theia/core/lib/node';
22
+ import { ProcessManager } from './process-manager';
23
+ import { ILogger } from '@theia/core/lib/common';
24
+ import { MultiRingBuffer, MultiRingBufferOptions } from './multi-ring-buffer';
25
+
26
+ export default new ContainerModule(bind => {
27
+ bind(RawProcess).toSelf().inTransientScope();
28
+ bind(ProcessManager).toSelf().inSingletonScope();
29
+ bind(BackendApplicationContribution).toService(ProcessManager);
30
+ bind(ILogger).toDynamicValue(ctx => {
31
+ const parentLogger = ctx.container.get<ILogger>(ILogger);
32
+ return parentLogger.child('process');
33
+ }).inSingletonScope().whenTargetNamed('process');
34
+ bind(RawProcessFactory).toFactory(ctx =>
35
+ (options: RawProcessOptions | RawForkOptions) => {
36
+ const child = new Container({ defaultScope: 'Singleton' });
37
+ child.parent = ctx.container;
38
+
39
+ child.bind(RawProcessOptions).toConstantValue(options);
40
+ return child.get(RawProcess);
41
+ }
42
+ );
43
+
44
+ bind(TerminalProcess).toSelf().inTransientScope();
45
+ bind(TerminalProcessFactory).toFactory(ctx =>
46
+ (options: TerminalProcessOptions) => {
47
+ const child = new Container({ defaultScope: 'Singleton' });
48
+ child.parent = ctx.container;
49
+
50
+ child.bind(TerminalProcessOptions).toConstantValue(options);
51
+ return child.get(TerminalProcess);
52
+ }
53
+ );
54
+
55
+ bind(TaskTerminalProcess).toSelf().inTransientScope();
56
+ bind(TaskTerminalProcessFactory).toFactory(ctx =>
57
+ (options: TerminalProcessOptions) => {
58
+ const child = ctx.container.createChild();
59
+ child.bind(TerminalProcessOptions).toConstantValue(options);
60
+ return child.get(TaskTerminalProcess);
61
+ }
62
+ );
63
+
64
+ bind(MultiRingBuffer).toSelf().inTransientScope();
65
+ /* 1MB size, TODO should be a user preference. */
66
+ bind(MultiRingBufferOptions).toConstantValue({ size: 1048576 });
67
+ });
@@ -1,107 +1,107 @@
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
- import { injectable, inject, named } from '@theia/core/shared/inversify';
17
- import { Emitter, Event } from '@theia/core/lib/common';
18
- import { ILogger } from '@theia/core/lib/common/logger';
19
- import { BackendApplicationContribution } from '@theia/core/lib/node';
20
- import { ManagedProcessManager, ManagedProcess } from '../common/process-manager-types';
21
- import { MAX_SAFE_INTEGER } from '@theia/core/lib/common/numbers';
22
- import { Process } from './process';
23
-
24
- @injectable()
25
- export class ProcessManager implements ManagedProcessManager, BackendApplicationContribution {
26
-
27
- protected readonly processes: Map<number, Process>;
28
- protected readonly deleteEmitter: Emitter<number>;
29
-
30
- constructor(
31
- @inject(ILogger) @named('process') protected logger: ILogger
32
- ) {
33
- this.processes = new Map();
34
- this.deleteEmitter = new Emitter<number>();
35
- }
36
-
37
- /**
38
- * Registers the given process into this manager. Both on process termination and on error,
39
- * the process will be automatically removed from the manager.
40
- *
41
- * @param process the process to register.
42
- */
43
- register(process: Process): number {
44
- const id = this.generateId();
45
- this.processes.set(id, process);
46
- process.onError(() => this.unregister(process));
47
- return id;
48
- }
49
-
50
- /**
51
- * @returns a random id for a process that is not assigned to a different process yet.
52
- */
53
- protected generateId(): number {
54
- let id = undefined;
55
- while (id === undefined) {
56
- const candidate = Math.floor(Math.random() * MAX_SAFE_INTEGER);
57
- if (!this.processes.has(candidate)) {
58
- id = candidate;
59
- }
60
- }
61
- return id;
62
- }
63
-
64
- /**
65
- * Removes the process from this process manager. Invoking this method, will make
66
- * sure that the process is terminated before eliminating it from the manager's cache.
67
- *
68
- * @param process the process to unregister from this process manager.
69
- */
70
- unregister(process: ManagedProcess): void {
71
- const processLabel = this.getProcessLabel(process);
72
- this.logger.debug(`Unregistering process. ${processLabel}`);
73
- if (!process.killed) {
74
- this.logger.debug(`Ensuring process termination. ${processLabel}`);
75
- process.kill();
76
- }
77
- if (this.processes.delete(process.id)) {
78
- this.deleteEmitter.fire(process.id);
79
- this.logger.debug(`The process was successfully unregistered. ${processLabel}`);
80
- } else {
81
- this.logger.warn(`This process was not registered or was already unregistered. ${processLabel}`);
82
- }
83
- }
84
-
85
- get(id: number): ManagedProcess | undefined {
86
- return this.processes.get(id);
87
- }
88
-
89
- get onDelete(): Event<number> {
90
- return this.deleteEmitter.event;
91
- }
92
-
93
- onStop(): void {
94
- for (const process of this.processes.values()) {
95
- try {
96
- this.unregister(process);
97
- } catch (error) {
98
- this.logger.error(`Error occurred when unregistering process. ${this.getProcessLabel(process)}`, error);
99
- }
100
- }
101
- }
102
-
103
- private getProcessLabel(process: ManagedProcess): string {
104
- return `[ID: ${process.id}]`;
105
- }
106
-
107
- }
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
+ import { injectable, inject, named } from '@theia/core/shared/inversify';
17
+ import { Emitter, Event } from '@theia/core/lib/common';
18
+ import { ILogger } from '@theia/core/lib/common/logger';
19
+ import { BackendApplicationContribution } from '@theia/core/lib/node';
20
+ import { ManagedProcessManager, ManagedProcess } from '../common/process-manager-types';
21
+ import { MAX_SAFE_INTEGER } from '@theia/core/lib/common/numbers';
22
+ import { Process } from './process';
23
+
24
+ @injectable()
25
+ export class ProcessManager implements ManagedProcessManager, BackendApplicationContribution {
26
+
27
+ protected readonly processes: Map<number, Process>;
28
+ protected readonly deleteEmitter: Emitter<number>;
29
+
30
+ constructor(
31
+ @inject(ILogger) @named('process') protected logger: ILogger
32
+ ) {
33
+ this.processes = new Map();
34
+ this.deleteEmitter = new Emitter<number>();
35
+ }
36
+
37
+ /**
38
+ * Registers the given process into this manager. Both on process termination and on error,
39
+ * the process will be automatically removed from the manager.
40
+ *
41
+ * @param process the process to register.
42
+ */
43
+ register(process: Process): number {
44
+ const id = this.generateId();
45
+ this.processes.set(id, process);
46
+ process.onError(() => this.unregister(process));
47
+ return id;
48
+ }
49
+
50
+ /**
51
+ * @returns a random id for a process that is not assigned to a different process yet.
52
+ */
53
+ protected generateId(): number {
54
+ let id = undefined;
55
+ while (id === undefined) {
56
+ const candidate = Math.floor(Math.random() * MAX_SAFE_INTEGER);
57
+ if (!this.processes.has(candidate)) {
58
+ id = candidate;
59
+ }
60
+ }
61
+ return id;
62
+ }
63
+
64
+ /**
65
+ * Removes the process from this process manager. Invoking this method, will make
66
+ * sure that the process is terminated before eliminating it from the manager's cache.
67
+ *
68
+ * @param process the process to unregister from this process manager.
69
+ */
70
+ unregister(process: ManagedProcess): void {
71
+ const processLabel = this.getProcessLabel(process);
72
+ this.logger.debug(`Unregistering process. ${processLabel}`);
73
+ if (!process.killed) {
74
+ this.logger.debug(`Ensuring process termination. ${processLabel}`);
75
+ process.kill();
76
+ }
77
+ if (this.processes.delete(process.id)) {
78
+ this.deleteEmitter.fire(process.id);
79
+ this.logger.debug(`The process was successfully unregistered. ${processLabel}`);
80
+ } else {
81
+ this.logger.warn(`This process was not registered or was already unregistered. ${processLabel}`);
82
+ }
83
+ }
84
+
85
+ get(id: number): ManagedProcess | undefined {
86
+ return this.processes.get(id);
87
+ }
88
+
89
+ get onDelete(): Event<number> {
90
+ return this.deleteEmitter.event;
91
+ }
92
+
93
+ onStop(): void {
94
+ for (const process of this.processes.values()) {
95
+ try {
96
+ this.unregister(process);
97
+ } catch (error) {
98
+ this.logger.error(`Error occurred when unregistering process. ${this.getProcessLabel(process)}`, error);
99
+ }
100
+ }
101
+ }
102
+
103
+ private getProcessLabel(process: ManagedProcess): string {
104
+ return `[ID: ${process.id}]`;
105
+ }
106
+
107
+ }