From 8e3a2787b348bb5b578e592b842c5603d9f027c6 Mon Sep 17 00:00:00 2001 From: davemooreuws Date: Tue, 1 Mar 2022 13:40:32 +1100 Subject: [PATCH] fix: nodemon poll required for hot reload windows --- pkg/runtime/javascript.go | 12 +++++++++++- pkg/runtime/typescript.go | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/pkg/runtime/javascript.go b/pkg/runtime/javascript.go index ad22db962..2bbe4fef3 100644 --- a/pkg/runtime/javascript.go +++ b/pkg/runtime/javascript.go @@ -20,6 +20,7 @@ import ( "fmt" "io" "path/filepath" + osruntime "runtime" "strings" "github.com/docker/docker/api/types/mount" @@ -110,6 +111,15 @@ func (t *javascript) LaunchOptsForFunctionCollect(runCtx string) (LaunchOpts, er } func (t *javascript) LaunchOptsForFunction(runCtx string) (LaunchOpts, error) { + var cmd []string + + if osruntime.GOOS == "windows" { + // https://github.com/remy/nodemon#application-isnt-restarting + cmd = strslice.StrSlice{"--watch", "/app/**", "--ext", "ts,js,json", "-L", "--exec", "node " + "/app/" + filepath.ToSlash(t.handler)} + } else { + cmd = strslice.StrSlice{"--watch", "/app/**", "--ext", "ts,js,json", "--exec", "node " + "/app/" + filepath.ToSlash(t.handler)} + } + return LaunchOpts{ Mounts: []mount.Mount{ { @@ -120,6 +130,6 @@ func (t *javascript) LaunchOptsForFunction(runCtx string) (LaunchOpts, error) { }, TargetWD: "/app", Entrypoint: strslice.StrSlice{"nodemon"}, - Cmd: strslice.StrSlice{"--watch", "/app/**", "--ext", "ts,js,json", "--exec", "node " + "/app/" + filepath.ToSlash(t.handler)}, + Cmd: cmd, }, nil } diff --git a/pkg/runtime/typescript.go b/pkg/runtime/typescript.go index 3e0bfe2cf..17591e219 100644 --- a/pkg/runtime/typescript.go +++ b/pkg/runtime/typescript.go @@ -20,6 +20,7 @@ import ( "fmt" "io" "path/filepath" + osruntime "runtime" "strings" "github.com/docker/docker/api/types/mount" @@ -113,6 +114,15 @@ func (t *typescript) LaunchOptsForFunctionCollect(runCtx string) (LaunchOpts, er } func (t *typescript) LaunchOptsForFunction(runCtx string) (LaunchOpts, error) { + var cmd []string + + if osruntime.GOOS == "windows" { + // https://github.com/remy/nodemon#application-isnt-restarting + cmd = strslice.StrSlice{"--watch", "/app/**", "--ext", "ts,js,json", "-L", "--exec", "ts-node -T " + "/app/" + filepath.ToSlash(t.handler)} + } else { + cmd = strslice.StrSlice{"--watch", "/app/**", "--ext", "ts,js,json", "--exec", "ts-node -T " + "/app/" + filepath.ToSlash(t.handler)} + } + return LaunchOpts{ TargetWD: "/app", Mounts: []mount.Mount{ @@ -123,6 +133,6 @@ func (t *typescript) LaunchOptsForFunction(runCtx string) (LaunchOpts, error) { }, }, Entrypoint: strslice.StrSlice{"nodemon"}, - Cmd: strslice.StrSlice{"--watch", "/app/**", "--ext", "ts,js,json", "--exec", "ts-node -T " + "/app/" + filepath.ToSlash(t.handler)}, + Cmd: cmd, }, nil }