Skip to content

Commit

Permalink
Revert "@uppy/companion-client: refactor to ESM (#3693)" (#3719)
Browse files Browse the repository at this point in the history
This reverts commit 795e817.
  • Loading branch information
aduh95 authored May 12, 2022
1 parent 3f63198 commit 837bf04
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 37 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ module.exports = {
// Packages that have switched to ESM sources:
'packages/@uppy/audio/src/**/*.js',
'packages/@uppy/box/src/**/*.js',
'packages/@uppy/companion-client/src/**/*.js',
'packages/@uppy/compressor/src/**/*.js',
'packages/@uppy/drag-drop/src/**/*.js',
'packages/@uppy/drop-target/src/**/*.js',
Expand Down
4 changes: 0 additions & 4 deletions packages/@uppy/companion-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"license": "MIT",
"main": "lib/index.js",
"types": "types/index.d.ts",
"type": "module",
"keywords": [
"file uploader",
"uppy",
Expand All @@ -24,8 +23,5 @@
"dependencies": {
"@uppy/utils": "workspace:^",
"namespace-emitter": "^2.0.1"
},
"devDependencies": {
"@jest/globals": "^27.4.2"
}
}
2 changes: 1 addition & 1 deletion packages/@uppy/companion-client/src/AuthError.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ class AuthError extends Error {
}
}

export default AuthError
module.exports = AuthError
10 changes: 4 additions & 6 deletions packages/@uppy/companion-client/src/Provider.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use strict'

import RequestClient from './RequestClient.js'
import tokenStorage from './tokenStorage.js'
const RequestClient = require('./RequestClient')
const tokenStorage = require('./tokenStorage')

const getName = (id) => {
return id.split('-').map((s) => s.charAt(0).toUpperCase() + s.slice(1)).join(' ')
}

export default class Provider extends RequestClient {
module.exports = class Provider extends RequestClient {
constructor (uppy, opts) {
super(uppy, opts)
this.provider = opts.provider
Expand Down Expand Up @@ -37,7 +37,7 @@ export default class Provider extends RequestClient {
}

onReceiveResponse (response) {
response = super.onReceiveResponse(response) // eslint-disable-line no-param-reassign
response = super.onReceiveResponse(response)
const plugin = this.uppy.getPlugin(this.pluginId)
const oldAuthenticated = plugin.getPluginState().authenticated
const authenticated = oldAuthenticated ? response.status !== 401 : response.status < 400
Expand Down Expand Up @@ -106,7 +106,6 @@ export default class Provider extends RequestClient {
}

static initPlugin (plugin, opts, defaultOpts) {
/* eslint-disable no-param-reassign */
plugin.type = 'acquirer'
plugin.files = []
if (defaultOpts) {
Expand All @@ -132,6 +131,5 @@ export default class Provider extends RequestClient {
}

plugin.storage = plugin.opts.storage || tokenStorage
/* eslint-enable no-param-reassign */
}
}
13 changes: 6 additions & 7 deletions packages/@uppy/companion-client/src/RequestClient.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
'use strict'

import fetchWithNetworkError from '@uppy/utils/lib/fetchWithNetworkError'
import ErrorWithCause from '@uppy/utils/lib/ErrorWithCause'
import AuthError from './AuthError.js'

import packageJson from '../package.json'
const fetchWithNetworkError = require('@uppy/utils/lib/fetchWithNetworkError')
const ErrorWithCause = require('@uppy/utils/lib/ErrorWithCause')
const AuthError = require('./AuthError')

// Remove the trailing slash so we can always safely append /xyz.
function stripSlash (url) {
Expand Down Expand Up @@ -32,8 +30,9 @@ async function handleJSONResponse (res) {
return jsonPromise
}

export default class RequestClient {
static VERSION = packageJson.version
module.exports = class RequestClient {
// eslint-disable-next-line global-require
static VERSION = require('../package.json').version

#getPostResponseFunc = skip => response => (skip ? response : this.onReceiveResponse(response))

Expand Down
3 changes: 1 addition & 2 deletions packages/@uppy/companion-client/src/RequestClient.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { describe, it, expect } from '@jest/globals'
import RequestClient from './RequestClient.js'
const RequestClient = require('./RequestClient')

describe('RequestClient', () => {
it('has a hostname without trailing slash', () => {
Expand Down
7 changes: 4 additions & 3 deletions packages/@uppy/companion-client/src/SearchProvider.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict'

import RequestClient from './RequestClient.js'
const RequestClient = require('./RequestClient')

const getName = (id) => {
return id.split('-').map((s) => s.charAt(0).toUpperCase() + s.slice(1)).join(' ')
}

export default class SearchProvider extends RequestClient {
module.exports = class SearchProvider extends RequestClient {
constructor (uppy, opts) {
super(uppy, opts)
this.provider = opts.provider
Expand All @@ -20,6 +20,7 @@ export default class SearchProvider extends RequestClient {
}

search (text, queries) {
return this.get(`search/${this.id}/list?q=${encodeURIComponent(text)}${queries ? `&${queries}` : ''}`)
queries = queries ? `&${queries}` : ''
return this.get(`search/${this.id}/list?q=${encodeURIComponent(text)}${queries}`)
}
}
4 changes: 2 additions & 2 deletions packages/@uppy/companion-client/src/Socket.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ee from 'namespace-emitter'
const ee = require('namespace-emitter')

export default class UppySocket {
module.exports = class UppySocket {
#queued = []

#emitter = ee()
Expand Down
3 changes: 1 addition & 2 deletions packages/@uppy/companion-client/src/Socket.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { jest, describe, it, expect } from '@jest/globals'
import UppySocket from './Socket.js'
const UppySocket = require('./Socket')

describe('Socket', () => {
let webSocketConstructorSpy
Expand Down
10 changes: 5 additions & 5 deletions packages/@uppy/companion-client/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
* Manages communications with Companion
*/

import RequestClient from './RequestClient.js'
import Provider from './Provider.js'
import SearchProvider from './SearchProvider.js'
import Socket from './Socket.js'
const RequestClient = require('./RequestClient')
const Provider = require('./Provider')
const SearchProvider = require('./SearchProvider')
const Socket = require('./Socket')

export {
module.exports = {
RequestClient,
Provider,
SearchProvider,
Expand Down
6 changes: 3 additions & 3 deletions packages/@uppy/companion-client/src/tokenStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
/**
* This module serves as an Async wrapper for LocalStorage
*/
export function setItem (key, value) {
module.exports.setItem = (key, value) => {
return new Promise((resolve) => {
localStorage.setItem(key, value)
resolve()
})
}

export function getItem (key) {
module.exports.getItem = (key) => {
return Promise.resolve(localStorage.getItem(key))
}

export function removeItem (key) {
module.exports.removeItem = (key) => {
return new Promise((resolve) => {
localStorage.removeItem(key)
resolve()
Expand Down
1 change: 0 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9713,7 +9713,6 @@ __metadata:
version: 0.0.0-use.local
resolution: "@uppy/companion-client@workspace:packages/@uppy/companion-client"
dependencies:
"@jest/globals": ^27.4.2
"@uppy/utils": "workspace:^"
namespace-emitter: ^2.0.1
languageName: unknown
Expand Down

0 comments on commit 837bf04

Please sign in to comment.