-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for @grpc/grpc-js #236
Add support for @grpc/grpc-js #236
Conversation
Add mode=grpc-js example
BTW, I tried installing the
ran it, and got this error:
It seems the |
The lib directory is only built on Line 15 in 3e58c65
|
Thanks for the quick response. Any suggestions on what I should do to make it work? Or should I stick with |
Quick fix: sed -i -- 's/import \* as grpc from "grpc";/import \* as grpc from "@grpc\/grpc-js";/g' * |
if you want to continue using this package, then you're going to have to stick with sed. but as mentioned here grpc/grpc-node#1380 (comment), I would suggest to try the new typescript generator offered by the author of grpc-js |
Hi @badsyntax, Any plans to merge this PR? |
I can't merge as I'm not the owner of this repo. Not sure why I haven't got a review yet :( |
@MarcusLongmuir Can you please help? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution! Apologies for the long delay in waiting for a review. This had gone under the radar.
Only a few minor things 👍
src/service/grpcnode.ts
Outdated
@@ -4,12 +4,12 @@ import {FileDescriptorProto} from "google-protobuf/google/protobuf/descriptor_pb | |||
import {CodeGeneratorResponse} from "google-protobuf/google/protobuf/compiler/plugin_pb"; | |||
import {createFile, RPCDescriptor, GrpcServiceDescriptor, RPCMethodDescriptor} from "./common"; | |||
|
|||
export function generateGrpcNodeService(filename: string, descriptor: FileDescriptorProto, exportMap: ExportMap): CodeGeneratorResponse.File { | |||
export function generateGrpcNodeService(filename: string, descriptor: FileDescriptorProto, exportMap: ExportMap, modeParameter: string | undefined): CodeGeneratorResponse.File { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is only called from the index.ts
file so the argument could be an enum rather than an optional string to make the mode explicit.
src/index.ts
Outdated
|
||
if (parameter === "service=true") { | ||
if (service === "true") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The service
parameter should probably have more validation and helpful warnings, but this additional parameter makes that even clearer.
Can you add checks for the supported service
and mode
values and change this to throw exceptions if they're unrecognised to help users more quickly identify misconfigurations please?
ff7a82f
to
30751e5
Compare
I've made those changes: Running:
Shows: protoc-gen-ts error: Error: Unrecognised service parameter: grpc-nodde
at getServiceParameter (/Users/richardwillis/Projects/badsyntax/ts-protoc-gen/lib/util.js:155:19)
at Object.getParameterEnums (/Users/richardwillis/Projects/badsyntax/ts-protoc-gen/lib/util.js:173:18)
at /Users/richardwillis/Projects/badsyntax/ts-protoc-gen/lib/index.js:19:25
at Socket.<anonymous> (/Users/richardwillis/Projects/badsyntax/ts-protoc-gen/lib/util.js:74:9)
at Socket.emit (events.js:215:7)
at endReadableNT (_stream_readable.js:1183:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
--ts_out: protoc-gen-ts: Plugin failed with status code 1. Running:
Shows protoc-gen-ts error: Error: Unrecognised mode parameter: grpc-jss
at getModeParameter (/Users/richardwillis/Projects/badsyntax/ts-protoc-gen/lib/util.js:166:19)
at Object.getParameterEnums (/Users/richardwillis/Projects/badsyntax/ts-protoc-gen/lib/util.js:174:15)
at /Users/richardwillis/Projects/badsyntax/ts-protoc-gen/lib/index.js:19:25
at Socket.<anonymous> (/Users/richardwillis/Projects/badsyntax/ts-protoc-gen/lib/util.js:74:9)
at Socket.emit (events.js:215:7)
at endReadableNT (_stream_readable.js:1183:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
--ts_out: protoc-gen-ts: Plugin failed with status code 1. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for making those changes
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: avdeev, MarcusLongmuir, qingzhenyun The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Awesome, thanks! |
@badsyntax Thanks! Could you release it? |
thanks ! |
Unfortunately the repo and org setup appears to make that quite difficult without another maintainer so I'll have to do it in the morning when others come online. If you want to validate usage in the meantime there is now a published version on npm: https://www.npmjs.com/package/ts-protoc-gen/v/0.12.1-pre.6383416. I'll comment on this PR when the release goes out. |
|
Thanks for the release. I've tested the change in my project and it lgtm 👍 |
Refs #226, #234, grpc/grpc-node#1380
Add support for generating files that import
@grpc/grpc-js
instead ofgrpc
. This does not change the default behaviour of the package, but instead introduces a new param allowing you to opt-in to using@grpc/grpc-js
.Changes
mode
param, for example:Verification
I've only tested it via the generated examples. It's very similar to
service=grpc-node
other than changing the import paths.