diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2d8509eff..33a3fe48c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,10 +28,9 @@ jobs: run: ./integration/pbjs.sh # This will fail if any git-tracked file has changed - name: Codegen - run: | - cd integration - ./codegen.sh - git status && git diff --exit-code + run: yarn bin2ts + - name: Diff Output + run: git status && git diff --exit-code - name: test run: yarn test env: diff --git a/README.markdown b/README.markdown index 64db0208d..72f613cc0 100644 --- a/README.markdown +++ b/README.markdown @@ -18,7 +18,7 @@ - [Supported options](#supported-options) - [Only Types](#only-types) - [NestJS Support](NESTJS.markdown) -- [Building](#building) +- [Development](#development) - [Assumptions](#assumptions) - [Todo](#todo) - [OneOf Handling](#oneof-handling) @@ -362,15 +362,69 @@ Kudos to our sponsors: If you need ts-proto customizations or priority support for your company, you can ping me at [via email](mailto:stephen.haberman@gmail.com). -# Building +# Development -After running `yarn install`, run `./integration/pbjs.sh` to create the integration test types. These pbjs-generated files are not currently checked in. +**Requirements** -After this, the tests should pass. +- [Docker](https://www.docker.com) or [protoc](https://github.com/protocolbuffers/protobuf/releases) v3.19.1 +- `yarn` — `npm install -g yarn` -After making changes to `ts-proto`, you can run `cd integration` and `./codegen.sh` to re-generate the test case `*.ts` output files that are in each `integration//` directory. +**Setup** -The test suite's proto files (i.e. `simple.proto`, `batching.proto`, etc.) currently have serialized/`.bin` copies checked into git (i.e. `simple.bin`, `batching.bin`, etc.), so that the test suite can run without having to invoke the `protoc` build chain. I.e. if you change the `simple.proto`/etc. files, you'll need to run `./integration/update-bins.sh`, which does require having the `protoc` executable available. +The commands below assume you have **Docker** installed. To use a **local** copy of `protoc` without docker, use commands suffixed with `:local` + +- Check out the [repository]() for the latest code. +- Run `yarn install` to install the dependencies. +- Run `yarn build:test` or `yarn build:test:local` to generate the test files. + > _This runs the following commands:_ + > - `proto2bin` — Converts integration test `.proto` files to `.bin`. + > - `bin2ts` — Runs `ts-proto` on the `.bin` files to generate `.ts` files. + > - `proto2pbjs` — Generates a reference implementation using `pbjs` for testing compatibility. +- Run `yarn test` + +**Workflow** + +- Modifying the plugin implementation: + - Run `yarn bin2ts` or `yarn bin2ts:local`. + _Since the proto files were not changed, you only need to regenerate the typescript files._ + - Run `yarn test` to verify the typescript files are compatible with the reference implementation, and pass other tests. +- Updating or adding `.proto` files in the integration directory: + - Run `yarn build:test` to regenerate the integration test files. + - Run `yarn test` to retest. + +**Contributing** + +- Run `yarn build:test` and `yarn test` to make sure everything works. +- Run `yarn prettier` to format the typescript files. +- Commit the changes: + - Also include the generated `.bin` files for the tests where you added or modified `.proto` files. + > These are checked into git so that the test suite can run without having to invoke the `protoc` build chain. + - Also include the generated `.ts` files. +- Create a pull request + +**Dockerized Protoc** + +The repository includes a dockerized version of `protoc`, which is configured in [docker-compose.yml](docker-compose.yml). + +It can be useful in case you want to manually invoke the plugin with a known version of `protoc`. + +Usage: + +```bash +# Include the protoc alias in your shell. +. aliases.sh + +# Run protoc as usual. The ts-proto directory is available in /ts-proto. +protoc --plugin=/ts-proto/protoc-gen-ts_proto --ts_proto_out=./output -I=./protos ./protoc/*.proto + +# Or use the ts-protoc alias which specifies the plugin path for you. +ts-protoc --ts_proto_out=./output -I=./protos ./protoc/*.proto +``` + +- All paths must be relative paths _within_ the current working directory of the host. `../` is not allowed +- Within the docker container, the absolute path to the project root is `/ts-proto` +- The container mounts the current working directory in `/host`, and sets it as its working directory. +- Once `aliases.sh` is sourced, you can use the `protoc` command in any folder. # Assumptions diff --git a/aliases.sh b/aliases.sh new file mode 100644 index 000000000..27eeed544 --- /dev/null +++ b/aliases.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +PROJECT_ROOT=$(realpath $(dirname "$BASH_SOURCE")) +PROJECT_ROOT_DOCKER="//ts-proto" # double slash to support git bash on windows + +# Alias docker-compose to make it usable from anywhere +function _docker-compose() { docker-compose -f $PROJECT_ROOT/docker-compose.yml "$@"; } + +function protoc() { _docker-compose run --rm protoc "$@"; } +function protoc-sh() { _docker-compose run --rm --entrypoint sh -- protoc "$@"; } +function protoc-build() { _docker-compose build protoc; } +function ts-protoc { protoc --plugin=$PROJECT_ROOT_DOCKER/protoc-gen-ts_proto "$@"; } diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..7a7b6acc7 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,14 @@ +version: "3" +services: + protoc: + build: + context: . + dockerfile: "protoc.Dockerfile" + args: + BASE: "node:17-alpine3.14" + BIN: "/ts-proto" + PROTOC_VERSION: "3.19.1" + working_dir: "/host" + volumes: + - "${PWD:-.}:/host" + - ".:/ts-proto" diff --git a/integration/angular/simple-message.bin b/integration/angular/simple-message.bin index 8b9b8cfd0..7a2445434 100644 Binary files a/integration/angular/simple-message.bin and b/integration/angular/simple-message.bin differ diff --git a/integration/avoid-import-conflicts-types-only/simple.bin b/integration/avoid-import-conflicts-types-only/simple.bin index f0741c863..75915195a 100644 Binary files a/integration/avoid-import-conflicts-types-only/simple.bin and b/integration/avoid-import-conflicts-types-only/simple.bin differ diff --git a/integration/avoid-import-conflicts-types-only/simple2.bin b/integration/avoid-import-conflicts-types-only/simple2.bin index 745b205c1..4a0fddc47 100644 Binary files a/integration/avoid-import-conflicts-types-only/simple2.bin and b/integration/avoid-import-conflicts-types-only/simple2.bin differ diff --git a/integration/avoid-import-conflicts/simple.bin b/integration/avoid-import-conflicts/simple.bin index 8e46534d8..57bd5482b 100644 Binary files a/integration/avoid-import-conflicts/simple.bin and b/integration/avoid-import-conflicts/simple.bin differ diff --git a/integration/avoid-import-conflicts/simple2.bin b/integration/avoid-import-conflicts/simple2.bin index 3278c61bf..7b35fb39e 100644 Binary files a/integration/avoid-import-conflicts/simple2.bin and b/integration/avoid-import-conflicts/simple2.bin differ diff --git a/integration/barrel-imports/bar.bin b/integration/barrel-imports/bar.bin index 9a23de976..8b84bf739 100644 Binary files a/integration/barrel-imports/bar.bin and b/integration/barrel-imports/bar.bin differ diff --git a/integration/barrel-imports/foo.bin b/integration/barrel-imports/foo.bin index 99e659e27..26df53209 100644 Binary files a/integration/barrel-imports/foo.bin and b/integration/barrel-imports/foo.bin differ diff --git a/integration/batching-with-context/batching.bin b/integration/batching-with-context/batching.bin index 7355180b5..5d6ad57e0 100644 Binary files a/integration/batching-with-context/batching.bin and b/integration/batching-with-context/batching.bin differ diff --git a/integration/batching/batching.bin b/integration/batching/batching.bin index 7355180b5..5d6ad57e0 100644 Binary files a/integration/batching/batching.bin and b/integration/batching/batching.bin differ diff --git a/integration/bytes-as-base64/message.bin b/integration/bytes-as-base64/message.bin index 5044a3414..b035d9e09 100644 Binary files a/integration/bytes-as-base64/message.bin and b/integration/bytes-as-base64/message.bin differ diff --git a/integration/bytes-node/point.bin b/integration/bytes-node/point.bin index 9a03b3eac..83d92ed00 100644 Binary files a/integration/bytes-node/point.bin and b/integration/bytes-node/point.bin differ diff --git a/integration/codegen.sh b/integration/codegen.sh index 38da4e010..b204f1e9c 100755 --- a/integration/codegen.sh +++ b/integration/codegen.sh @@ -9,23 +9,26 @@ # # Updates generated output for all integration tests. # -# ./codegen.sh simple +# ./codegen.sh simple value # -# Updates generated output only for the 'simple' integration test. +# Updates generated output only for the 'simple' and 'value' integration test. # # Each integration test can optionally have a `parameters.txt` file that will # be used as the ts-proto_opt... args for generating that test's code. -dir=${1:-*} +INTEGRATION_DIR=$(realpath $(dirname "$BASH_SOURCE")) -N=6 +# Run the code generator in parallel, with one process per core. +N=$(nproc) + +echo "Generating typescript code for integration tests using ${N} cores..." dir=. if [ -n "${1}" ]; then - dir=$1 + dir="${@}" fi -list=$(find "$dir" -name "*.bin" -type f | grep -v dump-response.bin) +list=$(find $dir -name "*.bin" -type f | grep -v dump-response.bin) for file in $list; do echo "${file}" @@ -39,7 +42,7 @@ for file in $list; do fi ((i=i%N)); ((i++==0)) && wait - ../node_modules/.bin/ts-node ./codegen.ts "${dir}" "${file}" "${params}" & + "${INTEGRATION_DIR}/../node_modules/.bin/ts-node" "${INTEGRATION_DIR}/codegen.ts" "${dir}" "${file}" "${params}" & done wait diff --git a/integration/const-enum/const-enum.bin b/integration/const-enum/const-enum.bin index 9842cd90a..12ff3f8df 100644 Binary files a/integration/const-enum/const-enum.bin and b/integration/const-enum/const-enum.bin differ diff --git a/integration/generic-service-definitions/simple.bin b/integration/generic-service-definitions/simple.bin index adf555a23..f101042df 100644 Binary files a/integration/generic-service-definitions/simple.bin and b/integration/generic-service-definitions/simple.bin differ diff --git a/integration/global-this/global-this.bin b/integration/global-this/global-this.bin index beb04f287..4a39e83e8 100644 Binary files a/integration/global-this/global-this.bin and b/integration/global-this/global-this.bin differ diff --git a/integration/grpc-js/google/protobuf/struct.ts b/integration/grpc-js/google/protobuf/struct.ts index abe3dfe8d..a2b7d6f54 100644 --- a/integration/grpc-js/google/protobuf/struct.ts +++ b/integration/grpc-js/google/protobuf/struct.ts @@ -60,8 +60,8 @@ export interface Struct_FieldsEntry { /** * `Value` represents a dynamically typed value which can be either * null, a number, a string, a boolean, a recursive struct value, or a - * list of values. A producer of value is expected to set one of that - * variants, absence of any variant indicates an error. + * list of values. A producer of value is expected to set one of these + * variants. Absence of any variant indicates an error. * * The JSON representation for `Value` is JSON value. */ diff --git a/integration/grpc-js/simple.bin b/integration/grpc-js/simple.bin index 97028a38b..a4adec606 100644 Binary files a/integration/grpc-js/simple.bin and b/integration/grpc-js/simple.bin differ diff --git a/integration/grpc-web-go-server/example.bin b/integration/grpc-web-go-server/example.bin index 5a0f331f3..1c0736d42 100644 Binary files a/integration/grpc-web-go-server/example.bin and b/integration/grpc-web-go-server/example.bin differ diff --git a/integration/grpc-web-no-streaming-observable/example.bin b/integration/grpc-web-no-streaming-observable/example.bin index 539202d2d..0b96ce0c6 100644 Binary files a/integration/grpc-web-no-streaming-observable/example.bin and b/integration/grpc-web-no-streaming-observable/example.bin differ diff --git a/integration/grpc-web-no-streaming/example.bin b/integration/grpc-web-no-streaming/example.bin index 539202d2d..0b96ce0c6 100644 Binary files a/integration/grpc-web-no-streaming/example.bin and b/integration/grpc-web-no-streaming/example.bin differ diff --git a/integration/grpc-web/example.bin b/integration/grpc-web/example.bin index a1281f473..ace3893cc 100644 Binary files a/integration/grpc-web/example.bin and b/integration/grpc-web/example.bin differ diff --git a/integration/lower-case-svc-methods/math.bin b/integration/lower-case-svc-methods/math.bin index 236dc3d61..eddba34a4 100644 Binary files a/integration/lower-case-svc-methods/math.bin and b/integration/lower-case-svc-methods/math.bin differ diff --git a/integration/meta-typings/google/protobuf/timestamp.ts b/integration/meta-typings/google/protobuf/timestamp.ts index 927b4c71a..f31402980 100644 --- a/integration/meta-typings/google/protobuf/timestamp.ts +++ b/integration/meta-typings/google/protobuf/timestamp.ts @@ -57,7 +57,16 @@ export const protobufPackage = 'google.protobuf'; * .setNanos((int) ((millis % 1000) * 1000000)).build(); * * - * Example 5: Compute Timestamp from current time in Python. + * Example 5: Compute Timestamp from Java `Instant.now()`. + * + * Instant now = Instant.now(); + * + * Timestamp timestamp = + * Timestamp.newBuilder().setSeconds(now.getEpochSecond()) + * .setNanos(now.getNano()).build(); + * + * + * Example 6: Compute Timestamp from current time in Python. * * timestamp = Timestamp() * timestamp.GetCurrentTime() @@ -177,7 +186,7 @@ export const protoMetadata: ProtoMetadata = { javaPackage: 'com.google.protobuf', javaOuterClassname: 'TimestampProto', javaMultipleFiles: true, - goPackage: 'github.com/golang/protobuf/ptypes/timestamp', + goPackage: 'google.golang.org/protobuf/types/known/timestamppb', ccEnableArenas: true, objcClassPrefix: 'GPB', csharpNamespace: 'Google.Protobuf.WellKnownTypes', @@ -186,21 +195,21 @@ export const protoMetadata: ProtoMetadata = { location: [ { path: [4, 0], - span: [126, 0, 137, 1], + span: [135, 0, 146, 1], leadingDetachedComments: [], leadingComments: - ' A Timestamp represents a point in time independent of any time zone or local\n calendar, encoded as a count of seconds and fractions of seconds at\n nanosecond resolution. The count is relative to an epoch at UTC midnight on\n January 1, 1970, in the proleptic Gregorian calendar which extends the\n Gregorian calendar backwards to year one.\n\n All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap\n second table is needed for interpretation, using a [24-hour linear\n smear](https://developers.google.com/time/smear).\n\n The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By\n restricting to that range, we ensure that we can convert to and from [RFC\n 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings.\n\n # Examples\n\n Example 1: Compute Timestamp from POSIX `time()`.\n\n Timestamp timestamp;\n timestamp.set_seconds(time(NULL));\n timestamp.set_nanos(0);\n\n Example 2: Compute Timestamp from POSIX `gettimeofday()`.\n\n struct timeval tv;\n gettimeofday(&tv, NULL);\n\n Timestamp timestamp;\n timestamp.set_seconds(tv.tv_sec);\n timestamp.set_nanos(tv.tv_usec * 1000);\n\n Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`.\n\n FILETIME ft;\n GetSystemTimeAsFileTime(&ft);\n UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime;\n\n // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z\n // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z.\n Timestamp timestamp;\n timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL));\n timestamp.set_nanos((INT32) ((ticks % 10000000) * 100));\n\n Example 4: Compute Timestamp from Java `System.currentTimeMillis()`.\n\n long millis = System.currentTimeMillis();\n\n Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000)\n .setNanos((int) ((millis % 1000) * 1000000)).build();\n\n\n Example 5: Compute Timestamp from current time in Python.\n\n timestamp = Timestamp()\n timestamp.GetCurrentTime()\n\n # JSON Mapping\n\n In JSON format, the Timestamp type is encoded as a string in the\n [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the\n format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z"\n where {year} is always expressed using four digits while {month}, {day},\n {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional\n seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution),\n are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone\n is required. A proto3 JSON serializer should always use UTC (as indicated by\n "Z") when printing the Timestamp type and a proto3 JSON parser should be\n able to accept both UTC and other timezones (as indicated by an offset).\n\n For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past\n 01:30 UTC on January 15, 2017.\n\n In JavaScript, one can convert a Date object to this format using the\n standard\n [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)\n method. In Python, a standard `datetime.datetime` object can be converted\n to this format using\n [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with\n the time format spec \'%Y-%m-%dT%H:%M:%S.%fZ\'. Likewise, in Java, one can use\n the Joda Time\'s [`ISODateTimeFormat.dateTime()`](\n http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D\n ) to obtain a formatter capable of generating timestamps in this format.\n\n\n', + ' A Timestamp represents a point in time independent of any time zone or local\n calendar, encoded as a count of seconds and fractions of seconds at\n nanosecond resolution. The count is relative to an epoch at UTC midnight on\n January 1, 1970, in the proleptic Gregorian calendar which extends the\n Gregorian calendar backwards to year one.\n\n All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap\n second table is needed for interpretation, using a [24-hour linear\n smear](https://developers.google.com/time/smear).\n\n The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By\n restricting to that range, we ensure that we can convert to and from [RFC\n 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings.\n\n # Examples\n\n Example 1: Compute Timestamp from POSIX `time()`.\n\n Timestamp timestamp;\n timestamp.set_seconds(time(NULL));\n timestamp.set_nanos(0);\n\n Example 2: Compute Timestamp from POSIX `gettimeofday()`.\n\n struct timeval tv;\n gettimeofday(&tv, NULL);\n\n Timestamp timestamp;\n timestamp.set_seconds(tv.tv_sec);\n timestamp.set_nanos(tv.tv_usec * 1000);\n\n Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`.\n\n FILETIME ft;\n GetSystemTimeAsFileTime(&ft);\n UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime;\n\n // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z\n // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z.\n Timestamp timestamp;\n timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL));\n timestamp.set_nanos((INT32) ((ticks % 10000000) * 100));\n\n Example 4: Compute Timestamp from Java `System.currentTimeMillis()`.\n\n long millis = System.currentTimeMillis();\n\n Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000)\n .setNanos((int) ((millis % 1000) * 1000000)).build();\n\n\n Example 5: Compute Timestamp from Java `Instant.now()`.\n\n Instant now = Instant.now();\n\n Timestamp timestamp =\n Timestamp.newBuilder().setSeconds(now.getEpochSecond())\n .setNanos(now.getNano()).build();\n\n\n Example 6: Compute Timestamp from current time in Python.\n\n timestamp = Timestamp()\n timestamp.GetCurrentTime()\n\n # JSON Mapping\n\n In JSON format, the Timestamp type is encoded as a string in the\n [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the\n format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z"\n where {year} is always expressed using four digits while {month}, {day},\n {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional\n seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution),\n are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone\n is required. A proto3 JSON serializer should always use UTC (as indicated by\n "Z") when printing the Timestamp type and a proto3 JSON parser should be\n able to accept both UTC and other timezones (as indicated by an offset).\n\n For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past\n 01:30 UTC on January 15, 2017.\n\n In JavaScript, one can convert a Date object to this format using the\n standard\n [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)\n method. In Python, a standard `datetime.datetime` object can be converted\n to this format using\n [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with\n the time format spec \'%Y-%m-%dT%H:%M:%S.%fZ\'. Likewise, in Java, one can use\n the Joda Time\'s [`ISODateTimeFormat.dateTime()`](\n http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D\n ) to obtain a formatter capable of generating timestamps in this format.\n\n\n', }, { path: [4, 0, 2, 0], - span: [130, 2, 20], + span: [139, 2, 20], leadingDetachedComments: [], leadingComments: ' Represents seconds of UTC time since Unix epoch\n 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to\n 9999-12-31T23:59:59Z inclusive.\n', }, { path: [4, 0, 2, 1], - span: [136, 2, 18], + span: [145, 2, 18], leadingDetachedComments: [], leadingComments: ' Non-negative fractions of a second at nanosecond resolution. Negative\n second values with fractions must still have non-negative nanos values\n that count forward in time. Must be from 0 to 999,999,999\n inclusive.\n', diff --git a/integration/meta-typings/meta-typings-test.ts b/integration/meta-typings/meta-typings-test.ts index 53a40554e..ade8e5da0 100644 --- a/integration/meta-typings/meta-typings-test.ts +++ b/integration/meta-typings/meta-typings-test.ts @@ -869,7 +869,7 @@ describe('simple', () => { "ccGenericServices": false, "csharpNamespace": "Google.Protobuf.WellKnownTypes", "deprecated": false, - "goPackage": "github.com/golang/protobuf/ptypes/timestamp", + "goPackage": "google.golang.org/protobuf/types/known/timestamppb", "javaGenerateEqualsAndHash": false, "javaGenericServices": false, "javaMultipleFiles": true, @@ -944,7 +944,16 @@ describe('simple', () => { .setNanos((int) ((millis % 1000) * 1000000)).build(); - Example 5: Compute Timestamp from current time in Python. + Example 5: Compute Timestamp from Java \`Instant.now()\`. + + Instant now = Instant.now(); + + Timestamp timestamp = + Timestamp.newBuilder().setSeconds(now.getEpochSecond()) + .setNanos(now.getNano()).build(); + + + Example 6: Compute Timestamp from current time in Python. timestamp = Timestamp() timestamp.GetCurrentTime() @@ -984,9 +993,9 @@ describe('simple', () => { 0, ], "span": Array [ - 126, + 135, 0, - 137, + 146, 1, ], "trailingComments": "", @@ -1004,7 +1013,7 @@ describe('simple', () => { 0, ], "span": Array [ - 130, + 139, 2, 20, ], @@ -1024,7 +1033,7 @@ describe('simple', () => { 1, ], "span": Array [ - 136, + 145, 2, 18, ], @@ -1097,7 +1106,7 @@ describe('simple', () => { "ccGenericServices": false, "csharpNamespace": "Google.Protobuf.WellKnownTypes", "deprecated": false, - "goPackage": "github.com/golang/protobuf/ptypes/timestamp", + "goPackage": "google.golang.org/protobuf/types/known/timestamppb", "javaGenerateEqualsAndHash": false, "javaGenericServices": false, "javaMultipleFiles": true, @@ -1172,7 +1181,16 @@ describe('simple', () => { .setNanos((int) ((millis % 1000) * 1000000)).build(); - Example 5: Compute Timestamp from current time in Python. + Example 5: Compute Timestamp from Java \`Instant.now()\`. + + Instant now = Instant.now(); + + Timestamp timestamp = + Timestamp.newBuilder().setSeconds(now.getEpochSecond()) + .setNanos(now.getNano()).build(); + + + Example 6: Compute Timestamp from current time in Python. timestamp = Timestamp() timestamp.GetCurrentTime() @@ -1212,9 +1230,9 @@ describe('simple', () => { 0, ], "span": Array [ - 126, + 135, 0, - 137, + 146, 1, ], "trailingComments": "", @@ -1232,7 +1250,7 @@ describe('simple', () => { 0, ], "span": Array [ - 130, + 139, 2, 20, ], @@ -1252,7 +1270,7 @@ describe('simple', () => { 1, ], "span": Array [ - 136, + 145, 2, 18, ], diff --git a/integration/meta-typings/simple.bin b/integration/meta-typings/simple.bin index 6812857bc..0fffa492d 100644 Binary files a/integration/meta-typings/simple.bin and b/integration/meta-typings/simple.bin differ diff --git a/integration/nestjs-metadata-grpc-js/hero.bin b/integration/nestjs-metadata-grpc-js/hero.bin index d48fee5f7..ad7849d17 100644 Binary files a/integration/nestjs-metadata-grpc-js/hero.bin and b/integration/nestjs-metadata-grpc-js/hero.bin differ diff --git a/integration/nestjs-metadata-observables/hero.bin b/integration/nestjs-metadata-observables/hero.bin index d48fee5f7..ad7849d17 100644 Binary files a/integration/nestjs-metadata-observables/hero.bin and b/integration/nestjs-metadata-observables/hero.bin differ diff --git a/integration/nestjs-metadata-restparameters/hero.bin b/integration/nestjs-metadata-restparameters/hero.bin index d48fee5f7..ad7849d17 100644 Binary files a/integration/nestjs-metadata-restparameters/hero.bin and b/integration/nestjs-metadata-restparameters/hero.bin differ diff --git a/integration/nestjs-metadata/hero.bin b/integration/nestjs-metadata/hero.bin index d48fee5f7..ad7849d17 100644 Binary files a/integration/nestjs-metadata/hero.bin and b/integration/nestjs-metadata/hero.bin differ diff --git a/integration/nestjs-restparameters/hero.bin b/integration/nestjs-restparameters/hero.bin index d48fee5f7..ad7849d17 100644 Binary files a/integration/nestjs-restparameters/hero.bin and b/integration/nestjs-restparameters/hero.bin differ diff --git a/integration/nestjs-simple-observables/hero.bin b/integration/nestjs-simple-observables/hero.bin index d48fee5f7..ad7849d17 100644 Binary files a/integration/nestjs-simple-observables/hero.bin and b/integration/nestjs-simple-observables/hero.bin differ diff --git a/integration/nestjs-simple-restparameters/hero.bin b/integration/nestjs-simple-restparameters/hero.bin index 0f667238c..0e82b21bc 100644 Binary files a/integration/nestjs-simple-restparameters/hero.bin and b/integration/nestjs-simple-restparameters/hero.bin differ diff --git a/integration/nestjs-simple/google/protobuf/timestamp.ts b/integration/nestjs-simple/google/protobuf/timestamp.ts index 1068c244d..a5fa33b23 100644 --- a/integration/nestjs-simple/google/protobuf/timestamp.ts +++ b/integration/nestjs-simple/google/protobuf/timestamp.ts @@ -56,7 +56,16 @@ export const protobufPackage = 'google.protobuf'; * .setNanos((int) ((millis % 1000) * 1000000)).build(); * * - * Example 5: Compute Timestamp from current time in Python. + * Example 5: Compute Timestamp from Java `Instant.now()`. + * + * Instant now = Instant.now(); + * + * Timestamp timestamp = + * Timestamp.newBuilder().setSeconds(now.getEpochSecond()) + * .setNanos(now.getNano()).build(); + * + * + * Example 6: Compute Timestamp from current time in Python. * * timestamp = Timestamp() * timestamp.GetCurrentTime() diff --git a/integration/nestjs-simple/hero.bin b/integration/nestjs-simple/hero.bin index c3ce2b17b..3ce8c0002 100644 Binary files a/integration/nestjs-simple/hero.bin and b/integration/nestjs-simple/hero.bin differ diff --git a/integration/no-proto-package/no-proto-package.bin b/integration/no-proto-package/no-proto-package.bin index a07d20f4b..b23df4108 100644 Binary files a/integration/no-proto-package/no-proto-package.bin and b/integration/no-proto-package/no-proto-package.bin differ diff --git a/integration/oneof-properties/oneof.bin b/integration/oneof-properties/oneof.bin index 2fc8f8616..e3c94035b 100644 Binary files a/integration/oneof-properties/oneof.bin and b/integration/oneof-properties/oneof.bin differ diff --git a/integration/oneof-unions/oneof.bin b/integration/oneof-unions/oneof.bin index 421cc6ec7..1ffbd30ec 100644 Binary files a/integration/oneof-unions/oneof.bin and b/integration/oneof-unions/oneof.bin differ diff --git a/integration/only-types-grpc-metadata/only-types-grpc-metadata.bin b/integration/only-types-grpc-metadata/only-types-grpc-metadata.bin index 91849ed14..e43e9b997 100644 Binary files a/integration/only-types-grpc-metadata/only-types-grpc-metadata.bin and b/integration/only-types-grpc-metadata/only-types-grpc-metadata.bin differ diff --git a/integration/only-types/google/protobuf/any.ts b/integration/only-types/google/protobuf/any.ts index 04572d4fc..ade2721aa 100644 --- a/integration/only-types/google/protobuf/any.ts +++ b/integration/only-types/google/protobuf/any.ts @@ -40,10 +40,13 @@ export const protobufPackage = 'google.protobuf'; * Example 4: Pack and unpack a message in Go * * foo := &pb.Foo{...} - * any, err := ptypes.MarshalAny(foo) + * any, err := anypb.New(foo) + * if err != nil { + * ... + * } * ... * foo := &pb.Foo{} - * if err := ptypes.UnmarshalAny(any, foo); err != nil { + * if err := any.UnmarshalTo(foo); err != nil { * ... * } * diff --git a/integration/only-types/google/protobuf/timestamp.ts b/integration/only-types/google/protobuf/timestamp.ts index 3fd84b70a..c88251a53 100644 --- a/integration/only-types/google/protobuf/timestamp.ts +++ b/integration/only-types/google/protobuf/timestamp.ts @@ -53,7 +53,16 @@ export const protobufPackage = 'google.protobuf'; * .setNanos((int) ((millis % 1000) * 1000000)).build(); * * - * Example 5: Compute Timestamp from current time in Python. + * Example 5: Compute Timestamp from Java `Instant.now()`. + * + * Instant now = Instant.now(); + * + * Timestamp timestamp = + * Timestamp.newBuilder().setSeconds(now.getEpochSecond()) + * .setNanos(now.getNano()).build(); + * + * + * Example 6: Compute Timestamp from current time in Python. * * timestamp = Timestamp() * timestamp.GetCurrentTime() diff --git a/integration/only-types/reservation.bin b/integration/only-types/reservation.bin index 774442d3f..27024a9e9 100644 Binary files a/integration/only-types/reservation.bin and b/integration/only-types/reservation.bin differ diff --git a/integration/point/point.bin b/integration/point/point.bin index 788211d81..a9f42b5d2 100644 Binary files a/integration/point/point.bin and b/integration/point/point.bin differ diff --git a/integration/protoc-gen-dump.bat b/integration/protoc-gen-dump.bat new file mode 100644 index 000000000..272f9e037 --- /dev/null +++ b/integration/protoc-gen-dump.bat @@ -0,0 +1 @@ +@bash protoc-gen-dump diff --git a/integration/return-observable/observable.bin b/integration/return-observable/observable.bin index 2373a978d..267c620b9 100644 Binary files a/integration/return-observable/observable.bin and b/integration/return-observable/observable.bin differ diff --git a/integration/simple-deprecated-fields/simple.bin b/integration/simple-deprecated-fields/simple.bin index 6255f0424..edc1b92bd 100644 Binary files a/integration/simple-deprecated-fields/simple.bin and b/integration/simple-deprecated-fields/simple.bin differ diff --git a/integration/simple-esmodule-interop/simple.bin b/integration/simple-esmodule-interop/simple.bin index da76fbd6a..fd3a1d254 100644 Binary files a/integration/simple-esmodule-interop/simple.bin and b/integration/simple-esmodule-interop/simple.bin differ diff --git a/integration/simple-json-name/simple.bin b/integration/simple-json-name/simple.bin index 97d15a687..6f4c9ddf5 100644 Binary files a/integration/simple-json-name/simple.bin and b/integration/simple-json-name/simple.bin differ diff --git a/integration/simple-long-string/google/protobuf/timestamp.ts b/integration/simple-long-string/google/protobuf/timestamp.ts index 5c733ee05..0fc344c57 100644 --- a/integration/simple-long-string/google/protobuf/timestamp.ts +++ b/integration/simple-long-string/google/protobuf/timestamp.ts @@ -56,7 +56,16 @@ export const protobufPackage = 'google.protobuf'; * .setNanos((int) ((millis % 1000) * 1000000)).build(); * * - * Example 5: Compute Timestamp from current time in Python. + * Example 5: Compute Timestamp from Java `Instant.now()`. + * + * Instant now = Instant.now(); + * + * Timestamp timestamp = + * Timestamp.newBuilder().setSeconds(now.getEpochSecond()) + * .setNanos(now.getNano()).build(); + * + * + * Example 6: Compute Timestamp from current time in Python. * * timestamp = Timestamp() * timestamp.GetCurrentTime() diff --git a/integration/simple-long-string/simple.bin b/integration/simple-long-string/simple.bin index b89792eb0..486951c66 100644 Binary files a/integration/simple-long-string/simple.bin and b/integration/simple-long-string/simple.bin differ diff --git a/integration/simple-long/simple.bin b/integration/simple-long/simple.bin index b1ad8ee48..28e779a04 100644 Binary files a/integration/simple-long/simple.bin and b/integration/simple-long/simple.bin differ diff --git a/integration/simple-optionals/google/protobuf/timestamp.ts b/integration/simple-optionals/google/protobuf/timestamp.ts index dfd3577e7..e4600a73e 100644 --- a/integration/simple-optionals/google/protobuf/timestamp.ts +++ b/integration/simple-optionals/google/protobuf/timestamp.ts @@ -56,7 +56,16 @@ export const protobufPackage = 'google.protobuf'; * .setNanos((int) ((millis % 1000) * 1000000)).build(); * * - * Example 5: Compute Timestamp from current time in Python. + * Example 5: Compute Timestamp from Java `Instant.now()`. + * + * Instant now = Instant.now(); + * + * Timestamp timestamp = + * Timestamp.newBuilder().setSeconds(now.getEpochSecond()) + * .setNanos(now.getNano()).build(); + * + * + * Example 6: Compute Timestamp from current time in Python. * * timestamp = Timestamp() * timestamp.GetCurrentTime() diff --git a/integration/simple-optionals/simple.bin b/integration/simple-optionals/simple.bin index d5f6049e5..d6a2033ae 100644 Binary files a/integration/simple-optionals/simple.bin and b/integration/simple-optionals/simple.bin differ diff --git a/integration/simple-optionals/thing.bin b/integration/simple-optionals/thing.bin index 4780dd38c..132073529 100644 Binary files a/integration/simple-optionals/thing.bin and b/integration/simple-optionals/thing.bin differ diff --git a/integration/simple-proto2/simple.bin b/integration/simple-proto2/simple.bin index bc6fb5234..c879526ac 100644 Binary files a/integration/simple-proto2/simple.bin and b/integration/simple-proto2/simple.bin differ diff --git a/integration/simple-snake/google/protobuf/timestamp.ts b/integration/simple-snake/google/protobuf/timestamp.ts index dfd3577e7..e4600a73e 100644 --- a/integration/simple-snake/google/protobuf/timestamp.ts +++ b/integration/simple-snake/google/protobuf/timestamp.ts @@ -56,7 +56,16 @@ export const protobufPackage = 'google.protobuf'; * .setNanos((int) ((millis % 1000) * 1000000)).build(); * * - * Example 5: Compute Timestamp from current time in Python. + * Example 5: Compute Timestamp from Java `Instant.now()`. + * + * Instant now = Instant.now(); + * + * Timestamp timestamp = + * Timestamp.newBuilder().setSeconds(now.getEpochSecond()) + * .setNanos(now.getNano()).build(); + * + * + * Example 6: Compute Timestamp from current time in Python. * * timestamp = Timestamp() * timestamp.GetCurrentTime() diff --git a/integration/simple-snake/simple.bin b/integration/simple-snake/simple.bin index d5f6049e5..d6a2033ae 100644 Binary files a/integration/simple-snake/simple.bin and b/integration/simple-snake/simple.bin differ diff --git a/integration/simple-string-enums/simple.bin b/integration/simple-string-enums/simple.bin index 602c5ff1e..8729b3131 100644 Binary files a/integration/simple-string-enums/simple.bin and b/integration/simple-string-enums/simple.bin differ diff --git a/integration/simple-unrecognized-enum/google/protobuf/timestamp.ts b/integration/simple-unrecognized-enum/google/protobuf/timestamp.ts index dfd3577e7..e4600a73e 100644 --- a/integration/simple-unrecognized-enum/google/protobuf/timestamp.ts +++ b/integration/simple-unrecognized-enum/google/protobuf/timestamp.ts @@ -56,7 +56,16 @@ export const protobufPackage = 'google.protobuf'; * .setNanos((int) ((millis % 1000) * 1000000)).build(); * * - * Example 5: Compute Timestamp from current time in Python. + * Example 5: Compute Timestamp from Java `Instant.now()`. + * + * Instant now = Instant.now(); + * + * Timestamp timestamp = + * Timestamp.newBuilder().setSeconds(now.getEpochSecond()) + * .setNanos(now.getNano()).build(); + * + * + * Example 6: Compute Timestamp from current time in Python. * * timestamp = Timestamp() * timestamp.GetCurrentTime() diff --git a/integration/simple-unrecognized-enum/simple.bin b/integration/simple-unrecognized-enum/simple.bin index d5f6049e5..d6a2033ae 100644 Binary files a/integration/simple-unrecognized-enum/simple.bin and b/integration/simple-unrecognized-enum/simple.bin differ diff --git a/integration/simple/google/protobuf/timestamp.ts b/integration/simple/google/protobuf/timestamp.ts index dfd3577e7..e4600a73e 100644 --- a/integration/simple/google/protobuf/timestamp.ts +++ b/integration/simple/google/protobuf/timestamp.ts @@ -56,7 +56,16 @@ export const protobufPackage = 'google.protobuf'; * .setNanos((int) ((millis % 1000) * 1000000)).build(); * * - * Example 5: Compute Timestamp from current time in Python. + * Example 5: Compute Timestamp from Java `Instant.now()`. + * + * Instant now = Instant.now(); + * + * Timestamp timestamp = + * Timestamp.newBuilder().setSeconds(now.getEpochSecond()) + * .setNanos(now.getNano()).build(); + * + * + * Example 6: Compute Timestamp from current time in Python. * * timestamp = Timestamp() * timestamp.GetCurrentTime() diff --git a/integration/simple/simple.bin b/integration/simple/simple.bin index eb98fb18e..321bb33c3 100644 Binary files a/integration/simple/simple.bin and b/integration/simple/simple.bin differ diff --git a/integration/struct/google/protobuf/struct.ts b/integration/struct/google/protobuf/struct.ts index abe3dfe8d..a2b7d6f54 100644 --- a/integration/struct/google/protobuf/struct.ts +++ b/integration/struct/google/protobuf/struct.ts @@ -60,8 +60,8 @@ export interface Struct_FieldsEntry { /** * `Value` represents a dynamically typed value which can be either * null, a number, a string, a boolean, a recursive struct value, or a - * list of values. A producer of value is expected to set one of that - * variants, absence of any variant indicates an error. + * list of values. A producer of value is expected to set one of these + * variants. Absence of any variant indicates an error. * * The JSON representation for `Value` is JSON value. */ diff --git a/integration/struct/struct.bin b/integration/struct/struct.bin index af5a5b0a3..d9a1b260e 100644 Binary files a/integration/struct/struct.bin and b/integration/struct/struct.bin differ diff --git a/integration/type-registry/foo.bin b/integration/type-registry/foo.bin index c5f68fe83..f6f140796 100644 Binary files a/integration/type-registry/foo.bin and b/integration/type-registry/foo.bin differ diff --git a/integration/types-with-underscores/file.bin b/integration/types-with-underscores/file.bin index 7cb551914..eeb5f3f23 100644 Binary files a/integration/types-with-underscores/file.bin and b/integration/types-with-underscores/file.bin differ diff --git a/integration/update-bins.sh b/integration/update-bins.sh index 66852c3e1..ae2be93a5 100755 --- a/integration/update-bins.sh +++ b/integration/update-bins.sh @@ -1,17 +1,23 @@ #!/usr/bin/env bash # To avoid running the protoc pipeline all the time, we capture the incoming Plugin -# proto requests into .bin files that then unit tests can pull in directly as needed. -list=$(find . -name "*.proto" -type f) +# proto requests into .bin PROTO_FILES that then unit tests can pull in directly as needed. -for file in $list; do - echo "${file}" -# # Strip the longest suffix starting at the 1st slash - dir="${file##./}" - dir="${dir%%/*}" +INTEGRATION_DIR=$(realpath $(dirname "$BASH_SOURCE")) +cd $INTEGRATION_DIR; - # Strip the proto suffix and add bin - dest="${file%proto}bin" - protoc --experimental_allow_proto3_optional "--plugin=$(pwd)/protoc-gen-dump" --dump_out=. "${file}" "-I${dir}" - mv file.bin "${dest}" +if [[ "$OSTYPE" == "msys" ]]; then + PLUGIN_PATH="protoc-gen-dump.bat" +else + PLUGIN_PATH="protoc-gen-dump" +fi + +PROTO_FILES=$(find . -maxdepth 2 -name "*.proto" -type f) + +for FILE in $PROTO_FILES; do + echo "${FILE}" + INPUT_DIR="$(dirname "$FILE")" + OUTPUT_FILE="${FILE%proto}bin" + protoc --experimental_allow_proto3_optional "--plugin=$PLUGIN_PATH" --dump_out=. "${FILE}" "-I${INPUT_DIR}" + mv file.bin "${OUTPUT_FILE}" done diff --git a/integration/use-date-false/google/protobuf/timestamp.ts b/integration/use-date-false/google/protobuf/timestamp.ts index dfd3577e7..e4600a73e 100644 --- a/integration/use-date-false/google/protobuf/timestamp.ts +++ b/integration/use-date-false/google/protobuf/timestamp.ts @@ -56,7 +56,16 @@ export const protobufPackage = 'google.protobuf'; * .setNanos((int) ((millis % 1000) * 1000000)).build(); * * - * Example 5: Compute Timestamp from current time in Python. + * Example 5: Compute Timestamp from Java `Instant.now()`. + * + * Instant now = Instant.now(); + * + * Timestamp timestamp = + * Timestamp.newBuilder().setSeconds(now.getEpochSecond()) + * .setNanos(now.getNano()).build(); + * + * + * Example 6: Compute Timestamp from current time in Python. * * timestamp = Timestamp() * timestamp.GetCurrentTime() diff --git a/integration/use-date-false/metadata.bin b/integration/use-date-false/metadata.bin index f1c729790..c4c8c7256 100644 Binary files a/integration/use-date-false/metadata.bin and b/integration/use-date-false/metadata.bin differ diff --git a/integration/use-date-string/google/protobuf/timestamp.ts b/integration/use-date-string/google/protobuf/timestamp.ts index dfd3577e7..e4600a73e 100644 --- a/integration/use-date-string/google/protobuf/timestamp.ts +++ b/integration/use-date-string/google/protobuf/timestamp.ts @@ -56,7 +56,16 @@ export const protobufPackage = 'google.protobuf'; * .setNanos((int) ((millis % 1000) * 1000000)).build(); * * - * Example 5: Compute Timestamp from current time in Python. + * Example 5: Compute Timestamp from Java `Instant.now()`. + * + * Instant now = Instant.now(); + * + * Timestamp timestamp = + * Timestamp.newBuilder().setSeconds(now.getEpochSecond()) + * .setNanos(now.getNano()).build(); + * + * + * Example 6: Compute Timestamp from current time in Python. * * timestamp = Timestamp() * timestamp.GetCurrentTime() diff --git a/integration/use-date-string/use-date-string.bin b/integration/use-date-string/use-date-string.bin index 6629454ec..79e656e01 100644 Binary files a/integration/use-date-string/use-date-string.bin and b/integration/use-date-string/use-date-string.bin differ diff --git a/integration/use-date-true/google/protobuf/timestamp.ts b/integration/use-date-true/google/protobuf/timestamp.ts index dfd3577e7..e4600a73e 100644 --- a/integration/use-date-true/google/protobuf/timestamp.ts +++ b/integration/use-date-true/google/protobuf/timestamp.ts @@ -56,7 +56,16 @@ export const protobufPackage = 'google.protobuf'; * .setNanos((int) ((millis % 1000) * 1000000)).build(); * * - * Example 5: Compute Timestamp from current time in Python. + * Example 5: Compute Timestamp from Java `Instant.now()`. + * + * Instant now = Instant.now(); + * + * Timestamp timestamp = + * Timestamp.newBuilder().setSeconds(now.getEpochSecond()) + * .setNanos(now.getNano()).build(); + * + * + * Example 6: Compute Timestamp from current time in Python. * * timestamp = Timestamp() * timestamp.GetCurrentTime() diff --git a/integration/use-date-true/use-date-true.bin b/integration/use-date-true/use-date-true.bin index c71a37d8a..1a6bb1cb0 100644 Binary files a/integration/use-date-true/use-date-true.bin and b/integration/use-date-true/use-date-true.bin differ diff --git a/integration/value/google/protobuf/struct.ts b/integration/value/google/protobuf/struct.ts index abe3dfe8d..a2b7d6f54 100644 --- a/integration/value/google/protobuf/struct.ts +++ b/integration/value/google/protobuf/struct.ts @@ -60,8 +60,8 @@ export interface Struct_FieldsEntry { /** * `Value` represents a dynamically typed value which can be either * null, a number, a string, a boolean, a recursive struct value, or a - * list of values. A producer of value is expected to set one of that - * variants, absence of any variant indicates an error. + * list of values. A producer of value is expected to set one of these + * variants. Absence of any variant indicates an error. * * The JSON representation for `Value` is JSON value. */ diff --git a/integration/value/value.bin b/integration/value/value.bin index 4f4868c81..f10ce787a 100644 Binary files a/integration/value/value.bin and b/integration/value/value.bin differ diff --git a/integration/vector-tile/vector_tile.bin b/integration/vector-tile/vector_tile.bin index 30bea5c1e..dad36b4bb 100644 Binary files a/integration/vector-tile/vector_tile.bin and b/integration/vector-tile/vector_tile.bin differ diff --git a/package.json b/package.json index 638f3a74f..19f9795e1 100644 --- a/package.json +++ b/package.json @@ -9,10 +9,19 @@ }, "scripts": { "build": "yarn tsc", - "setup": "cd ./integration && ./pbjs.sh && ./update-bins.sh && ./codegen.sh", + "build:test": "yarn proto2bin && yarn proto2pbjs && yarn bin2ts", + "build:test:local": "yarn proto2bin:local && yarn proto2pbjs:local && yarn bin2ts:local", + "proto2bin": "docker-compose run --rm --entrypoint bash -w /ts-proto/integration protoc update-bins.sh", + "proto2bin-node": "docker-compose run --rm --entrypoint bash -w /ts-proto/integration node update-bins.sh", + "proto2pbjs": "docker-compose run --rm --entrypoint bash -w /ts-proto/integration protoc pbjs.sh", + "bin2ts": "docker-compose run --rm --entrypoint bash -w /ts-proto/integration protoc codegen.sh", + "proto2bin:local": "integration/update-bins.sh", + "proto2pbjs:local": "integration/pbjs.sh", + "bin2ts:local": "integration/codegen.sh", "test": "yarn jest -c jest.config.js --maxWorkers=2", "prettier": "prettier --write {src,tests}/**/*.ts", - "prettier:check": "prettier --list-different {src,tests}/**/*.ts" + "prettier:check": "prettier --list-different {src,tests}/**/*.ts", + "setup:docker": "docker-compose build" }, "files": [ "build" diff --git a/protoc.Dockerfile b/protoc.Dockerfile new file mode 100644 index 000000000..f8a127b02 --- /dev/null +++ b/protoc.Dockerfile @@ -0,0 +1,17 @@ +# Docker image for protoc +ARG BASE="alpine:3.14.3" +FROM $BASE +ARG PROTOC_VERSION="3.19.1" +ARG BIN="" + +RUN apk add bash +RUN apk add gcompat +ADD "https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOC_VERSION/protoc-$PROTOC_VERSION-linux-x86_64.zip" protoc.zip +RUN mkdir /usr/local/lib/protoc && unzip protoc.zip -d /usr/local/lib/protoc && rm protoc.zip +RUN ln -s /usr/local/lib/protoc/bin/protoc /usr/local/bin/protoc + +RUN protoc --version + +ENV PATH "$BIN:$PATH" + +ENTRYPOINT ["/usr/local/bin/protoc"]