When writing code using the reflection API, getting good test coverage can be challenging. It's easy enough to generate code (which includes descriptors) or build descriptors with buf build, but co-locating Protobuf source with a test gives better confidence.
With the compileMessage function, you can compile inline Protobuf source to a message descriptor:
The package also exports functions to compile Protobuf descriptors for all other types, such as enumerations and services.
Under the hood, the functions shell out to the buf build command. You need @bufbuild/buf as a peer dependency to use them.
Note that the functions return anonymous descriptors. They are functionally identical to generated descriptors, but do not have generated type information attached.
Add @bufbuild/protocompile to the MANUAL.md.
When writing code using the reflection API, getting good test coverage can be challenging. It's easy enough to generate code (which includes descriptors) or build descriptors with
buf build
, but co-locating Protobuf source with a test gives better confidence.With the
compileMessage
function, you can compile inline Protobuf source to a message descriptor:The package also exports functions to compile Protobuf descriptors for all other types, such as enumerations and services.
Under the hood, the functions shell out to the
buf build
command. You need @bufbuild/buf as a peer dependency to use them.Note that the functions return anonymous descriptors. They are functionally identical to generated descriptors, but do not have generated type information attached.