From 13df224b7543fa01d9330c6f4a206f019115cf47 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Mon, 23 May 2022 17:15:15 +0200 Subject: [PATCH] @uppy/transloadit: remove IE 10 hack (#3777) --- packages/@uppy/transloadit/src/Assembly.js | 15 +------ private/dev/package.json | 2 - private/dev/vite.config.js | 52 ---------------------- yarn.lock | 2 - 4 files changed, 2 insertions(+), 69 deletions(-) diff --git a/packages/@uppy/transloadit/src/Assembly.js b/packages/@uppy/transloadit/src/Assembly.js index 8923ec321db..639acbcde80 100644 --- a/packages/@uppy/transloadit/src/Assembly.js +++ b/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, }) diff --git a/private/dev/package.json b/private/dev/package.json index 89d9de71606..e777ccc2d79 100644 --- a/private/dev/package.json +++ b/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", diff --git a/private/dev/vite.config.js b/private/dev/vite.config.js index 4ad6ed844e2..847b7fef4c4 100644 --- a/private/dev/vite.config.js +++ b/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 diff --git a/yarn.lock b/yarn.lock index e824f905936..2f9dac6ea5b 100644 --- a/yarn.lock +++ b/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