Просмотр исходного кода

Update eslint-plugin-compat and eslint-plugin-jest

Renée Kooi 6 лет назад
Родитель
Сommit
3b1d5b933f

+ 1 - 1
packages/@uppy/dashboard/src/index.js

@@ -319,7 +319,7 @@ module.exports = class Dashboard extends Plugin {
   openModal () {
     const { promise, resolve } = createPromise()
     // save scroll position
-    this.savedScrollPosition = window.scrollY
+    this.savedScrollPosition = window.pageYOffset
     // save active element, so we can restore focus when modal is closed
     this.savedActiveElement = document.activeElement
 

+ 9 - 1
packages/@uppy/provider-views/src/index.js

@@ -16,6 +16,14 @@ function findIndex (array, predicate) {
   return -1
 }
 
+// location.origin does not exist in IE
+function getOrigin () {
+  if ('origin' in location) {
+    return location.origin // eslint-disable-line compat/compat
+  }
+  return `${location.protocol}//${location.hostname}${location.port ? `:${location.port}` : ''}`
+}
+
 class CloseWrapper extends Component {
   componentWillUnmount () {
     this.props.onUnmount()
@@ -410,7 +418,7 @@ module.exports = class ProviderView {
   }
 
   handleAuth () {
-    const authState = btoa(JSON.stringify({ origin: location.origin }))
+    const authState = btoa(JSON.stringify({ origin: getOrigin() }))
     // @todo remove this hardcoded version
     const clientVersion = 'companion-client:1.0.2'
     const link = `${this.provider.authUrl()}?state=${authState}&uppyVersions=${clientVersion}`

+ 5 - 0
packages/@uppy/thumbnail-generator/src/index.js

@@ -190,6 +190,11 @@ module.exports = class ThumbnailGenerator extends Plugin {
     }
     return Promise.resolve().then(() => {
       return dataURItoBlob(canvas.toDataURL(type, quality), {})
+    }).then((blob) => {
+      if (blob === null) {
+        throw new Error('could not extract blob, probably an old browser')
+      }
+      return blob
     })
   }
 

+ 14 - 7
packages/@uppy/utils/src/dataURItoBlob.js

@@ -1,25 +1,32 @@
 module.exports = function dataURItoBlob (dataURI, opts, toFile) {
   // get the base64 data
-  var data = dataURI.split(',')[1]
+  const data = dataURI.split(',')[1]
 
   // user may provide mime type, if not get it from data URI
-  var mimeType = opts.mimeType || dataURI.split(',')[0].split(':')[1].split(';')[0]
+  let mimeType = opts.mimeType || dataURI.split(',')[0].split(':')[1].split(';')[0]
 
   // default to plain/text if data URI has no mimeType
   if (mimeType == null) {
     mimeType = 'plain/text'
   }
 
-  var binary = atob(data)
-  var array = []
-  for (var i = 0; i < binary.length; i++) {
+  const binary = atob(data)
+  const array = []
+  for (let i = 0; i < binary.length; i++) {
     array.push(binary.charCodeAt(i))
   }
 
+  let bytes
+  try {
+    bytes = new Uint8Array(array) // eslint-disable-line compat/compat
+  } catch (err) {
+    return null
+  }
+
   // Convert to a File?
   if (toFile) {
-    return new File([new Uint8Array(array)], opts.name || '', { type: mimeType })
+    return new File([bytes], opts.name || '', { type: mimeType })
   }
 
-  return new Blob([new Uint8Array(array)], { type: mimeType })
+  return new Blob([bytes], { type: mimeType })
 }

+ 8 - 2
packages/@uppy/utils/src/isTouchDevice.js

@@ -1,4 +1,10 @@
 module.exports = function isTouchDevice () {
-  return 'ontouchstart' in window || // works on most browsers
-          navigator.maxTouchPoints // works on IE10/11 and Surface
+  // works on most browsers
+  if ('ontouchstart' in window) {
+    return true
+  }
+
+  // works on IE10/11 and Surface
+  // eslint-disable-next-line compat/compat
+  return !!navigator.maxTouchPoints
 }

+ 2 - 0
packages/@uppy/webcam/src/index.js

@@ -11,7 +11,9 @@ const PermissionsScreen = require('./PermissionsScreen')
 // Setup getUserMedia, with polyfill for older browsers
 // Adapted from: https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia
 function getMediaDevices () {
+  // eslint-disable-next-line compat/compat
   if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
+    // eslint-disable-next-line compat/compat
     return navigator.mediaDevices
   }
 

+ 1 - 0
test/endtoend/utils.js

@@ -1,3 +1,4 @@
+/* eslint-disable compat/compat */
 /* global window, capabilities */
 const path = require('path')
 const { spawn } = require('child_process')