Przeglądaj źródła

@uppy/transloadit: remove IE 10 hack (#3777)

Antoine du Hamel 2 lat temu
rodzic
commit
c223a1f204

+ 2 - 13
packages/@uppy/transloadit/src/Assembly.js

@@ -1,21 +1,10 @@
 import Emitter from 'component-emitter'
+import { io } from 'socket.io-client'
 import has from '@uppy/utils/lib/hasProperty'
 import NetworkError from '@uppy/utils/lib/NetworkError'
 import fetchWithNetworkError from '@uppy/utils/lib/fetchWithNetworkError'
 import parseUrl from './parseUrl.js'
 
-// We used to lazy load socket.io to avoid a console error
-// in IE 10 when the Transloadit plugin is not used.
-// (The console.error call comes from `buffer`. I
-// think we actually don't use that part of socket.io
-// at all…)
-// TODO: remove this hack in the next release.
-let socketIo
-function requireSocketIo () {
-  // eslint-disable-next-line no-return-assign, no-restricted-globals, global-require, no-undef
-  return socketIo ??= require('socket.io-client')
-}
-
 const ASSEMBLY_UPLOADING = 'ASSEMBLY_UPLOADING'
 const ASSEMBLY_EXECUTING = 'ASSEMBLY_EXECUTING'
 const ASSEMBLY_COMPLETED = 'ASSEMBLY_COMPLETED'
@@ -75,7 +64,7 @@ class TransloaditAssembly extends Emitter {
 
   #connectSocket () {
     const parsed = parseUrl(this.status.websocket_url)
-    const socket = requireSocketIo().connect(parsed.origin, {
+    const socket = io(parsed.origin, {
       transports: ['websocket'],
       path: parsed.pathname,
     })

+ 0 - 2
private/dev/package.json

@@ -10,8 +10,6 @@
     "@uppy/companion": "workspace:^"
   },
   "devDependencies": {
-    "@babel/core": "^7.4.4",
-    "@babel/types": "^7.17.0",
     "autoprefixer": "^10.2.6",
     "postcss-dir-pseudo-class": "^5.0.0",
     "postcss-logical": "^4.0.2",

+ 0 - 52
private/dev/vite.config.js

@@ -1,6 +1,4 @@
 import { fileURLToPath } from 'node:url'
-import { transformAsync } from '@babel/core'
-import t from '@babel/types'
 import autoprefixer from 'autoprefixer'
 import postcssLogical from 'postcss-logical'
 import postcssDirPseudoClass from 'postcss-dir-pseudo-class'
@@ -46,56 +44,6 @@ const config = {
       //   },
     ],
   },
-  plugins: [
-    // TODO: remove plugin when we remove the socket.io require call in @uppy/transloadit/src/Assembly.
-    {
-      name: 'vite-plugin-rewrite-dynamic-socketIo-require',
-      // eslint-disable-next-line consistent-return
-      resolveId (id) {
-        if (id.startsWith(PACKAGES_ROOT) && id.endsWith('transloadit/src/Assembly.js')) {
-          return id
-        }
-      },
-      transform (code, id) {
-        if (id.startsWith(PACKAGES_ROOT) && id.endsWith('transloadit/src/Assembly.js')) {
-          return transformAsync(code, {
-            plugins: [
-              {
-                visitor: {
-                  FunctionDeclaration (path) {
-                    if (path.node.id.name === 'requireSocketIo') {
-                      const prevSibling = path.getPrevSibling()
-                      if (t.isImportDeclaration(prevSibling) && prevSibling.node.specifiers?.length === 1
-                         && t.isImportDefaultSpecifier(prevSibling.node.specifiers[0])
-                         && prevSibling.node.specifiers[0].local.name === 'socketIo') {
-                        // The require call has already been rewritten to an import statement.
-                        return
-                      }
-                      if (!t.isVariableDeclaration(prevSibling)) {
-                        const { type, loc } = prevSibling.node
-                        throw new Error(`Unexpected ${type} at line ${loc.start.line}, cannot apply requireSocketIo hack`)
-                      }
-
-                      const { id:socketIoIdentifier } = prevSibling.node.declarations[0]
-
-                      prevSibling.replaceWith(t.importDeclaration(
-                        [t.importDefaultSpecifier(socketIoIdentifier)],
-                        t.stringLiteral('socket.io-client'),
-                      ))
-                      path.replaceWith(t.functionDeclaration(path.node.id, path.node.params, t.blockStatement([
-                        t.returnStatement(socketIoIdentifier),
-                      ])))
-                    }
-                  },
-                },
-              },
-            ],
-          })
-        }
-        return code
-      },
-    },
-  ],
 }
 
 export default config

+ 0 - 2
yarn.lock

@@ -9239,8 +9239,6 @@ __metadata:
   version: 0.0.0-use.local
   resolution: "@uppy-dev/dev@workspace:private/dev"
   dependencies:
-    "@babel/core": ^7.4.4
-    "@babel/types": ^7.17.0
     "@uppy/companion": "workspace:^"
     autoprefixer: ^10.2.6
     postcss-dir-pseudo-class: ^5.0.0