Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation for Buf CLI option include_imports #1033

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ The quickstart below shows a simple example of code generation for a `.proto` fi
npx tsc --init
```

2. Install the runtime library, code generator, and the [Buf CLI](https://buf.build/docs/ecosystem/cli-overview):
2. Install the runtime library, code generator, and the [Buf CLI][buf-cli]:

```shellsession
npm install @bufbuild/protobuf
Expand Down Expand Up @@ -2496,6 +2496,28 @@ If you see the following error with [Metro] or [Expo], make sure to [enable pack
Metro error: Unable to resolve module @bufbuild/protobuf/codegenv1
```

### The plugin generates missing imports

The [Buf CLI][buf-cli] does not generate dependencies by default. For example, if you have a Protobuf message that uses
validation rules from [buf.build/bufbuild/protovalidate](https://buf.build/bufbuild/protovalidate), your Protobuf file
has an import for the validation options:

```protobuf
import "buf/validate/validate.proto";
```

Generated code will include an import for `./buf/validate/validate_pb`. To generate this file, add the following option
to your buf.gen.yaml config:

```diff
# buf.gen.yaml
version: v2
plugins:
- local: protoc-gen-es
out: src/gen
+ include_imports: true
```

### Is serialization deterministic?

Serialization to JSON and binary is deterministic within a version of protobuf-es, but map entries, repeated fields and extensions are ordered by insertion. Regular fields are sorted by field number.
Expand All @@ -2510,7 +2532,7 @@ Serialization to JSON and binary is deterministic within a version of protobuf-e
[blog-post]: https://buf.build/blog/protobuf-conformance
[bsr-reflection]: https://buf.build/docs/bsr/reflection/overview
[Buf style guide]: https://buf.build/best-practices/style-guide#enums
[buf-cli]: https://buf.build/docs/ecosystem/cli-overview
[buf-cli]: https://buf.build/docs/cli/
[buf-images]: https://buf.build/docs/reference/images
[buf.build/conformance-blog]: https://buf.build/blog/protobuf-conformance
[buf.build/descriptors]: https://buf.build/docs/reference/descriptors#deep-dive-into-the-model
Expand Down
4 changes: 3 additions & 1 deletion packages/protobuf-example/buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ inputs:
# Deletes the directories specified in the `out` field for all plugins before running code generation.
clean: true
plugins:
# The code generator is installed with `npm install @bufbuild/protoc-gen-es`.
# The local plugin is installed with `npm install @bufbuild/protoc-gen-es`.
- local: protoc-gen-es
opt: target=ts
out: src/gen
# Also generate any imported dependencies
include_imports: true
# Uncomment to set `jstype = JS_STRING` on all applicable fields automatically:
# managed:
# enabled: true
Expand Down
Loading