From 9ab9b8de0c09eb2299aa6b6866422f97516bbbfc Mon Sep 17 00:00:00 2001 From: Aman Karmani Date: Fri, 19 Dec 2025 14:01:11 -0800 Subject: [PATCH] Support --pprofDir option with --watch --- internal/execute/tsc.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/internal/execute/tsc.go b/internal/execute/tsc.go index e314f4433f..d6cf0bf869 100644 --- a/internal/execute/tsc.go +++ b/internal/execute/tsc.go @@ -3,7 +3,10 @@ package execute import ( "context" "fmt" + "os" + "os/signal" "strings" + "syscall" "github.com/microsoft/typescript-go/internal/ast" "github.com/microsoft/typescript-go/internal/collections" @@ -107,7 +110,18 @@ func tscCompilation(sys tsc.System, commandLine *tsoptions.ParsedCommandLine, te if pprofDir := commandLine.CompilerOptions().PprofDir; pprofDir != "" { // !!! stderr? profileSession := pprof.BeginProfiling(pprofDir, sys.Writer()) - defer profileSession.Stop() + + if commandLine.CompilerOptions().Watch.IsTrue() { + go func() { + ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) + defer stop() + <-ctx.Done() + profileSession.Stop() + os.Exit(int(tsc.ExitStatusSuccess)) + }() + } else { + defer profileSession.Stop() + } } if commandLine.CompilerOptions().Init.IsTrue() {