Skip to content
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

Support importSuffix with outputTypeRegistry #857

Open
adsau59 opened this issue Jun 27, 2023 · 7 comments
Open

Support importSuffix with outputTypeRegistry #857

adsau59 opened this issue Jun 27, 2023 · 7 comments
Assignees

Comments

@adsau59
Copy link

adsau59 commented Jun 27, 2023

I am using this command to generate

protoc --plugin=protoc-gen-ts_proto=".\\node_modules\\.bin\\protoc-gen-ts_proto.cmd" --ts_proto_opt=outputTypeRegistry=true --ts_proto_opt=importSuffix=.js --ts_proto_opt=esModuleInterop=true --proto_path=$pwd\proto\src --ts_proto_out=$pwd\proto\build $pwd\proto\src\messages.proto

in this, outputTypeRegistry=true creates a typeRegistery.ts file which other generated proto ts files tries to import, but as importSuffix=.js is also set, it tries to import typeRegistery.js instead which gives me

Error: Cannot find module './typeRegistry.js'


I want to use the outputTypeRegistry, as it does kindof eases my work as i dont have to maintain the list myself... but I also need importSuffix=.js as cocos doesn't work without it

@adsau59
Copy link
Author

adsau59 commented Jun 28, 2023

if it would import typeRegistry and other script which are generated without .js and protobufjs/minimal with .js it would be perfect, how can i do that?

@adsau59
Copy link
Author

adsau59 commented Jun 28, 2023

okay so for now, i removed importSuffix=.js and ran find proto/build -type f -exec sed -i 's/protobufjs\/minimal/protobufjs\/minimal.js/g' {} +

which seems to be working fine for now

@stephenh
Copy link
Owner

Hi @adsau59 , this is not entirely surprising, as the outputTypeRegistry and importSuffix features were written at different times / by different contributors. If you include more context what specific generated lines were incorrect, this would probably be easy to fix.

We have a test case for import-suffix here, if you wanted to add outputTypeRegistry to it and then reproduce the error in a PR, that'd be great:

https://github.com/stephenh/ts-proto/blob/main/integration/import-suffix/parameters.txt

Thanks!

@stephenh stephenh changed the title 2 different option conflicting Support importSuffix with outputTypeRegistry Jun 28, 2023
@adsau59
Copy link
Author

adsau59 commented Jun 28, 2023

Hi @adsau59 , this is not entirely surprising, as the outputTypeRegistry and importSuffix features were written at different times / by different contributors. If you include more context what specific generated lines were incorrect, this would probably be easy to fix.

We have a test case for import-suffix here, if you wanted to add outputTypeRegistry to it and then reproduce the error in a PR, that'd be great:

https://github.com/stephenh/ts-proto/blob/main/integration/import-suffix/parameters.txt

Thanks!

so the issue is that, generated files are .ts files, but they are imported using .js extention due to importSuffix=.js

I am not sure what exactly what you want me to do, but I'd be happy to create a PR

@stephenh
Copy link
Owner

stephenh commented Jul 1, 2023

I am not sure what exactly what you want me to do

Ah yeah; the readme describes in ts-proto here but the basic gist is that parameters.txt is what turns on/off the various opts/flags, and we have a bunch of directories/parameters.txts to test the various combinations of flags.

So we already have an test, in the import-suffix directory, for testing the importSuffix flag, but it doesn't have the outputTypeRegistry flag enabled.

My suggestion was to try enabling the outputTypeRegistry flag for that test, see the readme for how to re-run the codegen with the new flag applied, and then in theory we should see/reproduce a compile error that matches what we're seeing.

If you don't, hopefully you could nudge the import-suffix's parameters.txt / *.proto files around to reproduce the error you're seeing.

@adsau59
Copy link
Author

adsau59 commented Jul 4, 2023

Thanks for the explanation, will try it out and get back to u...

@adsau59
Copy link
Author

adsau59 commented Jul 15, 2023

@stephenh can u assign me the issue pls?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants