diff --git a/modules/polyfills/src/index.browser.ts b/modules/polyfills/src/index.browser.ts index ee02ee0930..8f0cfe4d9f 100644 --- a/modules/polyfills/src/index.browser.ts +++ b/modules/polyfills/src/index.browser.ts @@ -1,12 +1,5 @@ // loaders.gl, MIT License -import {allSettled} from './promise/all-settled'; - -if (!('allSettled' in Promise)) { - // @ts-ignore - Promise.allSettled = allSettled; -} - // eslint-disable-next-line @typescript-eslint/no-empty-function export function installFilePolyfills() {} diff --git a/modules/polyfills/src/index.ts b/modules/polyfills/src/index.ts index db71f3ad2e..a7f23ab37d 100644 --- a/modules/polyfills/src/index.ts +++ b/modules/polyfills/src/index.ts @@ -1,8 +1,7 @@ /* eslint-disable dot-notation */ -import {isBrowser} from './utils/globals'; +import {isBrowser} from './utils/is-browser'; import {TextDecoder, TextEncoder} from './lib/encoding'; -import {allSettled} from './promise/all-settled'; // Node specific import * as base64 from './node/buffer/btoa.node'; @@ -68,11 +67,6 @@ if (!isBrowser && !('_parseImageNode' in globalThis) && parseImageNode) { globalThis['_imageFormatsNode'] = NODE_FORMAT_SUPPORT; } -if (!('allSettled' in Promise)) { - // @ts-ignore - Promise.allSettled = allSettled; -} - // DEPRECATED POLYFILL: // - Node v18+: No, not needed // - Node v16 and lower: Yes diff --git a/modules/polyfills/src/promise/all-settled.ts b/modules/polyfills/src/promise/all-settled.ts deleted file mode 100644 index a2a12a9c72..0000000000 --- a/modules/polyfills/src/promise/all-settled.ts +++ /dev/null @@ -1,21 +0,0 @@ -export const REJECTED_STATUS = 'rejected'; -export const FULFILLED_STATUS = 'fulfilled'; - -/** - * Handle list of promises and return all values regardless of results. - * Polyfill for Promise.allSettled() method. - * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled - * @param promises - */ -export function allSettled(promises: Promise[]): Promise { - const mappedPromises = promises.map((promise) => { - return promise - .then((value) => { - return {status: FULFILLED_STATUS, value}; - }) - .catch((reason) => { - return {status: REJECTED_STATUS, reason}; - }); - }); - return Promise.all(mappedPromises); -} diff --git a/modules/polyfills/src/utils/globals.ts b/modules/polyfills/src/utils/globals.ts deleted file mode 100644 index a37f569cf7..0000000000 --- a/modules/polyfills/src/utils/globals.ts +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) 2015 - 2017 Uber Technologies, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -// Purpose: include this in your module to avoids adding dependencies on -// micro modules like 'global' and 'is-browser'; - -/* eslint-disable no-restricted-globals */ -const isBrowser: boolean = - // @ts-ignore process.browser - typeof process !== 'object' || String(process) !== '[object process]' || process.browser; - -const globals = { - self: typeof self !== 'undefined' && self, - window: typeof window !== 'undefined' && window, - global: typeof global !== 'undefined' && global -}; - -const global_: object = (globals.global || globals.self || globals.window) as object; - -export {isBrowser, global_ as global}; diff --git a/modules/polyfills/src/utils/is-browser.ts b/modules/polyfills/src/utils/is-browser.ts new file mode 100644 index 0000000000..4e3a721fd9 --- /dev/null +++ b/modules/polyfills/src/utils/is-browser.ts @@ -0,0 +1,6 @@ +// loaders.gl, MIT license + +/* eslint-disable no-restricted-globals */ +export const isBrowser: boolean = + // @ts-ignore process.browser + typeof process !== 'object' || String(process) !== '[object process]' || process.browser; diff --git a/modules/polyfills/test/images-node/images-node.spec.js b/modules/polyfills/test/images-node/images-node.spec.js index 8db7ef965c..1d89ba48af 100644 --- a/modules/polyfills/test/images-node/images-node.spec.js +++ b/modules/polyfills/test/images-node/images-node.spec.js @@ -1,8 +1,7 @@ /* eslint-disable max-len */ import test from 'tape-promise/tape'; import '@loaders.gl/polyfills'; -import {isBrowser} from '../../src/utils/globals'; -import {fetchFile} from '@loaders.gl/core'; +import {isBrowser, fetchFile} from '@loaders.gl/core'; import {parseImageNode} from '../../src/node/images/parse-image.node'; const images = [