fix(electron): use tree-kill for electron dev (#5252)

electron process sometimes do not get re-spawned because of some child process not being closed.
use tree-kill instead.
This commit is contained in:
Peng Xiao
2023-12-11 04:26:19 +00:00
parent f0c70b92f4
commit e8cfc807ea
3 changed files with 5 additions and 2 deletions

View File

@@ -63,6 +63,7 @@
"rxjs": "^7.8.1", "rxjs": "^7.8.1",
"semver": "^7.5.4", "semver": "^7.5.4",
"tinykeys": "^2.1.0", "tinykeys": "^2.1.0",
"tree-kill": "^1.2.2",
"ts-node": "^10.9.1", "ts-node": "^10.9.1",
"undici": "^6.0.0", "undici": "^6.0.0",
"uuid": "^9.0.1", "uuid": "^9.0.1",

View File

@@ -4,6 +4,7 @@ import { resolve } from 'node:path';
import type { ChildProcessWithoutNullStreams } from 'child_process'; import type { ChildProcessWithoutNullStreams } from 'child_process';
import type { BuildContext } from 'esbuild'; import type { BuildContext } from 'esbuild';
import * as esbuild from 'esbuild'; import * as esbuild from 'esbuild';
import kill from 'tree-kill';
import { config, electronDir, rootDir } from './common'; import { config, electronDir, rootDir } from './common';
@@ -24,9 +25,9 @@ function spawnOrReloadElectron() {
if (watchMode) { if (watchMode) {
return; return;
} }
if (spawnProcess !== null) { if (spawnProcess !== null && spawnProcess.pid) {
spawnProcess.off('exit', process.exit); spawnProcess.off('exit', process.exit);
spawnProcess.kill('SIGINT'); kill(spawnProcess.pid);
spawnProcess = null; spawnProcess = null;
} }

View File

@@ -499,6 +499,7 @@ __metadata:
rxjs: "npm:^7.8.1" rxjs: "npm:^7.8.1"
semver: "npm:^7.5.4" semver: "npm:^7.5.4"
tinykeys: "npm:^2.1.0" tinykeys: "npm:^2.1.0"
tree-kill: "npm:^1.2.2"
ts-node: "npm:^10.9.1" ts-node: "npm:^10.9.1"
undici: "npm:^6.0.0" undici: "npm:^6.0.0"
uuid: "npm:^9.0.1" uuid: "npm:^9.0.1"