From 4e6fe3787c1885d3f3a9875fd4e086572a8f0085 Mon Sep 17 00:00:00 2001 From: vince-fugnitto Date: Thu, 9 Feb 2023 15:57:11 -0500 Subject: [PATCH] fix `pid` typings Signed-off-by: vince-fugnitto --- packages/core/src/electron-main/electron-main-application.ts | 4 +++- packages/plugin-dev/src/node/hosted-instance-manager.ts | 2 +- packages/plugin-dev/src/node/hosted-plugins-manager.ts | 2 +- packages/plugin-ext/src/hosted/node/hosted-plugin-process.ts | 4 ++-- packages/process/src/node/raw-process.ts | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/core/src/electron-main/electron-main-application.ts b/packages/core/src/electron-main/electron-main-application.ts index bcb213a46d07a..1a4d6d560fb92 100644 --- a/packages/core/src/electron-main/electron-main-application.ts +++ b/packages/core/src/electron-main/electron-main-application.ts @@ -496,7 +496,9 @@ export class ElectronMainApplication { try { // If we forked the process for the clusters, we need to manually terminate it. // See: https://github.com/eclipse-theia/theia/issues/835 - process.kill(backendProcess.pid); + if (backendProcess.pid) { + process.kill(backendProcess.pid); + } } catch (error) { // See https://man7.org/linux/man-pages/man2/kill.2.html#ERRORS if (error.code === 'ESRCH') { diff --git a/packages/plugin-dev/src/node/hosted-instance-manager.ts b/packages/plugin-dev/src/node/hosted-instance-manager.ts index c86deb06d9aa2..2feb8ab2dfe47 100644 --- a/packages/plugin-dev/src/node/hosted-instance-manager.ts +++ b/packages/plugin-dev/src/node/hosted-instance-manager.ts @@ -158,7 +158,7 @@ export abstract class AbstractHostedInstanceManager implements HostedInstanceMan terminate(): void { if (this.isPluginRunning) { - this.hostedPluginProcess.killProcessTree(this.hostedInstanceProcess.pid); + this.hostedPluginProcess.killProcessTree(this.hostedInstanceProcess.pid!); this.hostedPluginSupport.sendLog({ data: 'Hosted instance has been terminated', type: LogType.Info }); this.isPluginRunning = false; } else { diff --git a/packages/plugin-dev/src/node/hosted-plugins-manager.ts b/packages/plugin-dev/src/node/hosted-plugins-manager.ts index 400c26c0a47d8..fe726a3db8e7f 100644 --- a/packages/plugin-dev/src/node/hosted-plugins-manager.ts +++ b/packages/plugin-dev/src/node/hosted-plugins-manager.ts @@ -96,7 +96,7 @@ export class HostedPluginsManagerImpl implements HostedPluginsManager { throw new Error('Watcher is not running in ' + pluginPath); } - this.killProcessTree(watchProcess.pid); + this.killProcessTree(watchProcess.pid!); return Promise.resolve(); } diff --git a/packages/plugin-ext/src/hosted/node/hosted-plugin-process.ts b/packages/plugin-ext/src/hosted/node/hosted-plugin-process.ts index 85df499084cae..c336fedd4045f 100644 --- a/packages/plugin-ext/src/hosted/node/hosted-plugin-process.ts +++ b/packages/plugin-ext/src/hosted/node/hosted-plugin-process.ts @@ -126,7 +126,7 @@ export class HostedPluginProcess implements ServerPluginRunner { await waitForTerminated.promise; } - this.killProcessTree(cp.pid); + this.killProcessTree(cp.pid!); } killProcessTree(parentPid: number): void { @@ -206,7 +206,7 @@ export class HostedPluginProcess implements ServerPluginRunner { childProcess.stderr!.on('data', data => this.logger.error(`[${options.serverName}: ${childProcess.pid}] ${data.toString().trim()}`)); this.logger.debug(`[${options.serverName}: ${childProcess.pid}] IPC started`); - childProcess.once('exit', (code: number, signal: string) => this.onChildProcessExit(options.serverName, childProcess.pid, code, signal)); + childProcess.once('exit', (code: number, signal: string) => this.onChildProcessExit(options.serverName, childProcess.pid!, code, signal)); childProcess.on('error', err => this.onChildProcessError(err)); return childProcess; } diff --git a/packages/process/src/node/raw-process.ts b/packages/process/src/node/raw-process.ts index 60cf5e22727d3..e9485b877fb9a 100644 --- a/packages/process/src/node/raw-process.ts +++ b/packages/process/src/node/raw-process.ts @@ -144,7 +144,7 @@ export class RawProcess extends Process { if (!this.process) { throw new Error('process did not start correctly'); } - return this.process.pid; + return this.process.pid!; } kill(signal?: string): void {