Skip to content

Commit fdfe5dd

Browse files
committed
fix(watch): 修正 windows 下无法正确启动新进程的问题
1 parent 9ed7855 commit fdfe5dd

4 files changed

Lines changed: 13 additions & 6 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module github.com/caixw/gobuild
22

33
require (
44
github.com/fsnotify/fsnotify v1.7.0
5-
github.com/issue9/assert/v4 v4.3.0
5+
github.com/issue9/assert/v4 v4.3.1
66
github.com/issue9/localeutil v0.27.2
77
github.com/issue9/source v0.11.5
88
github.com/issue9/term/v3 v3.3.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
22
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
3-
github.com/issue9/assert/v4 v4.3.0 h1:W3XDKmttsfzihYGxJ9rJoL2ViJgWERB9IxfHcxjv65U=
4-
github.com/issue9/assert/v4 v4.3.0/go.mod h1:v7qDRXi7AsaZZNh8eAK2rkLJg5/clztqQGA1DRv9Lv4=
3+
github.com/issue9/assert/v4 v4.3.1 h1:dHYODk1yV7j/1baIB6K6UggI4r1Hfuljqic7PaDbwLg=
4+
github.com/issue9/assert/v4 v4.3.1/go.mod h1:v7qDRXi7AsaZZNh8eAK2rkLJg5/clztqQGA1DRv9Lv4=
55
github.com/issue9/errwrap v0.3.2 h1:7KEme9Pfe75M+sIMcPCn/DV90wjnOcRbO4DXVAHj3Fw=
66
github.com/issue9/errwrap v0.3.2/go.mod h1:KcCLuUGiffjooLCUjL89r1cyO8/HT/VRcQrneO53N3A=
77
github.com/issue9/localeutil v0.27.2 h1:RkFLlDS/0W/YEIUUPyokdtegTp+DFMZ7/iR1V9OHUQg=

watch/options.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"io/fs"
1010
"os"
1111
"path/filepath"
12+
"runtime"
1213
"strings"
1314
"time"
1415

@@ -84,8 +85,8 @@ func (opt *Options) sanitize() (err error) {
8485
}
8586
// BUG: 如果获得的 opt.wd == /,那么 appName 将是个非法值。
8687
opt.appName = filepath.Join(opt.wd, filepath.Base(opt.wd))
87-
if goexe := os.Getenv("GOEXE"); goexe != "" {
88-
opt.appName += goexe
88+
if runtime.GOOS == "windows" {
89+
opt.appName += ".exe"
8990
}
9091

9192
// 根据 wd 获取项目根目录,从而拿到需要监视的列表

watch/options_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package watch
66

77
import (
88
"path/filepath"
9+
"runtime"
910
"strings"
1011
"testing"
1112

@@ -21,7 +22,12 @@ func TestOptions_sanitize(t *testing.T) {
2122
opt.MainFiles = "./"
2223
a.NotError(opt.sanitize()).
2324
Equal(opt.WatcherFrequency, MinWatcherFrequency).
24-
True(strings.HasSuffix(opt.appName, "watch"))
25+
When(runtime.GOOS == "windows", func(a *assert.Assertion) {
26+
a.True(strings.HasSuffix(opt.appName, "watch.exe"))
27+
}).
28+
When(runtime.GOOS != "windows", func(a *assert.Assertion) {
29+
a.True(strings.HasSuffix(opt.appName, "watch"))
30+
})
2531

2632
opt.Excludes = []string{}
2733
a.NotError(opt.sanitize())

0 commit comments

Comments
 (0)