From 11d06b4455a1f27793bfe172fffaf05b7a3400db Mon Sep 17 00:00:00 2001 From: Stephen Haberman Date: Sat, 17 Feb 2024 14:34:35 -0600 Subject: [PATCH] fix: Use as any on globalThis.Buffer check. (#1004) See #967. --- .../before-after-request-streaming/google/protobuf/wrappers.ts | 2 +- integration/bytes-as-base64/message.ts | 2 +- integration/emit-default-values-json/test.ts | 2 +- integration/grpc-js/google/protobuf/wrappers.ts | 2 +- integration/grpc-web/google/protobuf/wrappers.ts | 2 +- integration/nice-grpc/google/protobuf/wrappers.ts | 2 +- integration/oneof-properties/oneof.ts | 2 +- integration/oneof-unions/oneof.ts | 2 +- integration/output-toJSON-only/google/protobuf/wrappers.ts | 2 +- integration/simple-long-bigint/google/protobuf/wrappers.ts | 2 +- integration/simple-long-string/google/protobuf/wrappers.ts | 2 +- integration/simple-long/google/protobuf/wrappers.ts | 2 +- integration/simple-optionals/google/protobuf/wrappers.ts | 2 +- .../simple-prototype-defaults/google/protobuf/wrappers.ts | 2 +- integration/simple-prototype-defaults/simple.ts | 2 +- integration/simple-snake/google/protobuf/wrappers.ts | 2 +- .../simple-unrecognized-enum/google/protobuf/wrappers.ts | 2 +- integration/simple/google/protobuf/wrappers.ts | 2 +- integration/simple/simple.ts | 2 +- integration/use-map-type/use-map-type.ts | 2 +- integration/use-optionals-all/test.ts | 2 +- integration/use-optionals-no-undefined/test.ts | 2 +- integration/value/google/protobuf/wrappers.ts | 2 +- integration/wrappers-regression/google/protobuf/wrappers.ts | 2 +- src/main.ts | 2 +- 25 files changed, 25 insertions(+), 25 deletions(-) diff --git a/integration/before-after-request-streaming/google/protobuf/wrappers.ts b/integration/before-after-request-streaming/google/protobuf/wrappers.ts index 6aa1a51cc..537c9ccfa 100644 --- a/integration/before-after-request-streaming/google/protobuf/wrappers.ts +++ b/integration/before-after-request-streaming/google/protobuf/wrappers.ts @@ -621,7 +621,7 @@ function bytesFromBase64(b64: string): Uint8Array { } function base64FromBytes(arr: Uint8Array): string { - if (globalThis.Buffer) { + if ((globalThis as any).Buffer) { return globalThis.Buffer.from(arr).toString("base64"); } else { const bin: string[] = []; diff --git a/integration/bytes-as-base64/message.ts b/integration/bytes-as-base64/message.ts index 8fd805d0c..6f2f04639 100644 --- a/integration/bytes-as-base64/message.ts +++ b/integration/bytes-as-base64/message.ts @@ -47,7 +47,7 @@ function bytesFromBase64(b64: string): Uint8Array { } function base64FromBytes(arr: Uint8Array): string { - if (globalThis.Buffer) { + if ((globalThis as any).Buffer) { return globalThis.Buffer.from(arr).toString("base64"); } else { const bin: string[] = []; diff --git a/integration/emit-default-values-json/test.ts b/integration/emit-default-values-json/test.ts index 9f1eddf25..e1967795d 100644 --- a/integration/emit-default-values-json/test.ts +++ b/integration/emit-default-values-json/test.ts @@ -702,7 +702,7 @@ function bytesFromBase64(b64: string): Uint8Array { } function base64FromBytes(arr: Uint8Array): string { - if (globalThis.Buffer) { + if ((globalThis as any).Buffer) { return globalThis.Buffer.from(arr).toString("base64"); } else { const bin: string[] = []; diff --git a/integration/grpc-js/google/protobuf/wrappers.ts b/integration/grpc-js/google/protobuf/wrappers.ts index 6aa1a51cc..537c9ccfa 100644 --- a/integration/grpc-js/google/protobuf/wrappers.ts +++ b/integration/grpc-js/google/protobuf/wrappers.ts @@ -621,7 +621,7 @@ function bytesFromBase64(b64: string): Uint8Array { } function base64FromBytes(arr: Uint8Array): string { - if (globalThis.Buffer) { + if ((globalThis as any).Buffer) { return globalThis.Buffer.from(arr).toString("base64"); } else { const bin: string[] = []; diff --git a/integration/grpc-web/google/protobuf/wrappers.ts b/integration/grpc-web/google/protobuf/wrappers.ts index 6aa1a51cc..537c9ccfa 100644 --- a/integration/grpc-web/google/protobuf/wrappers.ts +++ b/integration/grpc-web/google/protobuf/wrappers.ts @@ -621,7 +621,7 @@ function bytesFromBase64(b64: string): Uint8Array { } function base64FromBytes(arr: Uint8Array): string { - if (globalThis.Buffer) { + if ((globalThis as any).Buffer) { return globalThis.Buffer.from(arr).toString("base64"); } else { const bin: string[] = []; diff --git a/integration/nice-grpc/google/protobuf/wrappers.ts b/integration/nice-grpc/google/protobuf/wrappers.ts index 4ccec88e4..6ba74fc40 100644 --- a/integration/nice-grpc/google/protobuf/wrappers.ts +++ b/integration/nice-grpc/google/protobuf/wrappers.ts @@ -621,7 +621,7 @@ function bytesFromBase64(b64: string): Uint8Array { } function base64FromBytes(arr: Uint8Array): string { - if (globalThis.Buffer) { + if ((globalThis as any).Buffer) { return globalThis.Buffer.from(arr).toString("base64"); } else { const bin: string[] = []; diff --git a/integration/oneof-properties/oneof.ts b/integration/oneof-properties/oneof.ts index 0c18d89f1..74d49932c 100644 --- a/integration/oneof-properties/oneof.ts +++ b/integration/oneof-properties/oneof.ts @@ -370,7 +370,7 @@ function bytesFromBase64(b64: string): Uint8Array { } function base64FromBytes(arr: Uint8Array): string { - if (globalThis.Buffer) { + if ((globalThis as any).Buffer) { return globalThis.Buffer.from(arr).toString("base64"); } else { const bin: string[] = []; diff --git a/integration/oneof-unions/oneof.ts b/integration/oneof-unions/oneof.ts index 350ae2922..d0cd92c83 100644 --- a/integration/oneof-unions/oneof.ts +++ b/integration/oneof-unions/oneof.ts @@ -501,7 +501,7 @@ function bytesFromBase64(b64: string): Uint8Array { } function base64FromBytes(arr: Uint8Array): string { - if (globalThis.Buffer) { + if ((globalThis as any).Buffer) { return globalThis.Buffer.from(arr).toString("base64"); } else { const bin: string[] = []; diff --git a/integration/output-toJSON-only/google/protobuf/wrappers.ts b/integration/output-toJSON-only/google/protobuf/wrappers.ts index 3627ad626..20fdbbc1e 100644 --- a/integration/output-toJSON-only/google/protobuf/wrappers.ts +++ b/integration/output-toJSON-only/google/protobuf/wrappers.ts @@ -183,7 +183,7 @@ export const BytesValue = { }; function base64FromBytes(arr: Uint8Array): string { - if (globalThis.Buffer) { + if ((globalThis as any).Buffer) { return globalThis.Buffer.from(arr).toString("base64"); } else { const bin: string[] = []; diff --git a/integration/simple-long-bigint/google/protobuf/wrappers.ts b/integration/simple-long-bigint/google/protobuf/wrappers.ts index b89f02f15..20d4a19d4 100644 --- a/integration/simple-long-bigint/google/protobuf/wrappers.ts +++ b/integration/simple-long-bigint/google/protobuf/wrappers.ts @@ -627,7 +627,7 @@ function bytesFromBase64(b64: string): Uint8Array { } function base64FromBytes(arr: Uint8Array): string { - if (globalThis.Buffer) { + if ((globalThis as any).Buffer) { return globalThis.Buffer.from(arr).toString("base64"); } else { const bin: string[] = []; diff --git a/integration/simple-long-string/google/protobuf/wrappers.ts b/integration/simple-long-string/google/protobuf/wrappers.ts index 881f6fc9e..8c4d9f9a7 100644 --- a/integration/simple-long-string/google/protobuf/wrappers.ts +++ b/integration/simple-long-string/google/protobuf/wrappers.ts @@ -621,7 +621,7 @@ function bytesFromBase64(b64: string): Uint8Array { } function base64FromBytes(arr: Uint8Array): string { - if (globalThis.Buffer) { + if ((globalThis as any).Buffer) { return globalThis.Buffer.from(arr).toString("base64"); } else { const bin: string[] = []; diff --git a/integration/simple-long/google/protobuf/wrappers.ts b/integration/simple-long/google/protobuf/wrappers.ts index 420b56ab2..8061accff 100644 --- a/integration/simple-long/google/protobuf/wrappers.ts +++ b/integration/simple-long/google/protobuf/wrappers.ts @@ -621,7 +621,7 @@ function bytesFromBase64(b64: string): Uint8Array { } function base64FromBytes(arr: Uint8Array): string { - if (globalThis.Buffer) { + if ((globalThis as any).Buffer) { return globalThis.Buffer.from(arr).toString("base64"); } else { const bin: string[] = []; diff --git a/integration/simple-optionals/google/protobuf/wrappers.ts b/integration/simple-optionals/google/protobuf/wrappers.ts index 6aa1a51cc..537c9ccfa 100644 --- a/integration/simple-optionals/google/protobuf/wrappers.ts +++ b/integration/simple-optionals/google/protobuf/wrappers.ts @@ -621,7 +621,7 @@ function bytesFromBase64(b64: string): Uint8Array { } function base64FromBytes(arr: Uint8Array): string { - if (globalThis.Buffer) { + if ((globalThis as any).Buffer) { return globalThis.Buffer.from(arr).toString("base64"); } else { const bin: string[] = []; diff --git a/integration/simple-prototype-defaults/google/protobuf/wrappers.ts b/integration/simple-prototype-defaults/google/protobuf/wrappers.ts index e60727dd1..69d9f9e8c 100644 --- a/integration/simple-prototype-defaults/google/protobuf/wrappers.ts +++ b/integration/simple-prototype-defaults/google/protobuf/wrappers.ts @@ -621,7 +621,7 @@ function bytesFromBase64(b64: string): Uint8Array { } function base64FromBytes(arr: Uint8Array): string { - if (globalThis.Buffer) { + if ((globalThis as any).Buffer) { return globalThis.Buffer.from(arr).toString("base64"); } else { const bin: string[] = []; diff --git a/integration/simple-prototype-defaults/simple.ts b/integration/simple-prototype-defaults/simple.ts index bd2662386..63b9e737e 100644 --- a/integration/simple-prototype-defaults/simple.ts +++ b/integration/simple-prototype-defaults/simple.ts @@ -2926,7 +2926,7 @@ function bytesFromBase64(b64: string): Uint8Array { } function base64FromBytes(arr: Uint8Array): string { - if (globalThis.Buffer) { + if ((globalThis as any).Buffer) { return globalThis.Buffer.from(arr).toString("base64"); } else { const bin: string[] = []; diff --git a/integration/simple-snake/google/protobuf/wrappers.ts b/integration/simple-snake/google/protobuf/wrappers.ts index 6aa1a51cc..537c9ccfa 100644 --- a/integration/simple-snake/google/protobuf/wrappers.ts +++ b/integration/simple-snake/google/protobuf/wrappers.ts @@ -621,7 +621,7 @@ function bytesFromBase64(b64: string): Uint8Array { } function base64FromBytes(arr: Uint8Array): string { - if (globalThis.Buffer) { + if ((globalThis as any).Buffer) { return globalThis.Buffer.from(arr).toString("base64"); } else { const bin: string[] = []; diff --git a/integration/simple-unrecognized-enum/google/protobuf/wrappers.ts b/integration/simple-unrecognized-enum/google/protobuf/wrappers.ts index 6aa1a51cc..537c9ccfa 100644 --- a/integration/simple-unrecognized-enum/google/protobuf/wrappers.ts +++ b/integration/simple-unrecognized-enum/google/protobuf/wrappers.ts @@ -621,7 +621,7 @@ function bytesFromBase64(b64: string): Uint8Array { } function base64FromBytes(arr: Uint8Array): string { - if (globalThis.Buffer) { + if ((globalThis as any).Buffer) { return globalThis.Buffer.from(arr).toString("base64"); } else { const bin: string[] = []; diff --git a/integration/simple/google/protobuf/wrappers.ts b/integration/simple/google/protobuf/wrappers.ts index 6aa1a51cc..537c9ccfa 100644 --- a/integration/simple/google/protobuf/wrappers.ts +++ b/integration/simple/google/protobuf/wrappers.ts @@ -621,7 +621,7 @@ function bytesFromBase64(b64: string): Uint8Array { } function base64FromBytes(arr: Uint8Array): string { - if (globalThis.Buffer) { + if ((globalThis as any).Buffer) { return globalThis.Buffer.from(arr).toString("base64"); } else { const bin: string[] = []; diff --git a/integration/simple/simple.ts b/integration/simple/simple.ts index 3767cbce8..49cb0be3f 100644 --- a/integration/simple/simple.ts +++ b/integration/simple/simple.ts @@ -3048,7 +3048,7 @@ function bytesFromBase64(b64: string): Uint8Array { } function base64FromBytes(arr: Uint8Array): string { - if (globalThis.Buffer) { + if ((globalThis as any).Buffer) { return globalThis.Buffer.from(arr).toString("base64"); } else { const bin: string[] = []; diff --git a/integration/use-map-type/use-map-type.ts b/integration/use-map-type/use-map-type.ts index 1547d9e08..314d8d37b 100644 --- a/integration/use-map-type/use-map-type.ts +++ b/integration/use-map-type/use-map-type.ts @@ -723,7 +723,7 @@ function bytesFromBase64(b64: string): Uint8Array { } function base64FromBytes(arr: Uint8Array): string { - if (globalThis.Buffer) { + if ((globalThis as any).Buffer) { return globalThis.Buffer.from(arr).toString("base64"); } else { const bin: string[] = []; diff --git a/integration/use-optionals-all/test.ts b/integration/use-optionals-all/test.ts index d1279d8e5..7e16d0f62 100644 --- a/integration/use-optionals-all/test.ts +++ b/integration/use-optionals-all/test.ts @@ -714,7 +714,7 @@ function bytesFromBase64(b64: string): Uint8Array { } function base64FromBytes(arr: Uint8Array): string { - if (globalThis.Buffer) { + if ((globalThis as any).Buffer) { return globalThis.Buffer.from(arr).toString("base64"); } else { const bin: string[] = []; diff --git a/integration/use-optionals-no-undefined/test.ts b/integration/use-optionals-no-undefined/test.ts index 3384fc3a7..20125b5ba 100644 --- a/integration/use-optionals-no-undefined/test.ts +++ b/integration/use-optionals-no-undefined/test.ts @@ -716,7 +716,7 @@ function bytesFromBase64(b64: string): Uint8Array { } function base64FromBytes(arr: Uint8Array): string { - if (globalThis.Buffer) { + if ((globalThis as any).Buffer) { return globalThis.Buffer.from(arr).toString("base64"); } else { const bin: string[] = []; diff --git a/integration/value/google/protobuf/wrappers.ts b/integration/value/google/protobuf/wrappers.ts index 6aa1a51cc..537c9ccfa 100644 --- a/integration/value/google/protobuf/wrappers.ts +++ b/integration/value/google/protobuf/wrappers.ts @@ -621,7 +621,7 @@ function bytesFromBase64(b64: string): Uint8Array { } function base64FromBytes(arr: Uint8Array): string { - if (globalThis.Buffer) { + if ((globalThis as any).Buffer) { return globalThis.Buffer.from(arr).toString("base64"); } else { const bin: string[] = []; diff --git a/integration/wrappers-regression/google/protobuf/wrappers.ts b/integration/wrappers-regression/google/protobuf/wrappers.ts index 6aa1a51cc..537c9ccfa 100644 --- a/integration/wrappers-regression/google/protobuf/wrappers.ts +++ b/integration/wrappers-regression/google/protobuf/wrappers.ts @@ -621,7 +621,7 @@ function bytesFromBase64(b64: string): Uint8Array { } function base64FromBytes(arr: Uint8Array): string { - if (globalThis.Buffer) { + if ((globalThis as any).Buffer) { return globalThis.Buffer.from(arr).toString("base64"); } else { const bin: string[] = []; diff --git a/src/main.ts b/src/main.ts index c199528b2..46a0cb765 100644 --- a/src/main.ts +++ b/src/main.ts @@ -609,7 +609,7 @@ function makeByteUtils(options: Options) { return base64FromBytesBrowserSnippet; default: return code` - if (${globalThis}.Buffer) { + if ((${globalThis} as any).Buffer) { ${base64FromBytesNodeSnippet} } else { ${base64FromBytesBrowserSnippet}