Fix, or at least a workaround, for (#1232) (#1247)

This commit is contained in:
BillBuilt 2022-03-12 01:30:25 -05:00 committed by GitHub
commit a52d68438b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -379,6 +379,13 @@ func runFrontendDevWatcherCommand(cwd string, devCommand string, wg *sync.WaitGr
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
cmd.Dir = dir
// not sure if this conditional is necessary, I mainly used it to prevent any issues with Windows
// since I do not have a Windows dev environment at the moment
// this conditional could be removed if found it causes no conflicts with Windows
if runtime.GOOS != "windows" {
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
}
go func(ctx context.Context, devCommand string, cwd string, wg *sync.WaitGroup) {
err := cmd.Run()
if err != nil {
@ -406,6 +413,19 @@ func runFrontendDevWatcherCommand(cwd string, devCommand string, wg *sync.WaitGr
}
}
} else {
// Experiencing the same issue on macOS BigSur
// I'm using Vite, but I would imagine this could be an issue with Node (npm) in general
// Also, after several edit/rebuild cycles any abnormal shutdown (crash or CTRL-C) may still leave Node running
// Credit: https://stackoverflow.com/a/29552044/14764450 (same page as the Windows solution above)
// Not tested on *nix
pgid, err := syscall.Getpgid(cmd.Process.Pid)
if err == nil {
err := syscall.Kill(-pgid, 15) // note the minus sign
if err != nil {
LogRed("Error from '%s' when attempting to kill the process: %s", devCommand, err.Error())
}
}
LogGreen("Dev command killed!")
cancel()
}
wg.Wait()