Skip to content

Commit b755b17

Browse files
committed
Support --pprofDir option with --watch
1 parent d9178cc commit b755b17

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

internal/execute/tsc.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ package execute
33
import (
44
"context"
55
"fmt"
6+
"os"
7+
"os/signal"
68
"strings"
9+
"syscall"
710

811
"github.com/microsoft/typescript-go/internal/ast"
912
"github.com/microsoft/typescript-go/internal/collections"
@@ -107,7 +110,16 @@ func tscCompilation(sys tsc.System, commandLine *tsoptions.ParsedCommandLine, te
107110
if pprofDir := commandLine.CompilerOptions().PprofDir; pprofDir != "" {
108111
// !!! stderr?
109112
profileSession := pprof.BeginProfiling(pprofDir, sys.Writer())
110-
defer profileSession.Stop()
113+
114+
if commandLine.CompilerOptions().Watch.IsTrue() {
115+
go func() {
116+
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
117+
defer stop()
118+
<-ctx.Done()
119+
profileSession.Stop()
120+
os.Exit(int(tsc.ExitStatusSuccess))
121+
}()
122+
}
111123
}
112124

113125
if commandLine.CompilerOptions().Init.IsTrue() {

0 commit comments

Comments
 (0)