Bladeren bron

core: remove more IE hacks (#3015)

We can now use `Object.fromEntries`, `Object.values`, and `Symbol`.
Also changes polyfill suggestion for legacy browsers to use `core-js`
which includes almost all we need and more.
Antoine du Hamel 3 jaren geleden
bovenliggende
commit
d40b5241db

+ 2 - 6
README.md

@@ -175,18 +175,14 @@ Here's a list of polyfills you'll need to include to make Uppy work in older bro
 If you're using a bundler, you need import them before Uppy:
 
 ```js
-import 'es6-promise/auto'
+import 'core-js'
 import 'whatwg-fetch'
 import 'abortcontroller-polyfill/dist/polyfill-patch-fetch'
-// Order matters: AbortController needs fetch which needs Promise.
+// Order matters: AbortController needs fetch which needs Promise (provided by core-js).
 
-import mathLog2 from 'math-log2'
 import 'md-gum-polyfill'
 import ResizeObserver from 'resize-observer-polyfill'
-import 'symbol-es6'
-import 'url-polyfill'
 
-Math.log2 ??= mathLog2
 window.ResizeObserver ??= ResizeObserver
 
 export { default } from '@uppy/core'

+ 1 - 4
bin/locale-packs.js

@@ -154,10 +154,7 @@ function checkForUnused (fileContents, pluginName, localePack) {
 }
 
 function sortObjectAlphabetically (obj, sortFunc) {
-  return Object.keys(obj).sort(sortFunc).reduce((result, key) => {
-    result[key] = obj[key]
-    return result
-  }, {})
+  return Object.fromEntries(Object.keys(obj).sort(sortFunc).map((key) => [key, obj[key]]))
 }
 
 function createTypeScriptLocale (plugin, pluginName) {

File diff suppressed because it is too large
+ 61 - 486
package-lock.json


+ 1 - 4
package.json

@@ -66,10 +66,10 @@
     "chai": "^4.2.0",
     "chalk": "^4.1.1",
     "concat-stream": "^2.0.0",
+    "core-js": "^3.15.2",
     "cssnano": "^5.0.6",
     "deep-freeze": "^0.0.1",
     "disc": "^1.3.3",
-    "es6-promise": "^4.2.8",
     "eslint": "^7.22.0",
     "eslint-config-transloadit": "^1.2.0",
     "eslint-import-resolver-lerna": "^2.0.0",
@@ -96,7 +96,6 @@
     "last-commit-message": "^1.0.0",
     "lerna": "^4.0.0",
     "lint-staged": "^11.0.0",
-    "math-log2": "^2.0.0",
     "md-gum-polyfill": "^1.0.0",
     "mime-types": "^2.1.26",
     "minify-stream": "^2.0.1",
@@ -121,7 +120,6 @@
     "sass": "^1.29.0",
     "size-limit": "4.5.6",
     "stringify-object": "^3.3.0",
-    "symbol-es6": "^0.1.2",
     "tar": "^6.1.0",
     "temp-write": "^5.0.0",
     "terser": "^5.7.0",
@@ -130,7 +128,6 @@
     "tsify": "^5.0.1",
     "tus-node-server": "^0.3.2",
     "typescript": "~4.3",
-    "url-polyfill": "^1.1.12",
     "verdaccio": "^5.1.1",
     "watchify": "^4.0.0",
     "webdriverio": "^7.7.4",

+ 1 - 2
packages/@uppy/core/src/index.js

@@ -1696,8 +1696,7 @@ class Uppy {
       .then(() => {
         const { currentUploads } = this.getState()
         // get a list of files that are currently assigned to uploads
-        const currentlyUploadingFiles = Object.keys(currentUploads)
-          .reduce((prev, curr) => prev.concat(currentUploads[curr].fileIDs), [])
+        const currentlyUploadingFiles = Object.values(currentUploads).flatMap(curr => curr.fileIDs)
 
         const waitingFileIDs = []
         Object.keys(files).forEach((fileID) => {

+ 1 - 8
packages/@uppy/react/src/getHTMLProps.js

@@ -149,16 +149,9 @@ const possibleStandardNames = [
   'wrap',
 ]
 
-// A decent polyfill for Object.entries for good browser support
-const getEntries = (object) => {
-  // eslint-disable-next-line compat/compat
-  return Object.entries ? Object.entries(object) : Object.keys(object).map(key => [key, object[key]])
-}
-
 const getHTMLProps = (props) => {
   // Gets all the React props
-  const reducer = (acc, [key, value]) => (possibleStandardNames.includes(key) ? { ...acc, [key]: value } : acc)
-  return getEntries(props).reduce(reducer, {})
+  return Object.fromEntries(Object.entries(props).filter(([key]) => possibleStandardNames.includes(key)))
 }
 
 module.exports = getHTMLProps

+ 1 - 5
packages/@uppy/robodog/bundle.js

@@ -1,15 +1,11 @@
-require('es6-promise/auto')
+require('core-js')
 require('whatwg-fetch')
 require('abortcontroller-polyfill/dist/polyfill-patch-fetch')
 // Order matters: AbortController needs fetch which needs Promise.
 
-const mathLog2 = require('math-log2')
 require('md-gum-polyfill')
 const ResizeObserver = require('resize-observer-polyfill')
-require('symbol-es6')
-require('url-polyfill')
 
-if (typeof Math.log2 !== 'function') Math.log2 = mathLog2
 if (typeof window.ResizeObserver !== 'function') window.ResizeObserver = ResizeObserver
 
 module.exports = require('.')

+ 1 - 4
packages/@uppy/transloadit/src/index.js

@@ -407,10 +407,7 @@ module.exports = class Transloadit extends BasePlugin {
   _onCancelAll () {
     const { uploadsAssemblies } = this.getPluginState()
 
-    const assemblyIDs = Object.keys(uploadsAssemblies).reduce((acc, uploadID) => {
-      acc.push(...uploadsAssemblies[uploadID])
-      return acc
-    }, [])
+    const assemblyIDs = Object.values(uploadsAssemblies)
 
     const cancelPromises = assemblyIDs.map((assemblyID) => {
       const assembly = this.getAssembly(assemblyID)

+ 2 - 3
packages/@uppy/utils/src/Translator.js

@@ -55,7 +55,6 @@ module.exports = class Translator {
    * @returns {any[]} interpolated
    */
   interpolate (phrase, options) {
-    const { split, replace } = String.prototype
     const dollarRegex = /\$/g
     const dollarBillsYall = '$$$$'
     let interpolated = [phrase]
@@ -67,7 +66,7 @@ module.exports = class Translator {
         // be escaped with "$" itself, and we need two in the resulting output.
         var replacement = options[arg]
         if (typeof replacement === 'string') {
-          replacement = replace.call(options[arg], dollarRegex, dollarBillsYall)
+          replacement = dollarRegex[Symbol.replace](replacement, dollarBillsYall)
         }
         // We create a new `RegExp` each time instead of using a more-efficient
         // string replace so that the same argument can be replaced multiple times
@@ -89,7 +88,7 @@ module.exports = class Translator {
           return newParts.push(chunk)
         }
 
-        split.call(chunk, rx).forEach((raw, i, list) => {
+        rx[Symbol.split](chunk).forEach((raw, i, list) => {
           if (raw !== '') {
             newParts.push(raw)
           }

+ 1 - 5
packages/uppy/bundle.js

@@ -1,15 +1,11 @@
-require('es6-promise/auto')
+require('core-js')
 require('whatwg-fetch')
 require('abortcontroller-polyfill/dist/polyfill-patch-fetch')
 // Order matters: AbortController needs fetch which needs Promise.
 
-const mathLog2 = require('math-log2')
 require('md-gum-polyfill')
 const ResizeObserver = require('resize-observer-polyfill')
-require('symbol-es6')
-require('url-polyfill')
 
-if (typeof Math.log2 !== 'function') Math.log2 = mathLog2
 if (typeof window.ResizeObserver !== 'function') window.ResizeObserver = ResizeObserver
 
 module.exports = require('.')

+ 1 - 5
website/src/_posts/2021-XX-XX.md

@@ -26,18 +26,14 @@ to make it work:
 If you're using a bundler, you need import them before Uppy:
 
 ```js
-import 'es6-promise/auto'
+import 'core-js'
 import 'whatwg-fetch'
 import 'abortcontroller-polyfill/dist/polyfill-patch-fetch'
 // Order matters: AbortController needs fetch which needs Promise.
 
-import mathLog2 from 'math-log2'
 import 'md-gum-polyfill'
 import ResizeObserver from 'resize-observer-polyfill'
-import 'symbol-es6'
-import 'url-polyfill'
 
-Math.log2 ??= mathLog2
 window.ResizeObserver ??= ResizeObserver
 
 export { default } from '@uppy/core'

Some files were not shown because too many files changed in this diff