From 2e6ea7c4f283d0e0e9bda1c50c38d7886be2d9dc Mon Sep 17 00:00:00 2001 From: Aleksandr Grenishin Date: Mon, 1 May 2023 17:50:41 +0300 Subject: [PATCH] chore(upload-client): do not use buffer for browser-like bundles to prevent polyfilling by cdn (#484) --- packages/upload-client/src/tools/isBuffer.browser.ts | 1 + packages/upload-client/src/tools/isBuffer.node.ts | 2 ++ .../upload-client/src/tools/isBuffer.react-native.ts | 1 + packages/upload-client/src/tools/isFileData.ts | 9 ++++----- 4 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 packages/upload-client/src/tools/isBuffer.browser.ts create mode 100644 packages/upload-client/src/tools/isBuffer.node.ts create mode 100644 packages/upload-client/src/tools/isBuffer.react-native.ts diff --git a/packages/upload-client/src/tools/isBuffer.browser.ts b/packages/upload-client/src/tools/isBuffer.browser.ts new file mode 100644 index 000000000..411c46577 --- /dev/null +++ b/packages/upload-client/src/tools/isBuffer.browser.ts @@ -0,0 +1 @@ +export const isBuffer = (data: unknown): data is Buffer => false diff --git a/packages/upload-client/src/tools/isBuffer.node.ts b/packages/upload-client/src/tools/isBuffer.node.ts new file mode 100644 index 000000000..fbd397a57 --- /dev/null +++ b/packages/upload-client/src/tools/isBuffer.node.ts @@ -0,0 +1,2 @@ +export const isBuffer = (data: unknown): data is Buffer => + data instanceof Buffer diff --git a/packages/upload-client/src/tools/isBuffer.react-native.ts b/packages/upload-client/src/tools/isBuffer.react-native.ts new file mode 100644 index 000000000..411c46577 --- /dev/null +++ b/packages/upload-client/src/tools/isBuffer.react-native.ts @@ -0,0 +1 @@ +export const isBuffer = (data: unknown): data is Buffer => false diff --git a/packages/upload-client/src/tools/isFileData.ts b/packages/upload-client/src/tools/isFileData.ts index c9b1f015e..6ceafc7cd 100644 --- a/packages/upload-client/src/tools/isFileData.ts +++ b/packages/upload-client/src/tools/isFileData.ts @@ -1,4 +1,7 @@ -import { SupportedFileInput, ReactNativeAsset } from '../types' +import { ReactNativeAsset, SupportedFileInput } from '../types' +import { isBuffer } from './isBuffer.node' + +export { isBuffer } export const isBlob = (data: unknown): data is Blob => { return typeof Blob !== 'undefined' && data instanceof Blob @@ -8,10 +11,6 @@ export const isFile = (data: unknown): data is File => { return typeof File !== 'undefined' && data instanceof File } -export const isBuffer = (data: unknown): data is Buffer => { - return typeof Buffer !== 'undefined' && data instanceof Buffer -} - export const isReactNativeAsset = (data: unknown): data is ReactNativeAsset => { return ( !!data &&