deno-google-protobuf
This repo provides utilities for transforming protoc-compiled javascript files into source files compatible with the deno runtime. It consists of two main components:
- A CLI tool (a deno script) for transforming js source files.
- A pre-compiled (deno-compatible)
google-protobufruntime.
CLI tool
The js files that act as input to the transformation (build) script is generated by protoc. The files must be exported targeting CommonJS imports:
$ protoc --js_out=import_style=commonjs,binary:srcDir messages.proto base.protoThen run the build script on the output:
$ deno run --allow-read --allow-write https://deno.land/x/deno_google_protobuf/tools/build.ts srcDir dstDirThe script will read all files matching **_pb.js in srcDir (and subdirectories) and transform the import- and export statements to deno-compatible syntax. It also switches out the google-protobuf runtime to the patched version provided by this package. The patched source is then written to dstDir. You can specify the same directory as both srcDir and dstDir to overwrite the files in-place.
google-runtime
By itself the pre-compiled google-protobuf runtime is not very useful. It does however power the transformed source files built by the the CLI tool.
plugin sources
The repo also provides pre-compiled google-protobuf plugin types. These patched plugin sources, together with the runtime, could potentially be used in specialized protoc-plugins.
Auto-deploy and versioning
To keep the runtime up-to-date, the repo contains an npm script to pull google-protobuf from upstream, transforming it into deno-compatible files, and push a mirrored release using a git tag matching the google-protobuf version. This means that a pinned runtime can be made available (for example https://deno.land/x/deno_google_protobuf@3.12.0/google-protobuf.js).