fix(cli.rs): `before dev` process kill, closes #1626 (#1700)

This commit is contained in:
Lucas Fernandes Nogueira 2021-05-04 11:27:10 -03:00 committed by GitHub
parent 2b4e2b7560
commit ac2cbcb131
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -0,0 +1,5 @@
---
"cli.rs": patch
---
Properly kill `beforeDevCommand` process.

View File

@ -29,7 +29,18 @@ static BEFORE_DEV: OnceCell<Mutex<Child>> = OnceCell::new();
fn kill_before_dev_process() {
if let Some(child) = BEFORE_DEV.get() {
let _ = child.lock().unwrap().kill();
let mut child = child.lock().unwrap();
#[cfg(windows)]
let _ = Command::new("powershell")
.arg("-Command")
.arg(format!("function Kill-Tree {{ Param([int]$ppid); Get-CimInstance Win32_Process | Where-Object {{ $_.ParentProcessId -eq $ppid }} | ForEach-Object {{ Kill-Tree $_.ProcessId }}; Stop-Process -Id $ppid }}; Kill-Tree {}", child.id()))
.status();
#[cfg(not(windows))]
let _ = Command::new("pkill")
.args(&["-TERM", "-P"])
.arg(child.id().to_string())
.status();
let _ = child.kill();
}
}