Skip to content

Use rewrite_imports to deduplicate a copy of validate_pb.ts - #184

Merged
timostamm merged 1 commit into
mainfrom
tstamm/Use-rewrite_imports-to-deduplicate-a-copy-of-validate_pb.ts
Sep 4, 2026
Merged

Use rewrite_imports to deduplicate a copy of validate_pb.ts#184
timostamm merged 1 commit into
mainfrom
tstamm/Use-rewrite_imports-to-deduplicate-a-copy-of-validate_pb.ts

Conversation

@timostamm

Copy link
Copy Markdown
Member

The package @bufbuild/protovalidate uses code generated for buf/build/validate.proto internally.
The private package packages/protovalidate-bench generates a second copy.
With #151, @bufbuild/protovalidate exports its generated code.

This PR uses the option rewrite_imports of @bufbuild/protoc-gen-es to rewrite the import for buf/build/validate.proto, to point to @bufbuild/protovalidate/gen/buf/build/validate_pb.js, so that only a single copy exists.

This is not a user-facing change, it's just a private package. The interesting bit is that this approach applies to users too. Consider the example in this repository: Its buf.gen.yaml config sets include_imports: true so that generated imports for buf/build/validate.proto resolve. As a result, two copies of validate_pb.ts end up in the user's bundle.

rewrite_imports replaces include_imports. There will only be a single version of the generated code (@bufbuild/protovalidate/gen/buf/build/validate_pb.js) in the user's bundle.

Comment thread packages/protovalidate-bench/buf.gen.yaml
@timostamm
timostamm merged commit f5954e9 into main Sep 4, 2026
15 checks passed
@timostamm
timostamm deleted the tstamm/Use-rewrite_imports-to-deduplicate-a-copy-of-validate_pb.ts branch September 4, 2026 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ignore-for-release Do not include in release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants