From 0a076d5552b490c9b7d7f5d9c172b3862f993dea Mon Sep 17 00:00:00 2001 From: Jack Works Date: Fri, 4 Mar 2022 12:39:23 +0800 Subject: [PATCH 1/4] chore: upgrade to iOS 14 --- packages/.eslintrc.json | 1 - packages/mask/.webpack/config.ts | 2 +- packages/polyfills/README.md | 19 +++++++++-------- packages/polyfills/builder.mjs | 2 +- .../web-apis/implementation/.gitkeep | 0 .../Blob.prototype.arrayBuffer.ts | 21 ------------------- .../implementation/EventTarget.constructor.ts | 20 ------------------ packages/polyfills/web-apis/worker.ts | 3 +-- packages/web3-kit/src/types.ts | 3 +-- packages/web3-shared/evm/types/index.ts | 3 +-- 10 files changed, 15 insertions(+), 59 deletions(-) create mode 100644 packages/polyfills/web-apis/implementation/.gitkeep delete mode 100644 packages/polyfills/web-apis/implementation/Blob.prototype.arrayBuffer.ts delete mode 100644 packages/polyfills/web-apis/implementation/EventTarget.constructor.ts diff --git a/packages/.eslintrc.json b/packages/.eslintrc.json index 9d32584cedf7..5f952dca7275 100644 --- a/packages/.eslintrc.json +++ b/packages/.eslintrc.json @@ -66,7 +66,6 @@ "unicorn/relative-url-style": ["error", "always"], "unicorn/throw-new-error": "error", "unused-imports/no-unused-imports-ts": "error", - "@dimensiondev/no-bigint": "error", "@dimensiondev/no-jsx-template-literal": "error", "@dimensiondev/no-locale-case": "error", "@dimensiondev/no-number-constructor": "off", diff --git a/packages/mask/.webpack/config.ts b/packages/mask/.webpack/config.ts index cdf0bc8b92c6..a08295222c58 100644 --- a/packages/mask/.webpack/config.ts +++ b/packages/mask/.webpack/config.ts @@ -240,7 +240,7 @@ export function createConfiguration(rawFlags: BuildFlags): Configuration { destructuring: true, forOf: true, module: false, - bigIntLiteral: false, + bigIntLiteral: true, // Our iOS App doesn't support dynamic import (it requires a heavy post-build time transform). dynamicImport: !(runtime.architecture === 'app' && runtime.engine === 'safari'), }, diff --git a/packages/polyfills/README.md b/packages/polyfills/README.md index 2600d4fe3bde..b7f4df4117db 100644 --- a/packages/polyfills/README.md +++ b/packages/polyfills/README.md @@ -13,26 +13,28 @@ Extra: ## Supporting browsers -- Safari 13.4+ (Released on Sept 2019) -- Chrome Last 2 versions (about 3 months) (91+ at 7/23/2021) -- Firefox Last 2 versions (about 3 months) (97+ at 7/23/2021) +- Safari 14+ (Released on Sept 2020) +- Chrome Last 2 versions (about 3 months) (98+ at 3/4/2022) +- Firefox Last 2 versions (about 3 months) (97+ at 3/4/2022) - GeckoView 91 (last updated at 7/23/2021). ## ES Syntax and APIs We're targeting syntax and libraries to ES2020. -Fell free to add polyfill (or install it from npm). -For proposals, stage 2 or higher can be considered. - ### Caution +Those features are not easy to polyfill. + - ES2017: SharedArrayBuffer and Atomics - ES2018: - (Syntax) RegExp Lookbehind Assertions (Safari not supported) -- ES2020: BigInt (requires Safari 15) +- ES2020: + - BigInt64Array (requires Safari 15) + - BigUint64Array (requires Safari 15) + - DataView.prototype.getBigInt64 (requires Safari 15) + - DataView.prototype.getBigUint64 (requires Safari 15) - ES2021: - WeakReference (requires Safari 15) - - (Syntax) Logical Assignment (requires Safari 14) - ES2022: - ⭐ C l a s s ⭐ F i e l d s ⭐ (requires Safari 15) - Class initialization block (Safari not supported, Firefox 93+) @@ -44,7 +46,6 @@ Check and polyfill before using. ### Simply polyfilled - Intl.ListFormat -- EventTarget.constructor (requires Safari 14) ### Using polyfill diff --git a/packages/polyfills/builder.mjs b/packages/polyfills/builder.mjs index ebb3a362af3e..813106c73bfd 100644 --- a/packages/polyfills/builder.mjs +++ b/packages/polyfills/builder.mjs @@ -29,7 +29,7 @@ if ((await readFile(versionFilePath, 'utf-8').catch(() => '')) === polyfillVersi await builder({ modules: ['es', 'web'], targets: [ - 'iOS >= 13.4', + 'iOS >= 14.0', // Android 'Firefox >= 91', 'last 2 Chrome versions', diff --git a/packages/polyfills/web-apis/implementation/.gitkeep b/packages/polyfills/web-apis/implementation/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/polyfills/web-apis/implementation/Blob.prototype.arrayBuffer.ts b/packages/polyfills/web-apis/implementation/Blob.prototype.arrayBuffer.ts deleted file mode 100644 index 1eb09f908f40..000000000000 --- a/packages/polyfills/web-apis/implementation/Blob.prototype.arrayBuffer.ts +++ /dev/null @@ -1,21 +0,0 @@ -// Remove this file after iOS 14- is dropped. -try { - if (typeof Blob === 'function') { - if (!Blob.prototype.arrayBuffer) shim() - } - function shim() { - // FileReader is not available in Worker on Safari - if (typeof FileReader === 'undefined') throw new Error('FileReader is undefined') - Blob.prototype.arrayBuffer = function () { - return new Promise((resolve, reject) => { - const reader = new FileReader() - reader.addEventListener('load', () => resolve(reader.result as ArrayBuffer)) - reader.addEventListener('error', () => reject(reader.error)) - reader.readAsArrayBuffer(this) - }) - } - } -} catch (err) { - console.warn('Failed to polyfill Blob.prototype.arrayBuffer:', err) -} -export {} diff --git a/packages/polyfills/web-apis/implementation/EventTarget.constructor.ts b/packages/polyfills/web-apis/implementation/EventTarget.constructor.ts deleted file mode 100644 index 18f89d31101c..000000000000 --- a/packages/polyfills/web-apis/implementation/EventTarget.constructor.ts +++ /dev/null @@ -1,20 +0,0 @@ -// Remove this file after iOS 14- is dropped. -try { - if (typeof globalThis.EventTarget?.call === 'function') { - try { - new EventTarget() - } catch { - shim() - } - } - function shim() { - globalThis.EventTarget = new Proxy(EventTarget, { - construct() { - return new AbortController().signal - }, - }) - } -} catch (err) { - console.warn('Failed to polyfill EventTarget.constructor:', err) -} -export {} diff --git a/packages/polyfills/web-apis/worker.ts b/packages/polyfills/web-apis/worker.ts index f36db668bfec..693da49fc40b 100644 --- a/packages/polyfills/web-apis/worker.ts +++ b/packages/polyfills/web-apis/worker.ts @@ -1,2 +1 @@ -import './implementation/EventTarget.constructor' -import './implementation/Blob.prototype.arrayBuffer' +export {} \ No newline at end of file diff --git a/packages/web3-kit/src/types.ts b/packages/web3-kit/src/types.ts index e190a7b90b77..9c6b1781de93 100644 --- a/packages/web3-kit/src/types.ts +++ b/packages/web3-kit/src/types.ts @@ -1,2 +1 @@ -// bigint is not in our list. iOS doesn't support that. -export type Primitive = string | number | boolean | symbol | undefined | null +export type Primitive = string | number | boolean | symbol | undefined | null | bigint diff --git a/packages/web3-shared/evm/types/index.ts b/packages/web3-shared/evm/types/index.ts index a9fa573f9b0b..7840867421cc 100644 --- a/packages/web3-shared/evm/types/index.ts +++ b/packages/web3-shared/evm/types/index.ts @@ -26,8 +26,7 @@ export interface CryptoPrice { export type ChainIdOptionalRecord = { [k in ChainId]?: T } export type ChainIdRecord = { [k in ChainId]: T } -// bigint is not in our list. iOS doesn't support that. -export type Primitive = string | number | boolean | symbol | undefined | null +export type Primitive = string | number | boolean | symbol | undefined | null | bigint export type Web3Constants = Record From 403fd2957b1fb9d721ab85cbe25b2ad8ce4b0fb2 Mon Sep 17 00:00:00 2001 From: Jack Works Date: Fri, 4 Mar 2022 12:41:27 +0800 Subject: [PATCH 2/4] chore: upgrade to iOS 14 --- packages/polyfills/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/polyfills/README.md b/packages/polyfills/README.md index b7f4df4117db..d47c7c7105a0 100644 --- a/packages/polyfills/README.md +++ b/packages/polyfills/README.md @@ -18,9 +18,10 @@ Extra: - Firefox Last 2 versions (about 3 months) (97+ at 3/4/2022) - GeckoView 91 (last updated at 7/23/2021). -## ES Syntax and APIs +## Targeting ES Syntax and APIs -We're targeting syntax and libraries to ES2020. +- Syntax: ES2020 +- Library: ES2022 (with [core-js](https://github.com/zloirock/core-js)). ### Caution From e5dec49d9499e706f8a5dea513d1f50c0d751a12 Mon Sep 17 00:00:00 2001 From: Jack Works Date: Fri, 4 Mar 2022 12:42:03 +0800 Subject: [PATCH 3/4] chore: upgrade to iOS 14 --- packages/polyfills/web-apis/worker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/polyfills/web-apis/worker.ts b/packages/polyfills/web-apis/worker.ts index 693da49fc40b..336ce12bb910 100644 --- a/packages/polyfills/web-apis/worker.ts +++ b/packages/polyfills/web-apis/worker.ts @@ -1 +1 @@ -export {} \ No newline at end of file +export {} From d3a653f42a2afb737c12c8b5f5fe05f7f03a6af5 Mon Sep 17 00:00:00 2001 From: Jack Works Date: Fri, 4 Mar 2022 12:45:42 +0800 Subject: [PATCH 4/4] chore: upgrade to iOS 14 --- packages/polyfills/builder.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/polyfills/builder.mjs b/packages/polyfills/builder.mjs index 813106c73bfd..afc8ace7001e 100644 --- a/packages/polyfills/builder.mjs +++ b/packages/polyfills/builder.mjs @@ -20,7 +20,7 @@ let polyfillVersion = '__' const lockfile = await readFile(lockfilePath) const hash = createHash('sha256') hash.update(lockfile) - polyfillVersion = 'v3' + hash.digest('hex') + polyfillVersion = 'v4' + hash.digest('hex') } const versionFilePath = fileURLToPath(new URL('./dist/version.txt', import.meta.url))