mirror of
https://github.com/zhigang1992/esbuild.git
synced 2026-01-12 22:46:54 +08:00
flush deferred warnings before writing to stdout
This commit is contained in:
@@ -21,7 +21,13 @@ const defaultTerminalWidth = 80
|
|||||||
type Log struct {
|
type Log struct {
|
||||||
AddMsg func(Msg)
|
AddMsg func(Msg)
|
||||||
HasErrors func() bool
|
HasErrors func() bool
|
||||||
Done func() []Msg
|
|
||||||
|
// This is called after the build has finished but before writing to stdout.
|
||||||
|
// It exists to ensure that deferred warning messages end up in the terminal
|
||||||
|
// before the data written to stdout.
|
||||||
|
AlmostDone func()
|
||||||
|
|
||||||
|
Done func() []Msg
|
||||||
}
|
}
|
||||||
|
|
||||||
type LogLevel int8
|
type LogLevel int8
|
||||||
@@ -351,6 +357,31 @@ func NewStderrLog(options OutputOptions) Log {
|
|||||||
remainingMessagesBeforeLimit = 0x7FFFFFFF
|
remainingMessagesBeforeLimit = 0x7FFFFFFF
|
||||||
}
|
}
|
||||||
var deferredWarnings []Msg
|
var deferredWarnings []Msg
|
||||||
|
didFinalizeLog := false
|
||||||
|
|
||||||
|
finalizeLog := func() {
|
||||||
|
if didFinalizeLog {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
didFinalizeLog = true
|
||||||
|
|
||||||
|
// Print the deferred warning now if there was no error after all
|
||||||
|
for remainingMessagesBeforeLimit > 0 && len(deferredWarnings) > 0 {
|
||||||
|
shownWarnings++
|
||||||
|
writeStringWithColor(os.Stderr, deferredWarnings[0].String(options, terminalInfo))
|
||||||
|
deferredWarnings = deferredWarnings[1:]
|
||||||
|
remainingMessagesBeforeLimit--
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print out a summary
|
||||||
|
if options.MessageLimit > 0 && errors+warnings > options.MessageLimit {
|
||||||
|
writeStringWithColor(os.Stderr, fmt.Sprintf("%s shown (disable the message limit with --error-limit=0)\n",
|
||||||
|
errorAndWarningSummary(errors, warnings, shownErrors, shownWarnings)))
|
||||||
|
} else if options.LogLevel <= LevelInfo && (warnings != 0 || errors != 0) {
|
||||||
|
writeStringWithColor(os.Stderr, fmt.Sprintf("%s\n",
|
||||||
|
errorAndWarningSummary(errors, warnings, shownErrors, shownWarnings)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch options.Color {
|
switch options.Color {
|
||||||
case ColorNever:
|
case ColorNever:
|
||||||
@@ -411,27 +442,17 @@ func NewStderrLog(options OutputOptions) Log {
|
|||||||
defer mutex.Unlock()
|
defer mutex.Unlock()
|
||||||
return hasErrors
|
return hasErrors
|
||||||
},
|
},
|
||||||
|
AlmostDone: func() {
|
||||||
|
mutex.Lock()
|
||||||
|
defer mutex.Unlock()
|
||||||
|
|
||||||
|
finalizeLog()
|
||||||
|
},
|
||||||
Done: func() []Msg {
|
Done: func() []Msg {
|
||||||
mutex.Lock()
|
mutex.Lock()
|
||||||
defer mutex.Unlock()
|
defer mutex.Unlock()
|
||||||
|
|
||||||
// Print the deferred warning now if there was no error after all
|
finalizeLog()
|
||||||
for remainingMessagesBeforeLimit > 0 && len(deferredWarnings) > 0 {
|
|
||||||
shownWarnings++
|
|
||||||
writeStringWithColor(os.Stderr, deferredWarnings[0].String(options, terminalInfo))
|
|
||||||
deferredWarnings = deferredWarnings[1:]
|
|
||||||
remainingMessagesBeforeLimit--
|
|
||||||
}
|
|
||||||
|
|
||||||
// Print out a summary
|
|
||||||
if options.MessageLimit > 0 && errors+warnings > options.MessageLimit {
|
|
||||||
writeStringWithColor(os.Stderr, fmt.Sprintf("%s shown (disable the message limit with --error-limit=0)\n",
|
|
||||||
errorAndWarningSummary(errors, warnings, shownErrors, shownWarnings)))
|
|
||||||
} else if options.LogLevel <= LevelInfo && (warnings != 0 || errors != 0) {
|
|
||||||
writeStringWithColor(os.Stderr, fmt.Sprintf("%s\n",
|
|
||||||
errorAndWarningSummary(errors, warnings, shownErrors, shownWarnings)))
|
|
||||||
}
|
|
||||||
|
|
||||||
sort.Stable(msgs)
|
sort.Stable(msgs)
|
||||||
return msgs
|
return msgs
|
||||||
},
|
},
|
||||||
@@ -759,6 +780,8 @@ func NewDeferLog() Log {
|
|||||||
defer mutex.Unlock()
|
defer mutex.Unlock()
|
||||||
return hasErrors
|
return hasErrors
|
||||||
},
|
},
|
||||||
|
AlmostDone: func() {
|
||||||
|
},
|
||||||
Done: func() []Msg {
|
Done: func() []Msg {
|
||||||
mutex.Lock()
|
mutex.Lock()
|
||||||
defer mutex.Unlock()
|
defer mutex.Unlock()
|
||||||
|
|||||||
@@ -774,6 +774,9 @@ func rebuildImpl(
|
|||||||
|
|
||||||
// Stop now if there were errors
|
// Stop now if there were errors
|
||||||
if !log.HasErrors() {
|
if !log.HasErrors() {
|
||||||
|
// Flush any deferred warnings now
|
||||||
|
log.AlmostDone()
|
||||||
|
|
||||||
if buildOpts.Write {
|
if buildOpts.Write {
|
||||||
// Special-case writing to stdout
|
// Special-case writing to stdout
|
||||||
if options.WriteToStdout {
|
if options.WriteToStdout {
|
||||||
|
|||||||
Reference in New Issue
Block a user