Skip to content

Commit

Permalink
Merge pull request #121 from nitrictech/fix/nodemon-restart-windows
Browse files Browse the repository at this point in the history
fix: nodemon poll required for hot reload windows
  • Loading branch information
davemooreuws authored Mar 1, 2022
2 parents 389d679 + 8e3a278 commit 4426eb2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
12 changes: 11 additions & 1 deletion pkg/runtime/javascript.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"io"
"path/filepath"
osruntime "runtime"
"strings"

"github.com/docker/docker/api/types/mount"
Expand Down Expand Up @@ -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{
{
Expand All @@ -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
}
12 changes: 11 additions & 1 deletion pkg/runtime/typescript.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"io"
"path/filepath"
osruntime "runtime"
"strings"

"github.com/docker/docker/api/types/mount"
Expand Down Expand Up @@ -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{
Expand All @@ -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
}

0 comments on commit 4426eb2

Please sign in to comment.