github.com/stackb/rules_proto@v0.0.0-20240221195024-5428336c51f1/pkg/rule/rules_nodejs/proto_nodejs_library.go (about)

     1  package rules_nodejs
     2  
     3  import (
     4  	"github.com/bazelbuild/bazel-gazelle/rule"
     5  
     6  	"github.com/stackb/rules_proto/pkg/protoc"
     7  )
     8  
     9  const (
    10  	ProtoNodeJsLibraryRuleName   = "proto_nodejs_library"
    11  	ProtoNodeJsLibraryRuleSuffix = "_nodejs_library"
    12  )
    13  
    14  func init() {
    15  	protoc.Rules().MustRegisterRule("stackb:rules_proto:proto_nodejs_library", &protoNodeJsLibrary{})
    16  }
    17  
    18  // protoNodeJsLibrary implements LanguageRule for the 'proto_nodejs_library' rule from
    19  // @rules_proto.
    20  type protoNodeJsLibrary struct{}
    21  
    22  // Name implements part of the LanguageRule interface.
    23  func (s *protoNodeJsLibrary) Name() string {
    24  	return ProtoNodeJsLibraryRuleName
    25  }
    26  
    27  // KindInfo implements part of the LanguageRule interface.
    28  func (s *protoNodeJsLibrary) KindInfo() rule.KindInfo {
    29  	return jsLibraryKindInfo
    30  }
    31  
    32  // LoadInfo implements part of the LanguageRule interface.
    33  func (s *protoNodeJsLibrary) LoadInfo() rule.LoadInfo {
    34  	return rule.LoadInfo{
    35  		Name:    "@build_stack_rules_proto//rules/nodejs:proto_nodejs_library.bzl",
    36  		Symbols: []string{ProtoNodeJsLibraryRuleName},
    37  	}
    38  }
    39  
    40  // ProvideRule implements part of the LanguageRule interface.
    41  func (s *protoNodeJsLibrary) ProvideRule(cfg *protoc.LanguageRuleConfig, pc *protoc.ProtocConfiguration) protoc.RuleProvider {
    42  	outputs := pc.GetPluginOutputs("builtin:js:common")
    43  	if len(outputs) == 0 {
    44  		return nil
    45  	}
    46  	return &JsLibrary{
    47  		KindName:       ProtoNodeJsLibraryRuleName,
    48  		RuleNameSuffix: ProtoNodeJsLibraryRuleSuffix,
    49  		Outputs:        outputs,
    50  		RuleConfig:     cfg,
    51  		Config:         pc,
    52  		Resolver:       protoc.ResolveDepsAttr("deps", true),
    53  	}
    54  }