Git Product home page Git Product logo

rules_typescript_proto's Introduction

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 or grpc-node.

Getting Started

If you're upgrading from a previous version and experiencing issues with missing _pb_service.d.ts files, 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 = "aac6dec2c8d55da2b2c2689b7a2afe44b691555cab32e2eaa2bdd29627d950e9",
    strip_prefix = "rules_typescript_proto-1.0.1",
    urls = [
        "https://github.com/Dig-Doug/rules_typescript_proto/archive/1.0.1.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

For generating grpc output files, you'll also need the following in your BUILD file:

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

# For grpc-web support use:
typescript_grpc_web_library(
  name = "test_ts_grpc_web",
  proto = ":test_proto",
)

# For grpc-node support use:
typescript_grpc_node_library(
  name = "test_ts_grpc_node",
  proto = ":test_proto",
)

# For grpc-node support with grpc-js use:
typescript_grpc_node_library(
  name = "test_ts_grpc_node_grpc_js",
  proto = ":test_proto",
  use_grpc_js = True,
)

See //test:pizza_service_proto_test_suite and //test:grpc_node_test for examples.

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 and VSCode with the bazel plugin NOTE: This assumes a default --symlink_prefix value.

Contributing

Contributions are welcome!

rules_typescript_proto's People

Contributors

renovate[bot] avatar dig-doug avatar dependabot[bot] avatar mc0 avatar purkhusid avatar eordano avatar mamogaaa avatar awmichel avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.