@@ -621,32 +621,26 @@ func (service *serviceType) handleBuildRequest(id uint32, request map[string]int
621
621
options .Plugins = append (options .Plugins , api.Plugin {
622
622
Name : "onEnd" ,
623
623
Setup : func (build api.PluginBuild ) {
624
- build .OnStart (func () (api.OnStartResult , error ) {
625
- activeBuild .mutex .Lock ()
626
- activeBuild .didGetRebuild = true
627
- activeBuild .mutex .Unlock ()
628
- return api.OnStartResult {}, nil
629
- })
630
-
631
624
build .OnEnd (func (result * api.BuildResult ) (api.OnEndResult , error ) {
632
625
// For performance, we only send JavaScript an "onEnd" message if
633
- // it's needed. It's only needed if there are any "onEnd" callbacks
634
- // registered or if JavaScript has called our "rebuild()" function
635
- // (since the result for "rebuild" is passed via the same mechanism).
626
+ // it's needed. It's only needed if one of the following is true:
627
+ //
628
+ // - There are any "onEnd" callbacks registered
629
+ // - JavaScript has called our "rebuild()" function
630
+ // - We are writing build output to JavaScript's stdout
631
+ //
636
632
// This is especially important if "write" is false since otherwise
637
633
// we'd unnecessarily send the entire contents of all output files!
638
634
//
639
635
// "If a tree falls in a forest and no one is
640
636
// around to hear it, does it make a sound?"
641
637
//
642
- if ! hasOnEndCallbacks {
643
- activeBuild .mutex .Lock ()
644
- didGetRebuild := activeBuild .didGetRebuild
645
- activeBuild .didGetRebuild = false
646
- activeBuild .mutex .Unlock ()
647
- if ! didGetRebuild {
648
- return api.OnEndResult {}, nil
649
- }
638
+ activeBuild .mutex .Lock ()
639
+ didGetRebuild := activeBuild .didGetRebuild
640
+ activeBuild .didGetRebuild = false
641
+ activeBuild .mutex .Unlock ()
642
+ if ! hasOnEndCallbacks && ! didGetRebuild && ! writeToStdout {
643
+ return api.OnEndResult {}, nil
650
644
}
651
645
request := resultToResponse (* result )
652
646
request ["command" ] = "on-end"
0 commit comments