Просмотр исходного кода

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

Lucas Fernandes Nogueira 4 лет назад
Родитель
Сommit
ac2cbcb131
2 измененных файлов с 17 добавлено и 1 удалено
  1. 5 0
      .changes/fix-before-dev-command-kill.md
  2. 12 1
      tooling/cli.rs/src/dev.rs

+ 5 - 0
.changes/fix-before-dev-command-kill.md

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

+ 12 - 1
tooling/cli.rs/src/dev.rs

@@ -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();
   }
 }