Skip to content

Commit c0b4f4f

Browse files
mc0Multiply
andauthored
Add grpc-node support (#134)
* Add `grpc-node` support - Refactor `typescript_proto_library` to generate only messages - Add `typescript_grpc_web_library` to provide previous functionality - Add `typescript_grpc_node_library` to add grpc-node support - Improve documentation - Add migration guide when coming from previous versions - Update `ts-protoc-gen` Co-authored-by: Jens Ulrich Hjuler Fosgerau <[email protected]>
1 parent aed1c82 commit c0b4f4f

14 files changed

+987
-2902
lines changed

README.md

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33

44
Bazel rules for generating TypeScript declarations for JavaScript protocol buffers using the
55
[ts-protoc-gen](https://github.com/improbable-eng/ts-protoc-gen) protoc plugin. These rules can also
6-
generate service definitions for use by [grpc-web](https://github.com/improbable-eng/grpc-web).
6+
generate service definitions for use by [grpc-web](https://github.com/improbable-eng/grpc-web) or
7+
[grpc-node](https://github.com/grpc/grpc-node).
78

89
## Getting Started
910

10-
> If you're migrating from the ts-protoc-gen rules, see [here](docs/migrating_from_ts_protoc_gen.md) for a migration guide
11+
> If you're upgrading from a previous version and experiencing issues with missing `_pb_service.d.ts` files, see
12+
> [here](docs/migrating_to_multi_rules.md) for a migration guide.
1113
1214
Before you can use `rules_typescript_proto`, you must first setup:
1315

@@ -61,7 +63,29 @@ will need to include the following dependencies at runtime yourself:
6163
- `@improbable-eng/grpc-web`
6264
- `browser-headers`
6365

64-
See `//test:pizza_service_proto_test_suite` for an example.
66+
For generating grpc output files, you'll also need the following in your `BUILD` file:
67+
```python
68+
# For grpc-web support use:
69+
typescript_grpc_web_library(
70+
name = "test_ts_grpc_web",
71+
proto = ":test_proto",
72+
)
73+
74+
# For grpc-node support use:
75+
typescript_grpc_node_library(
76+
name = "test_ts_grpc_node",
77+
proto = ":test_proto",
78+
)
79+
80+
# For grpc-node support with grpc-js use:
81+
typescript_grpc_node_library(
82+
name = "test_ts_grpc_node_grpc_js",
83+
proto = ":test_proto",
84+
use_grpc_js = True,
85+
)
86+
```
87+
88+
See `//test:pizza_service_proto_test_suite` and `//test:grpc_node_test` for examples.
6589

6690
## IDE Code Completion
6791

@@ -83,7 +107,8 @@ To get code completion working for the generated protos in your IDE, add the fol
83107
}
84108
```
85109

86-
> NOTE: This has only been tested in IntelliJ with the bazel plugin
110+
> NOTE: This has only been tested in IntelliJ and VSCode with the bazel plugin
111+
> NOTE: This assumes a default `--symlink_prefix` value.
87112
88113
## Contributing
89114

docs/migrating_to_multi_rules.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Migrating to multi_rules
2+
3+
Previously, the `typescript_proto_library` rule would also build grpc-web outputs automatically.
4+
5+
This is now split into multiple rules to align with other languages:
6+
- `typescript_proto_library` for outputting protobuf messages files (_pb.d.ts, _pb.js)
7+
- `typescript_grpc_node_library` for outputting protobuf service and client files (_grpc_pb.d.ts, _grpc_pb.js); supports both grpc and grpc-js requires
8+
- `typescript_grpc_web_library` for outputting protobuf service and client files (_pb_service.d.ts, _pb_service.js)
9+
10+
To keep the same behavior, add to your definition:
11+
```python
12+
# Before:
13+
typescript_proto_library(
14+
name = "test_ts_proto",
15+
proto = ":test_proto",
16+
)
17+
18+
# After:
19+
typescript_proto_library(
20+
name = "test_ts_proto",
21+
proto = ":test_proto",
22+
)
23+
typescript_grpc_web_library(
24+
name = "test_ts_grpc_web",
25+
proto = ":test_proto",
26+
)
27+
```

index.bzl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
load("//src:typescript_proto_library.bzl", _typescript_proto_library = "typescript_proto_library")
2+
load("//src:typescript_grpc_node_library.bzl", _typescript_grpc_node_library = "typescript_grpc_node_library")
3+
load("//src:typescript_grpc_web_library.bzl", _typescript_grpc_web_library = "typescript_grpc_web_library")
24
load("//src:rules_typescript_proto_dependencies.bzl", _rules_typescript_proto_dependencies = "rules_typescript_proto_dependencies")
35

46
rules_typescript_proto_dependencies = _rules_typescript_proto_dependencies
57
typescript_proto_library = _typescript_proto_library
8+
typescript_grpc_node_library = _typescript_grpc_node_library
9+
typescript_grpc_web_library = _typescript_grpc_web_library

0 commit comments

Comments
 (0)