Replies: 3 comments 4 replies
-
It looks like I could probably patch this bit of https://github.com/stephenh/ts-proto/blob/main/src/main.ts#L81-L86 And add something like this on line 82 to define an insertion point for imports: chunks.push(code`// @@protoc_insertion_point(imports)`); And then add something like this on line 244 to define an insertion point at the end of the file for my own generate services to be inserted: https://github.com/stephenh/ts-proto/blob/main/src/main.ts#L243-L245 chunks.push(code`// @@protoc_insertion_point(end_of_file)`); If this would work, one benefit of this would be that all of the existing service-generation options could be pulled out into standalone protoc plugins, which I think would reduce |
Beta Was this translation helpful? Give feedback.
-
Hm, interesting, no I hadn't seen the insertion point option/approach before. FWIW @aikoven recently added the I'd be tempted to look at that first, and hopefully build your custom services on top of that. If that really doesn't work, I guess I'm not 100% opposed to the insertion point approach, like a For my own personal tendencies, it seems a little brittle; although I can see how it makes sense for the |
Beta Was this translation helpful? Give feedback.
-
Yeah. Just talking out loud, an earlier version of the ts-poet code generation library used to be more object-based (the current API is basically "give me a bunch of strings, I'll concat them and then auto-organize / de-conflict the imports"). The object-based API was more like "here's a function function myPlugin(output: TsProtoOutput) {
const file = output.getFile("./simple.ts");
const foo = file.getClass("FooRpcService");
const getFoo = foo.getMethod("getFoo");
foo.setMethod("getFoo", code`
...my customization...
${getFoo}
...my customization...
`);
return output;
} And so you could like muck with the files / methods / functions after ts-proto had already made them, but before they go to disk. Granted, it would take some infrastructure to build, but I think fundamentally wouldn't be too hard/complex. That said, I do like the simplicity of ideally using the generic-definitions output. |
Beta Was this translation helpful? Give feedback.
-
Does
ts-proto
support insertion points?ts-proto/protos/google/protobuf/compiler/plugin.proto
Lines 135 to 172 in 7edc991
If not, do you plan on adding support, or do you have pointers to get started adding this feature on my own?
The use-case I have is that I am building my own service generation. I see that there's already quite a bit of service generation code directly in
ts-proto
, and each is unique and specific in its own way. I don't want to add Yet Another Service Generation option, and it seems like a perfect opportunity for insertion points so that I can write my own plugin which simply amendsts-proto
output with my own extensions.To achieve that I think I would just need one insertion point up top for imports, and one insertion point at the bottom for my own generated service additions.
Beta Was this translation helpful? Give feedback.
All reactions