diff --git a/internal/bundler/bundler.go b/internal/bundler/bundler.go index ee4ff1a0711..b025f4d398d 100644 --- a/internal/bundler/bundler.go +++ b/internal/bundler/bundler.go @@ -1751,7 +1751,7 @@ func (cache *runtimeCache) parseRuntime(options *config.Options) (source logger. if log.HasErrors() { msgs := "Internal error: failed to parse runtime:\n" for _, msg := range log.Done() { - msgs += msg.String(logger.StderrOptions{}, logger.TerminalInfo{}) + msgs += msg.String(logger.OutputOptions{}, logger.TerminalInfo{}) } panic(msgs[:len(msgs)-1]) } diff --git a/internal/bundler/bundler_test.go b/internal/bundler/bundler_test.go index f563590da6f..a2d2b014779 100644 --- a/internal/bundler/bundler_test.go +++ b/internal/bundler/bundler_test.go @@ -48,7 +48,7 @@ func assertLog(t *testing.T, msgs []logger.Msg, expected string) { t.Helper() text := "" for _, msg := range msgs { - text += msg.String(logger.StderrOptions{}, logger.TerminalInfo{}) + text += msg.String(logger.OutputOptions{}, logger.TerminalInfo{}) } assertEqual(t, text, expected) } diff --git a/internal/css_lexer/css_lexer_test.go b/internal/css_lexer/css_lexer_test.go index fc81a38fdd5..0eddbf8b74d 100644 --- a/internal/css_lexer/css_lexer_test.go +++ b/internal/css_lexer/css_lexer_test.go @@ -22,7 +22,7 @@ func lexerError(contents string) string { Tokenize(log, test.SourceForTest(contents)) text := "" for _, msg := range log.Done() { - text += msg.String(logger.StderrOptions{}, logger.TerminalInfo{}) + text += msg.String(logger.OutputOptions{}, logger.TerminalInfo{}) } return text } diff --git a/internal/css_parser/css_parser_test.go b/internal/css_parser/css_parser_test.go index ff89be35aba..f7e34943e2f 100644 --- a/internal/css_parser/css_parser_test.go +++ b/internal/css_parser/css_parser_test.go @@ -26,7 +26,7 @@ func expectParseError(t *testing.T, contents string, expected string) { msgs := log.Done() text := "" for _, msg := range msgs { - text += msg.String(logger.StderrOptions{}, logger.TerminalInfo{}) + text += msg.String(logger.OutputOptions{}, logger.TerminalInfo{}) } test.AssertEqual(t, text, expected) }) @@ -45,7 +45,7 @@ func expectPrintedCommon(t *testing.T, name string, contents string, expected st text := "" for _, msg := range msgs { if msg.Kind == logger.Error { - text += msg.String(logger.StderrOptions{}, logger.TerminalInfo{}) + text += msg.String(logger.OutputOptions{}, logger.TerminalInfo{}) } } assertEqual(t, text, "") diff --git a/internal/css_printer/css_printer_test.go b/internal/css_printer/css_printer_test.go index 0e635eb9c8b..c75b5b2a60c 100644 --- a/internal/css_printer/css_printer_test.go +++ b/internal/css_printer/css_printer_test.go @@ -25,7 +25,7 @@ func expectPrintedCommon(t *testing.T, name string, contents string, expected st text := "" for _, msg := range msgs { if msg.Kind == logger.Error { - text += msg.String(logger.StderrOptions{}, logger.TerminalInfo{}) + text += msg.String(logger.OutputOptions{}, logger.TerminalInfo{}) } } assertEqual(t, text, "") diff --git a/internal/js_lexer/js_lexer_test.go b/internal/js_lexer/js_lexer_test.go index e1bfbc97251..9c93e653d21 100644 --- a/internal/js_lexer/js_lexer_test.go +++ b/internal/js_lexer/js_lexer_test.go @@ -53,7 +53,7 @@ func expectLexerError(t *testing.T, contents string, expected string) { msgs := log.Done() text := "" for _, msg := range msgs { - text += msg.String(logger.StderrOptions{}, logger.TerminalInfo{}) + text += msg.String(logger.OutputOptions{}, logger.TerminalInfo{}) } test.AssertEqual(t, text, expected) }) diff --git a/internal/js_parser/js_parser_test.go b/internal/js_parser/js_parser_test.go index 766479b22ee..bc7bcafa913 100644 --- a/internal/js_parser/js_parser_test.go +++ b/internal/js_parser/js_parser_test.go @@ -23,7 +23,7 @@ func expectParseErrorCommon(t *testing.T, contents string, expected string, opti msgs := log.Done() text := "" for _, msg := range msgs { - text += msg.String(logger.StderrOptions{}, logger.TerminalInfo{}) + text += msg.String(logger.OutputOptions{}, logger.TerminalInfo{}) } test.AssertEqual(t, text, expected) }) @@ -54,7 +54,7 @@ func expectPrintedCommon(t *testing.T, contents string, expected string, options text := "" for _, msg := range msgs { if msg.Kind != logger.Warning { - text += msg.String(logger.StderrOptions{}, logger.TerminalInfo{}) + text += msg.String(logger.OutputOptions{}, logger.TerminalInfo{}) } } test.AssertEqual(t, text, "") diff --git a/internal/js_parser/json_parser_test.go b/internal/js_parser/json_parser_test.go index db5fcdc2328..b182b50f28c 100644 --- a/internal/js_parser/json_parser_test.go +++ b/internal/js_parser/json_parser_test.go @@ -19,7 +19,7 @@ func expectParseErrorJSON(t *testing.T, contents string, expected string) { msgs := log.Done() text := "" for _, msg := range msgs { - text += msg.String(logger.StderrOptions{}, logger.TerminalInfo{}) + text += msg.String(logger.OutputOptions{}, logger.TerminalInfo{}) } test.AssertEqual(t, text, expected) }) @@ -42,7 +42,7 @@ func expectPrintedJSONWithWarning(t *testing.T, contents string, warning string, msgs := log.Done() text := "" for _, msg := range msgs { - text += msg.String(logger.StderrOptions{}, logger.TerminalInfo{}) + text += msg.String(logger.OutputOptions{}, logger.TerminalInfo{}) } test.AssertEqual(t, text, warning) if !ok { diff --git a/internal/js_parser/ts_parser_test.go b/internal/js_parser/ts_parser_test.go index 4501bb75267..ace01477d70 100644 --- a/internal/js_parser/ts_parser_test.go +++ b/internal/js_parser/ts_parser_test.go @@ -24,7 +24,7 @@ func expectParseErrorTS(t *testing.T, contents string, expected string) { msgs := log.Done() text := "" for _, msg := range msgs { - text += msg.String(logger.StderrOptions{}, logger.TerminalInfo{}) + text += msg.String(logger.OutputOptions{}, logger.TerminalInfo{}) } test.AssertEqual(t, text, expected) }) @@ -43,7 +43,7 @@ func expectPrintedTS(t *testing.T, contents string, expected string) { msgs := log.Done() text := "" for _, msg := range msgs { - text += msg.String(logger.StderrOptions{}, logger.TerminalInfo{}) + text += msg.String(logger.OutputOptions{}, logger.TerminalInfo{}) } test.AssertEqual(t, text, "") if !ok { @@ -73,7 +73,7 @@ func expectParseErrorTSX(t *testing.T, contents string, expected string) { msgs := log.Done() text := "" for _, msg := range msgs { - text += msg.String(logger.StderrOptions{}, logger.TerminalInfo{}) + text += msg.String(logger.OutputOptions{}, logger.TerminalInfo{}) } test.AssertEqual(t, text, expected) }) @@ -95,7 +95,7 @@ func expectPrintedTSX(t *testing.T, contents string, expected string) { msgs := log.Done() text := "" for _, msg := range msgs { - text += msg.String(logger.StderrOptions{}, logger.TerminalInfo{}) + text += msg.String(logger.OutputOptions{}, logger.TerminalInfo{}) } test.AssertEqual(t, text, "") if !ok { diff --git a/internal/js_printer/js_printer_test.go b/internal/js_printer/js_printer_test.go index 99f8c5dfcc8..ff2442f582c 100644 --- a/internal/js_printer/js_printer_test.go +++ b/internal/js_printer/js_printer_test.go @@ -30,7 +30,7 @@ func expectPrintedCommon(t *testing.T, name string, contents string, expected st msgs := log.Done() text := "" for _, msg := range msgs { - text += msg.String(logger.StderrOptions{}, logger.TerminalInfo{}) + text += msg.String(logger.OutputOptions{}, logger.TerminalInfo{}) } assertEqual(t, text, "") if !ok { diff --git a/internal/logger/logger.go b/internal/logger/logger.go index 48254eb3174..7672be5563d 100644 --- a/internal/logger/logger.go +++ b/internal/logger/logger.go @@ -279,7 +279,7 @@ type TerminalInfo struct { Width int } -func NewStderrLog(options StderrOptions) Log { +func NewStderrLog(options OutputOptions) Log { var mutex sync.Mutex var msgs SortableMsgs terminalInfo := GetTerminalInfo(os.Stderr) @@ -351,8 +351,8 @@ func PrintErrorToStderr(osArgs []string, text string) { PrintMessageToStderr(osArgs, Msg{Kind: Error, Data: MsgData{Text: text}}) } -func StderrOptionsForArgs(osArgs []string) StderrOptions { - options := StderrOptions{IncludeSource: true} +func OutputOptionsForArgs(osArgs []string) OutputOptions { + options := OutputOptions{IncludeSource: true} // Implement a mini argument parser so these options always work even if we // haven't yet gotten to the general-purpose argument parsing code @@ -377,7 +377,7 @@ func StderrOptionsForArgs(osArgs []string) StderrOptions { } func PrintMessageToStderr(osArgs []string, msg Msg) { - log := NewStderrLog(StderrOptionsForArgs(osArgs)) + log := NewStderrLog(OutputOptionsForArgs(osArgs)) log.AddMsg(msg) log.Done() } @@ -392,7 +392,7 @@ type Colors struct { } func PrintText(file *os.File, level LogLevel, osArgs []string, callback func(Colors) string) { - options := StderrOptionsForArgs(osArgs) + options := OutputOptionsForArgs(osArgs) // Skip logging these if these logs are disabled if options.LogLevel > level { @@ -458,22 +458,22 @@ const colorBold = "\033[1m" const colorResetBold = "\033[0;1m" const colorResetUnderline = "\033[0;4m" -type StderrColor uint8 +type UseColor uint8 const ( - ColorIfTerminal StderrColor = iota + ColorIfTerminal UseColor = iota ColorNever ColorAlways ) -type StderrOptions struct { +type OutputOptions struct { IncludeSource bool ErrorLimit int - Color StderrColor + Color UseColor LogLevel LogLevel } -func (msg Msg) String(options StderrOptions, terminalInfo TerminalInfo) string { +func (msg Msg) String(options OutputOptions, terminalInfo TerminalInfo) string { // Compute the maximum margin maxMargin := 0 if options.IncludeSource { @@ -515,7 +515,7 @@ func emptyMarginText(maxMargin int) string { return fmt.Sprintf(" %s ╵ ", strings.Repeat(" ", maxMargin)) } -func msgString(options StderrOptions, terminalInfo TerminalInfo, kind MsgKind, data MsgData, maxMargin int) string { +func msgString(options OutputOptions, terminalInfo TerminalInfo, kind MsgKind, data MsgData, maxMargin int) string { var kindColor string textColor := colorBold textResetColor := colorResetBold diff --git a/pkg/api/api_impl.go b/pkg/api/api_impl.go index ccdaf096bac..43662d498d8 100644 --- a/pkg/api/api_impl.go +++ b/pkg/api/api_impl.go @@ -70,7 +70,7 @@ func validateSourceMap(value SourceMap) config.SourceMap { } } -func validateColor(value StderrColor) logger.StderrColor { +func validateColor(value StderrColor) logger.UseColor { switch value { case ColorIfTerminal: return logger.ColorIfTerminal @@ -506,7 +506,7 @@ func convertMessagesToInternal(msgs []logger.Msg, kind logger.MsgKind, messages // Build API func buildImpl(buildOpts BuildOptions) BuildResult { - logOptions := logger.StderrOptions{ + logOptions := logger.OutputOptions{ IncludeSource: true, ErrorLimit: buildOpts.ErrorLimit, Color: validateColor(buildOpts.Color), @@ -524,7 +524,7 @@ func rebuildImpl( buildOpts BuildOptions, caches *cache.CacheSet, plugins []config.Plugin, - logOptions logger.StderrOptions, + logOptions logger.OutputOptions, log logger.Log, ) BuildResult { // Convert and validate the buildOpts @@ -736,7 +736,7 @@ func rebuildImpl( // Transform API func transformImpl(input string, transformOpts TransformOptions) TransformResult { - log := logger.NewStderrLog(logger.StderrOptions{ + log := logger.NewStderrLog(logger.OutputOptions{ IncludeSource: true, ErrorLimit: transformOpts.ErrorLimit, Color: validateColor(transformOpts.Color), @@ -1052,7 +1052,7 @@ func (h *apiHandler) notifyRequest(duration time.Duration, req *http.Request, st } func errorsToString(errors []Message) string { - stderrOptions := logger.StderrOptions{IncludeSource: true} + stderrOptions := logger.OutputOptions{IncludeSource: true} terminalOptions := logger.TerminalInfo{} sb := strings.Builder{} limit := 5