Bladeren bron

@uppy/google-drive: refactor to ESM (#3683)

Antoine du Hamel 3 jaren geleden
bovenliggende
commit
55b2812943

+ 1 - 0
.eslintrc.js

@@ -205,6 +205,7 @@ module.exports = {
         'packages/@uppy/facebook/src/**/*.js',
         'packages/@uppy/file-input/src/**/*.js',
         'packages/@uppy/form/src/**/*.js',
+        'packages/@uppy/google-drive/src/**/*.js',
         'packages/@uppy/svelte/src/**/*.js',
         'packages/@uppy/svelte/rollup.config.js',
         'packages/@uppy/vue/src/**/*.js',

+ 1 - 0
packages/@uppy/google-drive/package.json

@@ -5,6 +5,7 @@
   "license": "MIT",
   "main": "lib/index.js",
   "types": "types/index.d.ts",
+  "type": "module",
   "keywords": [
     "file uploader",
     "google drive",

+ 2 - 2
packages/@uppy/google-drive/src/DriveProviderViews.js

@@ -1,6 +1,6 @@
-const { ProviderViews } = require('@uppy/provider-views')
+import { ProviderViews } from '@uppy/provider-views'
 
-module.exports = class DriveProviderViews extends ProviderViews {
+export default class DriveProviderViews extends ProviderViews {
   toggleCheckbox (e, file) {
     e.stopPropagation()
     e.preventDefault()

+ 86 - 0
packages/@uppy/google-drive/src/GoogleDrive.jsx

@@ -0,0 +1,86 @@
+import { UIPlugin } from '@uppy/core'
+import { Provider } from '@uppy/companion-client'
+import { h } from 'preact'
+
+import packageJson from '../package.json'
+import DriveProviderViews from './DriveProviderViews.js'
+import locale from './locale.js'
+
+export default class GoogleDrive extends UIPlugin {
+  static VERSION = packageJson.version
+
+  constructor (uppy, opts) {
+    super(uppy, opts)
+    this.id = this.opts.id || 'GoogleDrive'
+    this.title = this.opts.title || 'Google Drive'
+    Provider.initPlugin(this, opts)
+    this.title = this.opts.title || 'Google Drive'
+    this.icon = () => (
+      <svg
+        aria-hidden="true"
+        focusable="false"
+        width="32"
+        height="32"
+        viewBox="0 0 32 32"
+      >
+        <g fill="none" fillRule="evenodd">
+          <rect
+            className="uppy-ProviderIconBg"
+            fill="#4285F4"
+            width="32"
+            height="32"
+            rx="16"
+          />
+          <path
+            d="M25.216 17.736L19.043 7h-6.086l6.175 10.736h6.084zm-11.275.896L10.9 24h11.723l3.04-5.368H13.942zm-1.789-10.29l-5.816 10.29L9.38 24l5.905-10.29-3.132-5.369z"
+            fill="#FFF"
+          />
+        </g>
+      </svg>
+    )
+
+    this.provider = new Provider(uppy, {
+      companionUrl: this.opts.companionUrl,
+      companionHeaders: this.opts.companionHeaders,
+      companionKeysParams: this.opts.companionKeysParams,
+      companionCookiesRule: this.opts.companionCookiesRule,
+      provider: 'drive',
+      pluginId: this.id,
+    })
+
+    this.defaultLocale = locale
+
+    this.i18nInit()
+    this.title = this.i18n('pluginNameGoogleDrive')
+
+    this.onFirstRender = this.onFirstRender.bind(this)
+    this.render = this.render.bind(this)
+  }
+
+  install () {
+    this.view = new DriveProviderViews(this, {
+      provider: this.provider,
+    })
+
+    const { target } = this.opts
+    if (target) {
+      this.mount(target, this)
+    }
+  }
+
+  uninstall () {
+    this.view.tearDown()
+    this.unmount()
+  }
+
+  onFirstRender () {
+    return Promise.all([
+      this.provider.fetchPreAuthToken(),
+      this.view.getFolder('root', '/'),
+    ])
+  }
+
+  render (state) {
+    return this.view.render(state)
+  }
+}

+ 1 - 85
packages/@uppy/google-drive/src/index.js

@@ -1,85 +1 @@
-const { UIPlugin } = require('@uppy/core')
-const { Provider } = require('@uppy/companion-client')
-const { h } = require('preact')
-const DriveProviderViews = require('./DriveProviderViews')
-
-const locale = require('./locale')
-
-module.exports = class GoogleDrive extends UIPlugin {
-  static VERSION = require('../package.json').version
-
-  constructor (uppy, opts) {
-    super(uppy, opts)
-    this.id = this.opts.id || 'GoogleDrive'
-    this.title = this.opts.title || 'Google Drive'
-    Provider.initPlugin(this, opts)
-    this.title = this.opts.title || 'Google Drive'
-    this.icon = () => (
-      <svg
-        aria-hidden="true"
-        focusable="false"
-        width="32"
-        height="32"
-        viewBox="0 0 32 32"
-      >
-        <g fill="none" fillRule="evenodd">
-          <rect
-            className="uppy-ProviderIconBg"
-            fill="#4285F4"
-            width="32"
-            height="32"
-            rx="16"
-          />
-          <path
-            d="M25.216 17.736L19.043 7h-6.086l6.175 10.736h6.084zm-11.275.896L10.9 24h11.723l3.04-5.368H13.942zm-1.789-10.29l-5.816 10.29L9.38 24l5.905-10.29-3.132-5.369z"
-            fill="#FFF"
-          />
-        </g>
-      </svg>
-    )
-
-    this.provider = new Provider(uppy, {
-      companionUrl: this.opts.companionUrl,
-      companionHeaders: this.opts.companionHeaders,
-      companionKeysParams: this.opts.companionKeysParams,
-      companionCookiesRule: this.opts.companionCookiesRule,
-      provider: 'drive',
-      pluginId: this.id,
-    })
-
-    this.defaultLocale = locale
-
-    this.i18nInit()
-    this.title = this.i18n('pluginNameGoogleDrive')
-
-    this.onFirstRender = this.onFirstRender.bind(this)
-    this.render = this.render.bind(this)
-  }
-
-  install () {
-    this.view = new DriveProviderViews(this, {
-      provider: this.provider,
-    })
-
-    const { target } = this.opts
-    if (target) {
-      this.mount(target, this)
-    }
-  }
-
-  uninstall () {
-    this.view.tearDown()
-    this.unmount()
-  }
-
-  onFirstRender () {
-    return Promise.all([
-      this.provider.fetchPreAuthToken(),
-      this.view.getFolder('root', '/'),
-    ])
-  }
-
-  render (state) {
-    return this.view.render(state)
-  }
-}
+export { default } from './GoogleDrive.jsx'

+ 1 - 1
packages/@uppy/google-drive/src/locale.js

@@ -1,4 +1,4 @@
-module.exports = {
+export default {
   strings: {
     pluginNameGoogleDrive: 'Google Drive',
   },

+ 1 - 1
website/src/docs/google-drive.md

@@ -125,7 +125,7 @@ This option correlates to the [RequestCredentials value](https://developer.mozil
 <!-- eslint-disable no-restricted-globals, no-multiple-empty-lines -->
 
 ```js
-module.exports = {
+export default {
   strings: {
     pluginNameGoogleDrive: 'Google Drive',
   },