protobufjs / protobuf.js

Protocol Buffers for JavaScript & TypeScript.
Other
9.97k stars 1.42k forks source link

Pbjs does not use "import * as ..." for importing js files #1839

Open AVKurbatov opened 1 year ago

AVKurbatov commented 1 year ago

Versions: protobufjs: 7.1.2, protobufjs-cli: 1.0.2, pbjs: 0.0.14, ptjs: 0.2.4.

Hello!

We have a problem using protobuf-js-cli (pbjs, pbts) and protobuf-js. In our project we use more than 100 proto files and some of them use more than 20 imports for other proto files. Protobuf-js-cli generates all the code for importing protofiles into one. As a result, one of the js files we generated has a size of 60 MB and 300,000 lines of code. The pbts plugin can't handle this. It just crashes without any error messages and no d.ts file is created. For other cases, it would be generally convenient for us to use imports in the generated js files instead of large js files with all the imported code in them.

Could you give some advice? Can we use protobuf-js-cli to generate files without imported code in them?

AVKurbatov commented 1 year ago

Let me explain it with the example. I have two files: sub_module.proto:

syntax = "proto3"; package Codegen;

message HelloRequest { string name = 1; } message HelloReply { string message = 1; }

and module.proto: syntax = "proto3"; package Codegen;

import "sub_module.proto"; message SomeComposition { HelloRequest title = 1; HelloReply assets = 2; } service Greeter { rpc SayHello (HelloRequest) returns (HelloReply) {} }

If I generate js file for this two proto files, I get file module.js with definitions for HelloRequest and HelloReply. I use command line "pbjs -t static-module -p protoFolder -w commonjs -o module.js module.proto" But I want to import sub_module into module. I see it in this way. 1) We need to add imports to the head of the generated file: image 2) We need to add the namespace to names for all classes described in the sub_module: image 3) And finally we need to remove definitions of all classes that are defined in the sub_module: image

I'm going to update pbjs and pbts code according to this ideas. What do you think about this plan? Are there any critical flaws in it? Do we have any easier ways to solve this problem?

Yongle-Fu commented 10 months ago

same issue, hope support import submodule.proto