github.com/stackb/rules_proto@v0.0.0-20240221195024-5428336c51f1/pkg/plugin/builtin/js_common_plugin.go (about)

     1  // for some bizarre reason, naming this file 'protoc_js.go' makes it be ignored
     2  // by the compiler?
     3  package builtin
     4  
     5  import (
     6  	"path"
     7  	"strings"
     8  
     9  	"github.com/bazelbuild/bazel-gazelle/label"
    10  	"github.com/stackb/rules_proto/pkg/protoc"
    11  )
    12  
    13  func init() {
    14  	protoc.Plugins().MustRegisterPlugin(&JsCommonPlugin{})
    15  }
    16  
    17  // JsCommonPlugin implements Plugin for the built-in protoc js/library plugin.
    18  type JsCommonPlugin struct{}
    19  
    20  // Name implements part of the Plugin interface.
    21  func (p *JsCommonPlugin) Name() string {
    22  	return "builtin:js:common"
    23  }
    24  
    25  // Configure implements part of the Plugin interface.
    26  func (p *JsCommonPlugin) Configure(ctx *protoc.PluginContext) *protoc.PluginConfiguration {
    27  	basename := strings.ToLower(ctx.ProtoLibrary.BaseName())
    28  	library := basename + "_pb.js"
    29  	if ctx.Rel != "" {
    30  		library = path.Join(ctx.Rel, library)
    31  	}
    32  
    33  	return &protoc.PluginConfiguration{
    34  		Label:   label.New("build_stack_rules_proto", "plugin/builtin", "commonjs"),
    35  		Outputs: []string{library},
    36  		Options: append(ctx.PluginConfig.GetOptions(), "import_style=commonjs"),
    37  	}
    38  }