improbable-eng / ts-protoc-gen

Protocol Buffers Compiler (protoc) plugin for TypeScript and gRPC-Web.
Apache License 2.0
1.36k stars 173 forks source link

Add plugin param to only generate gRPC types #292

Closed tatemz closed 2 years ago

tatemz commented 2 years ago

Changes

This change adds the grpcOnly parameter to the plugin in order to handle the cases where the user wants to exclusively generate the types for the grpc service only.

Prior to this change, users could not use grpc-tools, grpc-web, and ts-protoc-gen simultaneously.

After this change, it is possible to let grpc-web generate the .d.ts files (using the commonjs+dts or typescript options) for the non-gRPC generated files, while letting ts-protoc-gen singularly manage the generation of the .d.ts files for grpc-node

Verification

Tested it with the following buf.gen.yml configuration:

version: v1

plugins:
  - name: js
    out: ./__generated/proto/js
    opt:
      - import_style=commonjs,binary

  - name: grpc-node
    path: ./node_modules/.bin/grpc_tools_node_protoc_plugin
    out: ./__generated/proto/js

  - name: grpc-web
    path: ./node_modules/.bin/protoc-gen-grpc-web
    out: ./__generated/proto/js
    opt:
      - import_style=commonjs+dts
      - mode=grpcweb

  - name: ts-node
    path: ~/Development/ts-protoc-gen/bin/protoc-gen-ts
    out: ./__generated/proto/js
    opt:
      - service=grpc-node
      - grpcOnly=true
improbable-prow-robot commented 2 years ago

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: To complete the pull request process, please assign marcuslongmuir You can assign the PR to them by writing /assign @marcuslongmuir in a comment when ready.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files: - **[OWNERS](https://github.com/improbable-eng/ts-protoc-gen/blob/master/OWNERS)** Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment
tatemz commented 2 years ago

Dev Note: This feature may not be needed by most, but I found that it is helpful when wanting to generate for grpc-node and grpc-web simultaneously. Feel free to suggest any alternative methods for accomplishing this.

I was hoping that grpc-tools allowed for the commonjs+dts option, but it does not, and the proto-loader is not a protoc plugin - https://github.com/grpc/proposal/pull/183#discussion_r453237722

tatemz commented 2 years ago

/assign @marcuslongmuir

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.