You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Feature Request] Export generated validate proto artifacts #151
Make @bufbuild/protovalidate/gen/buf/validate/validate_pb.js an exported artifact so that it can be used by the generated code of user protobuf files.
Problem it solves or use case:
In a typical installation of protovalidate-es, there are two copies of validate_pb.js. One is inside @bufbuild/protovalidate and one is generated when users compile their proto files. The packages/example shows this as it includes its own copy in src/gen/buf/validate/validate_pb.ts. The generated JS files contains over 60KB of data describing the proto artifacts.
Proposed implementation or solution:
Allow users to replace the generated validate_pb.js with a single line:
export * from "@bufbuild/protovalidate/gen/buf/validate/validate_pb.js";
This could eventually be automated by a protoc plugin.
It's true that there are typically two copies of validate_pb.js when you use protovalidate. It's usually compressed away very well when you serve a web app, but clearly it's not ideal.
Edition 2024 adds the import option feature (see here for an example). This feature solves the issue because the code you're generating doesn't need to generate the import anymore. Unfortunately import option isn't available in syntax proto3, so it isn't very helpful in practice.
What's needed here is a "canonical" import location, so that instead of generating validate_pb.js, the file is simply imported from @bufbuild/protovalidate. We actually have a plugin option to enable that (see here). We never got around to testing all use cases and documenting it properly, but it looks like the cleanest solution to me. You'd drop include_imports: true from buf.gen.yaml, and instead add a rewrite_imports= line.
Exporting the generated code from @bufbuild/protovalidate is still necessary though, and that's a good starting point. It needs to be "canonical" though: A .js extension is the most flexible and portable, so it's important that the exports use only this file extension.
v1.3.0 of @bufbuild/protovalidate exports gen/buf/validate/validate_pb.js now.
v2.15.0 of @bufbuild/protoc-gen-es adds the new plugin option map_imports, which can be used to import validate_pb.js from the package instead of generating it locally.
In buf.gen.yaml, remove include_imports: true, and add the map_imports plugin option:
Activity
timostamm commentedon Aug 24, 2026
It's true that there are typically two copies of
validate_pb.jswhen you use protovalidate. It's usually compressed away very well when you serve a web app, but clearly it's not ideal.Edition 2024 adds the
import optionfeature (see here for an example). This feature solves the issue because the code you're generating doesn't need to generate the import anymore. Unfortunatelyimport optionisn't available in syntaxproto3, so it isn't very helpful in practice.What's needed here is a "canonical" import location, so that instead of generating
validate_pb.js, the file is simply imported from@bufbuild/protovalidate. We actually have a plugin option to enable that (see here). We never got around to testing all use cases and documenting it properly, but it looks like the cleanest solution to me. You'd dropinclude_imports: truefrombuf.gen.yaml, and instead add arewrite_imports=line.Exporting the generated code from
@bufbuild/protovalidateis still necessary though, and that's a good starting point. It needs to be "canonical" though: A.jsextension is the most flexible and portable, so it's important that the exports use only this file extension.timostamm commentedon Sep 3, 2026
rewrite_importsoption in an internal package.timostamm commentedon Sep 16, 2026
v1.3.0 of
@bufbuild/protovalidateexportsgen/buf/validate/validate_pb.jsnow.v2.15.0 of
@bufbuild/protoc-gen-esadds the new plugin optionmap_imports, which can be used to import validate_pb.js from the package instead of generating it locally.In buf.gen.yaml, remove
include_imports: true, and add themap_importsplugin option:plugins: - local: protoc-gen-es opt: - target=ts + - map_imports=buf/validate/:@bufbuild/protovalidate/gen out: src/gen - include_imports: trueAs a result, only a single copy of
validate_pb.jsis used in the project.newyankeecodeshop commentedon Sep 18, 2026
Thanks for getting this over the line @timostamm !