diff --git a/.eslintrc.js b/.eslintrc.js index 926740fc6..236518219 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -168,11 +168,38 @@ module.exports = { jsx: true, }, }, + rules: { + 'no-restricted-globals': [ + 'error', + { + name: '__filename', + message: 'Use import.meta.url instead', + }, + { + name: '__dirname', + message: 'Not available in ESM', + }, + { + name: 'exports', + message: 'Not available in ESM', + }, + { + name: 'module', + message: 'Not available in ESM', + }, + { + name: 'require', + message: 'Use import instead', + }, + ], + 'import/extensions': ['error', 'ignorePackages'], + }, }, { files: [ // Packages that have switched to ESM sources: 'packages/@uppy/audio/src/**/*.js', + 'packages/@uppy/box/src/**/*.js', 'packages/@uppy/compressor/src/**/*.js', 'packages/@uppy/vue/src/**/*.js', ], diff --git a/packages/@uppy/box/package.json b/packages/@uppy/box/package.json index 4dcfcc8c0..ed4ab4f2e 100644 --- a/packages/@uppy/box/package.json +++ b/packages/@uppy/box/package.json @@ -4,6 +4,7 @@ "version": "1.0.5", "license": "MIT", "main": "lib/index.js", + "type": "module", "types": "types/index.d.ts", "keywords": [ "file uploader", diff --git a/packages/@uppy/box/src/Box.jsx b/packages/@uppy/box/src/Box.jsx new file mode 100644 index 000000000..e924d3496 --- /dev/null +++ b/packages/@uppy/box/src/Box.jsx @@ -0,0 +1,70 @@ +import { UIPlugin } from '@uppy/core' +import { Provider } from '@uppy/companion-client' +import { ProviderViews } from '@uppy/provider-views' +import { h } from 'preact' + +import locale from './locale.js' +import packageJson from '../package.json' + +export default class Box extends UIPlugin { + static VERSION = packageJson.version + + constructor (uppy, opts) { + super(uppy, opts) + this.id = this.opts.id || 'Box' + Provider.initPlugin(this, opts) + this.title = this.opts.title || 'Box' + this.icon = () => ( + + ) + + this.provider = new Provider(uppy, { + companionUrl: this.opts.companionUrl, + companionHeaders: this.opts.companionHeaders, + companionKeysParams: this.opts.companionKeysParams, + companionCookiesRule: this.opts.companionCookiesRule, + provider: 'box', + pluginId: this.id, + }) + + this.defaultLocale = locale + + this.i18nInit() + this.title = this.i18n('pluginNameBox') + + this.onFirstRender = this.onFirstRender.bind(this) + this.render = this.render.bind(this) + } + + install () { + this.view = new ProviderViews(this, { + provider: this.provider, + }) + + const { target } = this.opts + if (target) { + this.mount(target, this) + } + } + + uninstall () { + this.view.tearDown() + this.unmount() + } + + onFirstRender () { + return this.view.getFolder() + } + + render (state) { + return this.view.render(state) + } +} diff --git a/packages/@uppy/box/src/index.js b/packages/@uppy/box/src/index.js index 064b0fa3f..14577982d 100644 --- a/packages/@uppy/box/src/index.js +++ b/packages/@uppy/box/src/index.js @@ -1,69 +1 @@ -const { UIPlugin } = require('@uppy/core') -const { Provider } = require('@uppy/companion-client') -const { ProviderViews } = require('@uppy/provider-views') -const { h } = require('preact') - -const locale = require('./locale') - -module.exports = class Box extends UIPlugin { - static VERSION = require('../package.json').version - - constructor (uppy, opts) { - super(uppy, opts) - this.id = this.opts.id || 'Box' - Provider.initPlugin(this, opts) - this.title = this.opts.title || 'Box' - this.icon = () => ( - - ) - - this.provider = new Provider(uppy, { - companionUrl: this.opts.companionUrl, - companionHeaders: this.opts.companionHeaders, - companionKeysParams: this.opts.companionKeysParams, - companionCookiesRule: this.opts.companionCookiesRule, - provider: 'box', - pluginId: this.id, - }) - - this.defaultLocale = locale - - this.i18nInit() - this.title = this.i18n('pluginNameBox') - - this.onFirstRender = this.onFirstRender.bind(this) - this.render = this.render.bind(this) - } - - install () { - this.view = new ProviderViews(this, { - provider: this.provider, - }) - - const { target } = this.opts - if (target) { - this.mount(target, this) - } - } - - uninstall () { - this.view.tearDown() - this.unmount() - } - - onFirstRender () { - return this.view.getFolder() - } - - render (state) { - return this.view.render(state) - } -} +export { default } from './Box.jsx' diff --git a/packages/@uppy/box/src/locale.js b/packages/@uppy/box/src/locale.js index 18e820dac..27431b6bb 100644 --- a/packages/@uppy/box/src/locale.js +++ b/packages/@uppy/box/src/locale.js @@ -1,4 +1,4 @@ -module.exports = { +export default { strings: { pluginNameBox: 'Box', }, diff --git a/website/src/docs/box.md b/website/src/docs/box.md index 18648e8ce..763f4c108 100644 --- a/website/src/docs/box.md +++ b/website/src/docs/box.md @@ -130,7 +130,7 @@ This option correlates to the [RequestCredentials value](https://developer.mozil ```js -module.exports = { +export default { strings: { pluginNameBox: 'Box', },