Skip to content

Commit

Permalink
fix(watch): 修正 windows 下无法正确启动新进程的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
caixw committed Sep 8, 2024
1 parent 9ed7855 commit fdfe5dd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/caixw/gobuild

require (
github.com/fsnotify/fsnotify v1.7.0
github.com/issue9/assert/v4 v4.3.0
github.com/issue9/assert/v4 v4.3.1
github.com/issue9/localeutil v0.27.2
github.com/issue9/source v0.11.5
github.com/issue9/term/v3 v3.3.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/issue9/assert/v4 v4.3.0 h1:W3XDKmttsfzihYGxJ9rJoL2ViJgWERB9IxfHcxjv65U=
github.com/issue9/assert/v4 v4.3.0/go.mod h1:v7qDRXi7AsaZZNh8eAK2rkLJg5/clztqQGA1DRv9Lv4=
github.com/issue9/assert/v4 v4.3.1 h1:dHYODk1yV7j/1baIB6K6UggI4r1Hfuljqic7PaDbwLg=
github.com/issue9/assert/v4 v4.3.1/go.mod h1:v7qDRXi7AsaZZNh8eAK2rkLJg5/clztqQGA1DRv9Lv4=
github.com/issue9/errwrap v0.3.2 h1:7KEme9Pfe75M+sIMcPCn/DV90wjnOcRbO4DXVAHj3Fw=
github.com/issue9/errwrap v0.3.2/go.mod h1:KcCLuUGiffjooLCUjL89r1cyO8/HT/VRcQrneO53N3A=
github.com/issue9/localeutil v0.27.2 h1:RkFLlDS/0W/YEIUUPyokdtegTp+DFMZ7/iR1V9OHUQg=
Expand Down
5 changes: 3 additions & 2 deletions watch/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io/fs"
"os"
"path/filepath"
"runtime"
"strings"
"time"

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

// 根据 wd 获取项目根目录,从而拿到需要监视的列表
Expand Down
8 changes: 7 additions & 1 deletion watch/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package watch

import (
"path/filepath"
"runtime"
"strings"
"testing"

Expand All @@ -21,7 +22,12 @@ func TestOptions_sanitize(t *testing.T) {
opt.MainFiles = "./"
a.NotError(opt.sanitize()).
Equal(opt.WatcherFrequency, MinWatcherFrequency).
True(strings.HasSuffix(opt.appName, "watch"))
When(runtime.GOOS == "windows", func(a *assert.Assertion) {
a.True(strings.HasSuffix(opt.appName, "watch.exe"))
}).
When(runtime.GOOS != "windows", func(a *assert.Assertion) {
a.True(strings.HasSuffix(opt.appName, "watch"))
})

opt.Excludes = []string{}
a.NotError(opt.sanitize())
Expand Down

0 comments on commit fdfe5dd

Please sign in to comment.