@@ -903,7 +903,6 @@ func contextImpl(buildOpts BuildOptions) (*internalContext, []Message) {
903
903
LogLevel : validateLogLevel (buildOpts .LogLevel ),
904
904
Overrides : validateLogOverrides (buildOpts .LogOverride ),
905
905
}
906
- log := logger .NewStderrLog (logOptions )
907
906
908
907
// Validate that the current working directory is an absolute path
909
908
absWorkingDir := buildOpts .AbsWorkingDir
@@ -916,6 +915,7 @@ func contextImpl(buildOpts BuildOptions) (*internalContext, []Message) {
916
915
DoNotCache : true ,
917
916
})
918
917
if err != nil {
918
+ log := logger .NewStderrLog (logOptions )
919
919
log .AddError (nil , logger.Range {}, err .Error ())
920
920
return nil , convertMessagesToPublic (logger .Error , log .Done ())
921
921
}
@@ -924,6 +924,7 @@ func contextImpl(buildOpts BuildOptions) (*internalContext, []Message) {
924
924
// directory doesn't change, since breaking that invariant would break the
925
925
// validation that we just did above.
926
926
caches := cache .MakeCacheSet ()
927
+ log := logger .NewDeferLog (logger .DeferLogNoVerboseOrDebug , logOptions .Overrides )
927
928
onEndCallbacks , onDisposeCallbacks , finalizeBuildOptions := loadPlugins (& buildOpts , realFS , log , caches )
928
929
options , entryPoints := validateBuildOptions (buildOpts , log , realFS )
929
930
finalizeBuildOptions (& options )
@@ -933,7 +934,19 @@ func contextImpl(buildOpts BuildOptions) (*internalContext, []Message) {
933
934
934
935
// If we have errors already, then refuse to build any further. This only
935
936
// happens when the build options themselves contain validation errors.
936
- if msgs := log .Done (); log .HasErrors () {
937
+ msgs := log .Done ()
938
+ if log .HasErrors () {
939
+ if logOptions .LogLevel < logger .LevelSilent {
940
+ // Print all deferred validation log messages to stderr. We defer all log
941
+ // messages that are generated above because warnings are re-printed for
942
+ // every rebuild and we don't want to double-print these warnings for the
943
+ // first build.
944
+ stderr := logger .NewStderrLog (logOptions )
945
+ for _ , msg := range msgs {
946
+ stderr .AddMsg (msg )
947
+ }
948
+ stderr .Done ()
949
+ }
937
950
return nil , convertMessagesToPublic (logger .Error , msgs )
938
951
}
939
952
@@ -942,6 +955,7 @@ func contextImpl(buildOpts BuildOptions) (*internalContext, []Message) {
942
955
onEndCallbacks : onEndCallbacks ,
943
956
onDisposeCallbacks : onDisposeCallbacks ,
944
957
logOptions : logOptions ,
958
+ logWarnings : msgs ,
945
959
entryPoints : entryPoints ,
946
960
options : options ,
947
961
mangleCache : buildOpts .MangleCache ,
@@ -1423,6 +1437,7 @@ type rebuildArgs struct {
1423
1437
onEndCallbacks []onEndCallback
1424
1438
onDisposeCallbacks []func ()
1425
1439
logOptions logger.OutputOptions
1440
+ logWarnings []logger.Msg
1426
1441
entryPoints []bundler.EntryPoint
1427
1442
options config.Options
1428
1443
mangleCache map [string ]interface {}
@@ -1440,6 +1455,11 @@ type rebuildState struct {
1440
1455
func rebuildImpl (args rebuildArgs , oldSummary buildSummary ) rebuildState {
1441
1456
log := logger .NewStderrLog (args .logOptions )
1442
1457
1458
+ // All validation warnings are repeated for every rebuild
1459
+ for _ , msg := range args .logWarnings {
1460
+ log .AddMsg (msg )
1461
+ }
1462
+
1443
1463
// Convert and validate the buildOpts
1444
1464
realFS , err := fs .RealFS (fs.RealFSOptions {
1445
1465
AbsWorkingDir : args .absWorkingDir ,
0 commit comments