From ac2cbcb131819e01074e1ed8fb6808260c56a027 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Tue, 4 May 2021 11:27:10 -0300 Subject: [PATCH] fix(cli.rs): `before dev` process kill, closes #1626 (#1700) --- .changes/fix-before-dev-command-kill.md | 5 +++++ tooling/cli.rs/src/dev.rs | 13 ++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 .changes/fix-before-dev-command-kill.md diff --git a/.changes/fix-before-dev-command-kill.md b/.changes/fix-before-dev-command-kill.md new file mode 100644 index 000000000..bd1b8ce4f --- /dev/null +++ b/.changes/fix-before-dev-command-kill.md @@ -0,0 +1,5 @@ +--- +"cli.rs": patch +--- + +Properly kill `beforeDevCommand` process. diff --git a/tooling/cli.rs/src/dev.rs b/tooling/cli.rs/src/dev.rs index d547e3b6a..5864f2b5d 100644 --- a/tooling/cli.rs/src/dev.rs +++ b/tooling/cli.rs/src/dev.rs @@ -29,7 +29,18 @@ static BEFORE_DEV: OnceCell> = 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(); } }