Skip to content

Realpage-SmartBuilding/rules_typescript_proto

 
 

Repository files navigation

rules_typescript_proto

Bazel rules for generating TypeScript declarations for JavaScript protocol buffers using the ts-protoc-gen protoc plugin. These rules can also generate service definitions for use by grpc-web.

Getting Started

If you're migrating from the ts-protoc-gen rules, see here for a migration guide

Before you can use rules_typescript_proto, you must first setup:

Once those are setup, add the following to your workspace:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# TODO: Setup rules_proto
# TODO: Setup rules_nodejs

http_archive(
    name = "rules_typescript_proto",
    sha256 = "51c7c5995f5de89ea1bbd64d956fd589f1c03357ab6768032930fadc2570f6a8",
    strip_prefix = "rules_typescript_proto-0.0.5",
    urls = [
        "https://github.com/Dig-Doug/rules_typescript_proto/archive/0.0.5.tar.gz",
    ],
)

load("@rules_typescript_proto//:index.bzl", "rules_typescript_proto_dependencies")

rules_typescript_proto_dependencies()

Then, in your BUILD file:

load("@rules_typescript_proto//:index.bzl", "typescript_proto_library")

proto_library(
  name = "test_proto",
  srcs = [
    "test.proto",
  ],
)

typescript_proto_library(
  name = "test_ts_proto",
  proto = ":test_proto",
)

You can now use the test_ts_proto target as a dep in other ts_library targets. However, you will need to include the following dependencies at runtime yourself:

  • google-protobuf
  • @improbable-eng/grpc-web
  • browser-headers

See //test:pizza_service_proto_test_suite for an example.

IDE Code Completion

To get code completion working for the generated protos in your IDE, add the following to your tsconfig.json:

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      // Replace <workspace-name> with the name of your workspace
      "<workspace-name>/*": [
        "*", // Enables absolute paths for src files in your project
        "bazel-bin/*" // Enables referencing generate protos with absolute paths
      ]
    }
  }
}

NOTE: This has only been tested in IntelliJ with the bazel plugin

Contributing

Contributions are welcome!

About

Bazel rules for generating TypeScript declarations for JavaScript protocol buffers

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Starlark 66.4%
  • TypeScript 24.4%
  • JavaScript 9.2%