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

js_out path ignored for service=true #57

Open gertcuykens opened 6 years ago

gertcuykens commented 6 years ago

Please consider when service=true to use the js_out path to store the generated service js file instead of using, ts_out one. Alternatively if the previous isn't possible service=path/to/jsout maybe, thanks.

protoc -I=. grpc.proto \
  --js_out=import_style=commonjs,binary:./pkg \
  --plugin=protoc-gen-ts=/Users/gert/node/bin/protoc-gen-ts \
  --ts_out=service=true:./src

image

Junkern commented 6 years ago

This is also a thing I would like to have!

jonnyreeves commented 6 years ago

AFAIK there is no way to access flags (configuration) for other protoc-plugins, in other words, ts-protoc-gen can only read flags present in the ts_out parameter.

Your alternative suggestion should be possible however I'm not sure I see the use case; could this not be achieved with a post-build step?

gertcuykens commented 6 years ago

https://www.typescriptlang.org/docs/handbook/tsconfig-json.html

Please note that the compiler does not include files that can be possible outputs; e.g. if the input includes index.ts, then index.d.ts and index.js are excluded. In general, having files that differ only in extension next to each other is not recomended.

Sure it can be done post build, but for me that means ts-protoc-gen is the only cmd that need post processing in my generation chain.

jonnyreeves commented 6 years ago

Thanks for clarifying @gertcuykens; just to confirm, you want the ability to specify an alternative location to write the javascript files generated for the grpc-web service stubs? If so, my proposed flag syntax would be:

protoc -I=. grpc.proto \
  --js_out=import_style=commonjs,binary:./pkg \
  --plugin=protoc-gen-ts=/Users/gert/node/bin/protoc-gen-ts \
  --ts_out=service=true,service_out=./pkg:./src

Where the JavaScript files generated for the grpc-web services will be written to ./pkg and the .d.ts files will be written to ./src

Please can you confirm this would fit your intended use case, or suggest alternatives? Thanks.

gertcuykens commented 6 years ago

Yep that would be perfect. Maybe ommit service=true when using service_out=./pkg if possible, because service will always be true when using service out?

protoc -I=. grpc.proto \
  --js_out=import_style=commonjs,binary:./pkg \
  --plugin=protoc-gen-ts=/Users/gert/node/bin/protoc-gen-ts \
  --ts_out=service_out=./pkg:./src
easyCZ commented 6 years ago

I believe this is now obsolete as services are always generated in the latest version. @gertcuykens could you confirm the latest version of ts-protoc-gen resolves this problem?

gertcuykens commented 6 years ago

Nope ts-protoc-gen@0.7.6 still can't separate typescript files form js files each in there own directory