Open nicksieger opened 11 months ago
Thanks a lot for your pr, let me have a look :)
Hi @nicksieger , I've made some investigation. Just like what you said, seems the release version has no such feature for now.
I tested the latest version with
$ protoc --version
libprotoc 3.20.3
$ grpc_tools_node_protoc --version
libprotoc 3.19.1
$ protoc \
--js_out=import_style=commonjs,binary,from_object:./src/grpcjs/proto \
--grpc_out=grpc_js:./src/grpcjs/proto \
--plugin=protoc-gen-grpc=`which grpc_tools_node_protoc_plugin` \
-I ./proto \
proto/*.proto
Seems no fromObject
methods generated in the js files
.
I'd like to test and apply your pr when it's officially released. Or could you please tell me how to build the protoc-gen-js you mentioned manually? I'm not familiar with this.
Sure, here's a Dockerfile snippet, or you can run these commands manually on Debian or Ubuntu.
FROM node:18-bookworm
ENV DEBIAN_FRONTEND=noninteractive
WORKDIR /root
RUN apt update && apt install -y bazel-bootstrap protobuf-compiler && rm -rf /var/lib/apt/lists/*
RUN curl -sL https://github.com/protocolbuffers/protobuf-javascript/archive/refs/tags/v3.21.2.tar.gz | tar zxf -
# Apply patch to enable 'fromClass' generation from https://github.com/protocolbuffers/protobuf-javascript/pull/162
RUN cd protobuf-javascript-3.21.2 && \
curl -sL https://github.com/protocolbuffers/protobuf-javascript/commit/a3c4522bbdab5784de0361049437242980df07d0.diff | patch -u -p1 && \
bazel build :plugin_files && cp bazel-bin/generator/protoc-gen-js /usr/local/bin
FYI, I'm using regular protoc
instead of grpc_tools_node_protoc
, the latter seems to bundle its own version of proto-gen-js.
protoc \
--plugin=protoc-gen-js="$(which protoc-gen-js)" \
--js_out=import_style=commonjs,binary:./protos \
--plugin=protoc-gen-grpc="$(which grpc_tools_node_protoc_plugin)" \
--grpc_out=grpc_js:./protos \
--plugin=protoc-gen-ts="$(which protoc-gen-ts)" \
--ts_out=grpc_js,from_object:./protos \
my-service.proto
FYI, I'm using regular
protoc
instead ofgrpc_tools_node_protoc
, the latter seems to bundle its own version of proto-gen-js.protoc \ --plugin=protoc-gen-js="$(which protoc-gen-js)" \ --js_out=import_style=commonjs,binary:./protos \ --plugin=protoc-gen-grpc="$(which grpc_tools_node_protoc_plugin)" \ --grpc_out=grpc_js:./protos \ --plugin=protoc-gen-ts="$(which protoc-gen-ts)" \ --ts_out=grpc_js,from_object:./protos \ my-service.proto
I have 2 questions:
--js_out=import_style=commonjs,binary:./protos
, seems there is no from_object
option enabled? Will there any fromObject function generated in js codes?protoc-gen-js
? Do you installed it by npm package? I saw one package could help to install this command globallyRUN
command is the one that builds protoc-gen-js and copies it to /usr/local/bin.
Currently, fromObject is only added by protoc-gen-js if you custom-build it (see protocolbuffers/protobuf-javascript#162 for an example patch).