ts-proto icon indicating copy to clipboard operation
ts-proto copied to clipboard

feat!: Replace protobuf.js

Open timostamm opened this issue 1 year ago • 4 comments

This PR replaces protobuf.js with @bufbuild/protobuf in generated code. The libraries are used for low-level wire encoding. Since they have a similar API, the changes to main.ts are relatively simple.

The main advantage is that Long.js is no longer a dependency, unless you explicitly want to use Long.js (plugin option forceLong=long).

The signatures of encode and decode change - they no longer use Reader and Writer from protobuf.js, but the counterparts from @bufbuild/protobuf. This will be a breaking change for users that manually pass in readers, or rely on the returned writer to be a specific type.

Follow-ups:

  • ~Replace Reader in src/schema.ts~ https://github.com/stephenh/ts-proto/pull/1058/commits/0d763e98ad96abded801a45d1b53370564f9950d
  • ~Re-generate code for ts-proto-descriptors~ https://github.com/stephenh/ts-proto/pull/1058/commits/3ae88891b08d21597f085bdaabbf1404e9e44c9e
  • ~Move protobufjs from dependencies to devDependencies~ https://github.com/stephenh/ts-proto/pull/1058/commits/7ef0c73543706c069a9e189ac02511316495afda

timostamm avatar Jun 10 '24 14:06 timostamm

@stephenh, I took care of the follow-ups.

This is using an alpha of @bufbuild/protobuf v2. I promise we won't break it if you want to publish as is. A stable v2 is about a month out in case you prefer to wait.

ts-proto-descriptors should be published first - the ts-proto package.json has a dep on it.

timostamm avatar Jun 14 '24 14:06 timostamm

Amazing, thank you @timostamm !

stephenh avatar Jun 14 '24 16:06 stephenh

A beta of @bufbuild/protobuf is available, and it won't be long until it's stable. I'll update this PR once the stable v2 is published.

timostamm avatar Jun 26 '24 15:06 timostamm

Awesome! Thanks for the update @timostamm !

stephenh avatar Jun 27 '24 04:06 stephenh

@timostamm @stephenh It looks like @bufbuild/protobuf v2 stable has been released. Any chance we can now get this PR merged/released?

corwinsheahan-wf avatar Aug 07 '24 22:08 corwinsheahan-wf

This is amazing, as usual, @timostamm , thank you for the bump to the latest!

I merged this to main, with a semantic-release change to hopefully push it out as an alpha release, and we can see if that works! :crossed_fingers:

stephenh avatar Aug 15 '24 20:08 stephenh

Just wanted to say thanks again @timostamm ! Really appreciate the help on this PR, and looking forward to @bufbuild/protobuf being a much better runtime for us! :pray:

stephenh avatar Aug 17 '24 22:08 stephenh

Sorry, I was out for a couple of days. This was fun 😃 Congratulations on the v2 release!

timostamm avatar Aug 18 '24 14:08 timostamm