Skip to content

[Feature Request] Export generated validate proto artifacts #151

Closed

Description

@newyankeecodeshop

Feature description:

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.

Contribution:

I have a PR that implements this and updates the example package.

Examples or references:

None

Additional context:

None

Activity

  1. timostamm commented on Aug 24, 2026

    @timostamm
    Member

    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.

  2. timostamm commented on Sep 3, 2026

    @timostamm
    Member
  3. timostamm commented on Sep 16, 2026

    @timostamm
    Member

    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:

    plugins:
      - local: protoc-gen-es
        opt:
          - target=ts
    +     - map_imports=buf/validate/:@bufbuild/protovalidate/gen
        out: src/gen
    -   include_imports: true

    As a result, only a single copy of validate_pb.js is used in the project.

  4. newyankeecodeshop commented on Sep 18, 2026

    @newyankeecodeshop
    ContributorAuthor

    Thanks for getting this over the line @timostamm !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions