Conversation
| // Our goal is to provide options with source retention to plugin authors. | ||
| // CodeGeneratorRequest.proto_file elides options with source retention for | ||
| // files to generate. For these files, we take the file from source_file_descriptors, | ||
| // which does include options with source retention. | ||
| const allProtoWithSourceOptions = request.protoFile.map((protoFile) => { | ||
| const sourceFile = request.sourceFileDescriptors.find( | ||
| (s) => s.name == protoFile.name, | ||
| ); | ||
| return sourceFile ?? protoFile; | ||
| }); |
There was a problem hiding this comment.
This is backwards compatible. Old compilers will not populate source_file_descriptors, and we keep using proto_file.
| function getFileDescCall(f: GeneratedFile, file: DescFile, schema: Schema) { | ||
| const sourceFile = file.proto; | ||
| const runtimeFile = schema.proto.protoFile.find(f => f.name == sourceFile.name); | ||
| const info = embedFileDesc(runtimeFile ?? sourceFile); |
There was a problem hiding this comment.
This removes source retention options from embedded file descriptors generated by protoc-gen-es. We simply do the reverse of packages/protoplugin/src/ecmascript/schema.ts:223.
There was a problem hiding this comment.
Might be worth a comment in here about why we want the version in schema.proto.protoFile instead of the provided file.proto, because it would already have omitted source-only options.
| function getFileDescCall(f: GeneratedFile, file: DescFile, schema: Schema) { | ||
| const sourceFile = file.proto; | ||
| const runtimeFile = schema.proto.protoFile.find(f => f.name == sourceFile.name); | ||
| const info = embedFileDesc(runtimeFile ?? sourceFile); |
There was a problem hiding this comment.
Might be worth a comment in here about why we want the version in schema.proto.protoFile instead of the provided file.proto, because it would already have omitted source-only options.
This PR adds support for option retention: Options can specify whether they should be included in generated code (making them accessible at runtime), or be only available for plugins, while generating code.
With this change, options that specify
retention = RETENTION_SOURCEare available in plugins written on top of @bufbuild/protoplugin. But they will not be included in the code generated by protoc-gen-es.