Skip to main content
Deno 2 is finally here 🎉️
Learn more

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:

  1. A CLI tool (a deno script) for transforming js source files.
  2. A pre-compiled (deno-compatible) google-protobuf runtime.

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.proto

Then run the build script on the output:

$ deno run --allow-read --allow-write https://deno.land/x/deno_google_protobuf/tools/build.ts srcDir dstDir

The 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 (or omit the dstDir) to overwrite the files in-place.

Version select

By default, the master version of the pre-compiled runtime is used, but a third parameter can be passed to select a specific version (in which case, the dstDir must be explicitly provided). The version must match the version x.y.z and exist as a release in this repo:

$ deno run --allow-read --allow-write https://deno.land/x/deno_google_protobuf/tools/build.ts srcDir dstDir 3.12.2

If the version argument does not match a version string, it will be interpreted as a path to the runtime.

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).