From 0047552c2cd77be0e58eb6200f5db5b78583b8a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Eriksson?= Date: Sat, 14 Dec 2024 13:36:43 +0100 Subject: [PATCH] builder: make Stderr configurable --- pkg/builder/builder.go | 3 +++ v2/tsbuilder/tsbuilder.go | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/builder/builder.go b/pkg/builder/builder.go index 1ff56c0bf9..bfd1d90541 100644 --- a/pkg/builder/builder.go +++ b/pkg/builder/builder.go @@ -90,6 +90,9 @@ type ParseParams struct { Experiments *experiments.Set WorkingDir string ParseTests bool + + // Optional writer to redirect stderr to. + Stderr option.Option[io.Writer] } type ParseResult struct { diff --git a/v2/tsbuilder/tsbuilder.go b/v2/tsbuilder/tsbuilder.go index bd3e074fce..f118feaf7a 100644 --- a/v2/tsbuilder/tsbuilder.go +++ b/v2/tsbuilder/tsbuilder.go @@ -122,7 +122,13 @@ func (i *BuilderImpl) Parse(ctx context.Context, p builder.ParseParams) (*builde if err != nil { return nil, fmt.Errorf("unable to get stdin: %s", err) } - cmd.Stderr = os.Stderr + + if stderr, ok := p.Stderr.Get(); ok { + cmd.Stderr = stderr + } else { + cmd.Stderr = os.Stderr + } + if err := cmd.Start(); err != nil { return nil, fmt.Errorf("unable to start builder: %s", err) }