@opensumi/ide-process 2.21.9-rc-1671176957.0 → 2.21.9

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/package.json CHANGED
@@ -1,9 +1,8 @@
1
1
  {
2
2
  "name": "@opensumi/ide-process",
3
- "version": "2.21.9-rc-1671176957.0",
3
+ "version": "2.21.9",
4
4
  "files": [
5
- "lib",
6
- "src"
5
+ "lib"
7
6
  ],
8
7
  "license": "MIT",
9
8
  "main": "lib/index.js",
@@ -17,11 +16,11 @@
17
16
  "url": "git@github.com:opensumi/core.git"
18
17
  },
19
18
  "dependencies": {
20
- "@opensumi/ide-core-common": "2.21.9-rc-1671176957.0",
21
- "@opensumi/ide-core-node": "2.21.9-rc-1671176957.0"
19
+ "@opensumi/ide-core-common": "2.21.9",
20
+ "@opensumi/ide-core-node": "2.21.9"
22
21
  },
23
22
  "devDependencies": {
24
23
  "@opensumi/ide-dev-tool": "^1.3.1"
25
24
  },
26
- "gitHead": "81fe16f43c329c633bd8b2eeb737363c8f4e7110"
25
+ "gitHead": "6038a6faa5ad85bfb5acb721c1d39190fe674555"
27
26
  }
@@ -1,68 +0,0 @@
1
- import { ChildProcess } from 'child_process';
2
- import stream from 'stream';
3
-
4
- import { Event } from '@opensumi/ide-core-common';
5
-
6
- export const IProcessFactory = Symbol('IProcessFactory');
7
- export const IProcessManage = Symbol('IProcessManage');
8
- export const processManageServicePath = 'ProcessManageService';
9
-
10
- export interface IProcess {
11
- readonly process: ChildProcess | undefined;
12
- readonly outputStream: stream.Readable;
13
- readonly errorStream: stream.Readable;
14
- readonly inputStream: stream.Writable;
15
- readonly processManage: IProcessManage;
16
- pid: number | null;
17
- onStart: Event<unknown>;
18
- onExit: Event<IProcessExitEvent>;
19
- onError: Event<ProcessErrorEvent>;
20
- killed: boolean;
21
- dispose(signal?: string);
22
- }
23
-
24
- export interface IProcessFactory {
25
- create(options: ProcessOptions | ForkOptions): IProcess;
26
- }
27
-
28
- export interface IProcessManage {
29
- register(process: IProcess): boolean;
30
- unregister(process: IProcess): void;
31
- get(id: number): IProcess | undefined;
32
- onUnregister: Event<number>;
33
- dispose(): void;
34
- }
35
-
36
- export interface ProcessOptions<T = string> {
37
- readonly command: string;
38
- args?: T[];
39
- options?: {
40
- [key: string]: any;
41
- };
42
- }
43
-
44
- export interface ForkOptions {
45
- readonly modulePath: string;
46
- args?: string[];
47
- options?: object;
48
- }
49
-
50
- export interface IProcessExitEvent {
51
- // Exactly one of code and signal will be set.
52
- readonly code?: number;
53
- readonly signal?: string;
54
- }
55
-
56
- /**
57
- * Data emitted when a process has been successfully started.
58
- */
59
- // eslint-disable-next-line @typescript-eslint/no-empty-interface
60
- export interface IProcessStartEvent {}
61
-
62
- /**
63
- * Data emitted when a process has failed to start.
64
- */
65
- export interface ProcessErrorEvent extends Error {
66
- /** An errno-like error string (e.g. ENOENT). */
67
- code: string;
68
- }
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './common';
@@ -1,16 +0,0 @@
1
- import stream = require('stream');
2
-
3
- /**
4
- * A Node stream like `/dev/null`.
5
- *
6
- * Writing goes to a black hole, reading returns `EOF`.
7
- */
8
- export class DevNullStream extends stream.Duplex {
9
- _write(chunk: any, encoding: string, callback: (err?: Error) => void): void {
10
- callback();
11
- }
12
-
13
- _read(size: number): void {
14
- this.push(null);
15
- }
16
- }
package/src/node/index.ts DELETED
@@ -1,25 +0,0 @@
1
- import { Provider, Injectable } from '@opensumi/di';
2
- import { NodeModule } from '@opensumi/ide-core-node';
3
-
4
- import { IProcessManage, processManageServicePath, IProcessFactory } from '../common/';
5
-
6
- import { ProcessFactory } from './process';
7
- import { ProcessManage } from './process-manager';
8
-
9
- @Injectable()
10
- export class ProcessModule extends NodeModule {
11
- providers: Provider[] = [
12
- { token: IProcessManage, useClass: ProcessManage },
13
- { token: IProcessFactory, useClass: ProcessFactory },
14
- ];
15
-
16
- backServices = [
17
- {
18
- servicePath: processManageServicePath,
19
- token: IProcessManage,
20
- },
21
- ];
22
- }
23
-
24
- export * from './process';
25
- export * from './process-manager';
@@ -1,64 +0,0 @@
1
- import { Injectable } from '@opensumi/di';
2
- import { Disposable, getDebugLogger, Emitter, Event } from '@opensumi/ide-core-common';
3
-
4
- import { IProcessManage } from '../common/index';
5
-
6
- import { Process } from './process';
7
-
8
- const logger = getDebugLogger();
9
-
10
- @Injectable()
11
- export class ProcessManage extends Disposable implements IProcessManage {
12
- protected readonly processes: Map<number, Process>;
13
- protected readonly unregisterEmitter: Emitter<number>;
14
-
15
- constructor() {
16
- super();
17
- this.processes = new Map();
18
- this.unregisterEmitter = new Emitter<number>();
19
- }
20
-
21
- register(process: Process) {
22
- const id = process.pid;
23
-
24
- if (!id) {
25
- logger.error('The Process launch failed!');
26
- return false;
27
- }
28
- this.processes.set(id, process);
29
- process.onExit(() => this.unregister(process));
30
- process.onError(() => this.unregister(process));
31
- return true;
32
- }
33
-
34
- unregister(process: Process) {
35
- const id = process.pid;
36
- if (!process.killed) {
37
- process.dispose();
38
- }
39
- if (id && this.processes.delete(id)) {
40
- this.unregisterEmitter.fire(id);
41
- // logger.log(`The process was successfully unregistered. ${id}`);
42
- } else {
43
- logger.warn(`This process was not registered or was already unregistered. ${id || ''}`);
44
- }
45
- }
46
-
47
- get(id: number): Process | undefined {
48
- return this.processes.get(id);
49
- }
50
-
51
- get onUnregister(): Event<number> {
52
- return this.unregisterEmitter.event;
53
- }
54
-
55
- dispose() {
56
- this.processes.forEach((process, id) => {
57
- try {
58
- this.unregister(process);
59
- } catch (e) {
60
- logger.error(`Error occurred when unregistering process. ${id}`, e);
61
- }
62
- });
63
- }
64
- }
@@ -1,134 +0,0 @@
1
- import { ChildProcess, spawn, fork } from 'child_process';
2
- import stream from 'stream';
3
-
4
- import { Injectable, Autowired } from '@opensumi/di';
5
- import { Disposable, Emitter } from '@opensumi/ide-core-common';
6
-
7
- import {
8
- ProcessOptions,
9
- ForkOptions,
10
- IProcessStartEvent,
11
- IProcessExitEvent,
12
- ProcessErrorEvent,
13
- IProcessManage,
14
- IProcess,
15
- } from '../common/index';
16
-
17
- import { DevNullStream } from './dev-null-stream';
18
- import { ProcessManage } from './process-manager';
19
-
20
- @Injectable()
21
- export class ProcessFactory {
22
- constructor() {}
23
-
24
- @Autowired(IProcessManage)
25
- private readonly processManage: ProcessManage;
26
-
27
- create(options: ProcessOptions | ForkOptions): IProcess {
28
- return new Process(options, this.processManage);
29
- }
30
- }
31
-
32
- export class Process extends Disposable implements IProcess {
33
- readonly process: ChildProcess | undefined;
34
- readonly outputStream: stream.Readable;
35
- readonly errorStream: stream.Readable;
36
- readonly inputStream: stream.Writable;
37
- protected _killed = false;
38
-
39
- protected readonly startEmitter: Emitter<IProcessStartEvent> = new Emitter<IProcessStartEvent>();
40
- protected readonly exitEmitter: Emitter<IProcessExitEvent> = new Emitter<IProcessExitEvent>();
41
- protected readonly errorEmitter: Emitter<ProcessErrorEvent> = new Emitter<ProcessErrorEvent>();
42
-
43
- constructor(options: ProcessOptions | ForkOptions, readonly processManage: ProcessManage) {
44
- super();
45
- // About catching errors: spawn will sometimes throw directly
46
- // (EACCES on Linux), sometimes return a Process object with the pid
47
- // property undefined (ENOENT on Linux) and then emit an 'error' event.
48
- // For now, we try to normalize that into always emitting an 'error'
49
- // event.
50
- try {
51
- if (this.isForkOptions(options)) {
52
- this.process = fork(options.modulePath, options.args, options.options);
53
- } else {
54
- this.process = spawn(options.command, options.args, options.options);
55
- }
56
-
57
- this.process.on('error', (error: NodeJS.ErrnoException) => {
58
- error.code = error.code || 'Unknown error';
59
- this.errorEmitter.fire(error as ProcessErrorEvent);
60
- });
61
- this.process.on('exit', (exitCode: number, signal: string) => {
62
- // node's child_process exit sets the unused parameter to null,
63
- // but we want it to be undefined instead.
64
- this.emitOnExit({
65
- code: exitCode !== null ? exitCode : undefined,
66
- signal: signal !== null ? signal : undefined,
67
- });
68
- });
69
-
70
- this.outputStream = this.process.stdout || new DevNullStream();
71
- this.inputStream = this.process.stdin || new DevNullStream();
72
- this.errorStream = this.process.stderr || new DevNullStream();
73
-
74
- if (this.process.pid !== undefined) {
75
- this.processManage.register(this);
76
- process.nextTick(this.emitOnStart.bind(this));
77
- }
78
- } catch (error) {
79
- /* When an error is thrown, set up some fake streams, so the client
80
- code doesn't break because these field are undefined. */
81
- this.outputStream = new DevNullStream();
82
- this.inputStream = new DevNullStream();
83
- this.errorStream = new DevNullStream();
84
-
85
- /* Call the client error handler, but first give them a chance to register it. */
86
- process.nextTick(this.emitOnError.bind(this), error);
87
- }
88
- }
89
-
90
- protected isForkOptions(options: any): options is ForkOptions {
91
- return !!options && !!options.modulePath;
92
- }
93
-
94
- protected emitOnStart() {
95
- this.startEmitter.fire({});
96
- }
97
-
98
- protected emitOnError(err: ProcessErrorEvent) {
99
- this._killed = true;
100
- this.errorEmitter.fire(err);
101
- }
102
-
103
- protected emitOnExit(event: IProcessExitEvent) {
104
- this._killed = true;
105
- this.exitEmitter.fire(event);
106
- }
107
-
108
- get pid(): number | null {
109
- return this.process ? this.process.pid : null;
110
- }
111
-
112
- get onStart() {
113
- return this.startEmitter.event;
114
- }
115
-
116
- get onExit() {
117
- return this.exitEmitter.event;
118
- }
119
-
120
- get onError() {
121
- return this.errorEmitter.event;
122
- }
123
-
124
- get killed() {
125
- return this._killed;
126
- }
127
-
128
- dispose(signal?: string) {
129
- if (this.process && this.killed === false) {
130
- // TODO test window is work
131
- this.process.kill(signal);
132
- }
133
- }
134
- }