Skip to content

Commit

Permalink
feat: optionally output versions used to generate files (#1040)
Browse files Browse the repository at this point in the history
### Description

- Add the `annotateFilesWithVersion` option so that changes are
correctly captured in CI (eliminating noise on each file)
- Added this option to the README
  • Loading branch information
lukealvoeiro committed May 13, 2024
1 parent d444507 commit 53d6799
Show file tree
Hide file tree
Showing 258 changed files with 23 additions and 767 deletions.
6 changes: 3 additions & 3 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,8 @@ Generated code will be placed in the Gradle build directory.

- With `--ts_proto_opt=useMongoObjectId=true`, fields of a type called ObjectId where the message is constructed to have on field called value that is a string will be mapped to type `mongodb.ObjectId` in the generated types. This will require your project to install the mongodb npm package. See [ObjectId](#objectid) for more details.

- With `--ts_proto_opt=annotateFilesWithVersion=false`, the generated files will not contain the versions of `protoc` and `ts-proto` used to generate the file. This option is normally set to `true`, such that files list the versions used.

- With `--ts_proto_opt=outputSchema=true`, meta typings will be generated that can later be used in other code generators.

- With `--ts_proto_opt=outputTypeAnnotations=true`, each message will be given a `$type` field containing its fully-qualified name. You can use `--ts_proto_opt=outputTypeAnnotations=static-only` to omit it from the `interface` declaration, or `--ts_proto_opt=outputTypeAnnotations=optional` to make it an optional property on the `interface` definition. The latter option may be useful if you want to use the `$type` field for runtime type checking on responses from a server.
Expand Down Expand Up @@ -787,9 +789,7 @@ The following helper types may make it easier to work with the types generated f
type OneOfCases<T> = T extends { $case: infer U extends string } ? U : never;

/** Extracts a union of all the value types from a oneOf field */
type OneOfValues<T> = T extends { $case: infer U extends string; [key: string]: unknown }
? T[U]
: never;
type OneOfValues<T> = T extends { $case: infer U extends string; [key: string]: unknown } ? T[U] : never;

/** Extracts the specific type of a oneOf case based on its field name */
type OneOfCase<T, K extends OneOfCases<T>> = T extends {
Expand Down
3 changes: 0 additions & 3 deletions integration/angular/simple-message.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: simple-message.proto

/* eslint-disable */
Expand Down
3 changes: 0 additions & 3 deletions integration/async-iterable-services-abort-signal/simple.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: simple.proto

/* eslint-disable */
Expand Down
3 changes: 0 additions & 3 deletions integration/async-iterable-services/simple.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: simple.proto

/* eslint-disable */
Expand Down
3 changes: 0 additions & 3 deletions integration/avoid-import-conflicts-folder-name/ui.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: ui.proto

/* eslint-disable */
Expand Down
3 changes: 0 additions & 3 deletions integration/avoid-import-conflicts-folder-name/ui/simple.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: ui/simple.proto

/* eslint-disable */
Expand Down
3 changes: 0 additions & 3 deletions integration/avoid-import-conflicts-types-only/simple.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: simple.proto

/* eslint-disable */
Expand Down
3 changes: 0 additions & 3 deletions integration/avoid-import-conflicts-types-only/simple2.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: simple2.proto

/* eslint-disable */
Expand Down
3 changes: 0 additions & 3 deletions integration/avoid-import-conflicts/simple.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: simple.proto

/* eslint-disable */
Expand Down
3 changes: 0 additions & 3 deletions integration/avoid-import-conflicts/simple2.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: simple2.proto

/* eslint-disable */
Expand Down
3 changes: 0 additions & 3 deletions integration/barrel-imports/bar.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: bar.proto

/* eslint-disable */
Expand Down
3 changes: 0 additions & 3 deletions integration/barrel-imports/foo.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: foo.proto

/* eslint-disable */
Expand Down
3 changes: 0 additions & 3 deletions integration/batching-with-context-esModuleInterop/batching.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: batching.proto

/* eslint-disable */
Expand Down
3 changes: 0 additions & 3 deletions integration/batching-with-context/batching.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: batching.proto

/* eslint-disable */
Expand Down
3 changes: 0 additions & 3 deletions integration/batching/batching.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: batching.proto

/* eslint-disable */
Expand Down
3 changes: 0 additions & 3 deletions integration/before-after-request-streaming/example.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: example.proto

/* eslint-disable */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: google/protobuf/wrappers.proto

/* eslint-disable */
Expand Down
3 changes: 0 additions & 3 deletions integration/before-after-request/simple.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: simple.proto

/* eslint-disable */
Expand Down
3 changes: 0 additions & 3 deletions integration/before-after-request/simple2.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: simple2.proto

/* eslint-disable */
Expand Down
3 changes: 0 additions & 3 deletions integration/bytes-as-base64-browser/message.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: message.proto

/* eslint-disable */
Expand Down
3 changes: 0 additions & 3 deletions integration/bytes-as-base64-node/message.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: message.proto

/* eslint-disable */
Expand Down
3 changes: 0 additions & 3 deletions integration/bytes-as-base64/message.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: message.proto

/* eslint-disable */
Expand Down
3 changes: 0 additions & 3 deletions integration/bytes-node/google/protobuf/wrappers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: google/protobuf/wrappers.proto

/* eslint-disable */
Expand Down
3 changes: 0 additions & 3 deletions integration/bytes-node/point.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: point.proto

/* eslint-disable */
Expand Down
10 changes: 10 additions & 0 deletions integration/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ async function generate(binFile: string, baseDir: string, parameter: string) {
const { protocVersion, tsProtoVersion } = await getVersions(request);

const options = optionsFromParameter(parameter || "");

// we have to check for the parameter as a string here because the
// default value of the parameter is true.
if (parameter.includes("annotateFilesWithVersion=true")) {
options.annotateFilesWithVersion = true;
} else {
// we practically always want to not annotate files with version in tests
// as this will make snapshots fail on every version bump
options.annotateFilesWithVersion = false;
}
const typeMap = createTypeMap(request, options);

for (let file of request.protoFile) {
Expand Down
3 changes: 0 additions & 3 deletions integration/const-enum/const-enum.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: const-enum.proto

/* eslint-disable */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: default-with-custom-metadata.proto

/* eslint-disable */
Expand Down
3 changes: 0 additions & 3 deletions integration/default-with-metadata/default-with-metadata.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: default-with-metadata.proto

/* eslint-disable */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: google/protobuf/timestamp.proto

/* eslint-disable */
Expand Down
3 changes: 0 additions & 3 deletions integration/emit-default-values-json/test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: test.proto

/* eslint-disable */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: enums-as-literals-with-string-enums.proto

/* eslint-disable */
Expand Down
3 changes: 0 additions & 3 deletions integration/enums-as-literals/enums-as-literals.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: enums-as-literals.proto

/* eslint-disable */
Expand Down
3 changes: 0 additions & 3 deletions integration/enums-with-unrecognized-name-value/test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: test.proto

/* eslint-disable */
Expand Down
3 changes: 0 additions & 3 deletions integration/extensions/test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: test.proto

/* eslint-disable */
Expand Down
3 changes: 0 additions & 3 deletions integration/fieldmask-optional-all/fieldmask-optional.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: fieldmask-optional.proto

/* eslint-disable */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: google/protobuf/field_mask.proto

/* eslint-disable */
Expand Down
3 changes: 0 additions & 3 deletions integration/fieldmask/fieldmask.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: fieldmask.proto

/* eslint-disable */
Expand Down
3 changes: 0 additions & 3 deletions integration/fieldmask/google/protobuf/field_mask.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: google/protobuf/field_mask.proto

/* eslint-disable */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: fieldoption-jstype-with-forcelong-bigint.proto

/* eslint-disable */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: fieldoption-jstype-with-forcelong-long.proto

/* eslint-disable */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: fieldoption-jstype-with-forcelong-number.proto

/* eslint-disable */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: fieldoption-jstype-with-forcelong-string.proto

/* eslint-disable */
Expand Down
3 changes: 0 additions & 3 deletions integration/fieldoption-jstype/fieldoption-jstype.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: fieldoption-jstype.proto

/* eslint-disable */
Expand Down
3 changes: 0 additions & 3 deletions integration/file-suffix/child.pb.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: child.proto

/* eslint-disable */
Expand Down
3 changes: 0 additions & 3 deletions integration/file-suffix/google/protobuf/timestamp.pb.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: google/protobuf/timestamp.proto

/* eslint-disable */
Expand Down
3 changes: 0 additions & 3 deletions integration/file-suffix/parent.pb.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: parent.proto

/* eslint-disable */
Expand Down
3 changes: 0 additions & 3 deletions integration/from-partial-no-initialize/test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: test.proto

/* eslint-disable */
Expand Down
Loading

0 comments on commit 53d6799

Please sign in to comment.