0.0.1 • Published 5 years ago

rules_typescript_proto v0.0.1

Weekly downloads
3
License
Apache-2.0
Repository
github
Last release
5 years ago

rules_typescript_proto

npm.io

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",
    # TODO: Update these values to the latest version
    sha256 = "3ef93812b7c8589a5e7fbc7e9a8c1b2f9a982320f3e96443f8bcdd76b3ef6bc0",
    strip_prefix = "rules_typescript_proto-88de411e84ca05133f584633871f1f417a52095e",
    urls = [
        "https://github.com/Dig-Doug/rules_typescript_proto/archive/88de411e84ca05133f584633871f1f417a52095e.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!