Skip to content

Commit

Permalink
uppy: refactor to ESM (#3807)
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Jun 7, 2022
1 parent b7ecab5 commit e00b9ed
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 86 deletions.
10 changes: 10 additions & 0 deletions .eslintrc.js
Expand Up @@ -274,6 +274,16 @@ module.exports = {
'import/extensions': ['error', 'ignorePackages'],
},
},
{
files: ['packages/uppy/*.mjs'],
rules: {
'import/first': 'off',
'import/newline-after-import': 'off',
'import/no-extraneous-dependencies': ['error', {
devDependencies: true,
}],
},
},
{
files: [
'packages/@uppy/*/types/*.d.ts',
Expand Down
20 changes: 12 additions & 8 deletions bin/build-bundle.mjs
Expand Up @@ -10,18 +10,17 @@ import babel from 'esbuild-plugin-babel'
const UPPY_ROOT = new URL('../', import.meta.url)
const PACKAGES_ROOT = new URL('./packages/', UPPY_ROOT)

function buildBundle (srcFile, bundleFile, { minify = true, standalone = '', plugins, target } = {}) {
function buildBundle (srcFile, bundleFile, { minify = true, standalone = '', plugins, target, format } = {}) {
return esbuild.build({
bundle: true,
sourcemap: true,
entryPoints: [srcFile],
outfile: bundleFile,
banner: {
js: '"use strict";',
},
platform: 'browser',
minify,
plugins,
target,
format,
}).then(() => {
if (minify) {
console.info(chalk.green(`✓ Built Minified Bundle [${standalone}]:`), chalk.magenta(bundleFile))
Expand All @@ -37,12 +36,17 @@ await fs.mkdir(new URL('./@uppy/locales/dist', PACKAGES_ROOT), { recursive: true

const methods = [
buildBundle(
'./packages/uppy/bundle.js',
'./packages/uppy/index.mjs',
'./packages/uppy/dist/uppy.min.mjs',
{ standalone: 'Uppy (ESM)', format: 'esm' },
),
buildBundle(
'./packages/uppy/bundle.mjs',
'./packages/uppy/dist/uppy.min.js',
{ standalone: 'Uppy' },
{ standalone: 'Uppy', format: 'iife' },
),
buildBundle(
'./packages/uppy/bundle-legacy.js',
'./packages/uppy/bundle-legacy.mjs',
'./packages/uppy/dist/uppy.legacy.min.js',
{
standalone: 'Uppy (with polyfills)',
Expand Down Expand Up @@ -94,7 +98,7 @@ methods.push(
),
)

Promise.all(methods).then(() => {
await Promise.all(methods).then(() => {
console.info(chalk.yellow('✓ JS bundles 🎉'))
}, (err) => {
console.error(chalk.red('✗ Error:'), chalk.red(err.message))
Expand Down
14 changes: 0 additions & 14 deletions packages/uppy/bundle-legacy.js

This file was deleted.

18 changes: 18 additions & 0 deletions packages/uppy/bundle-legacy.mjs
@@ -0,0 +1,18 @@
// adding this directive to make sure the output file is using strict mode:

'use strict'

import 'core-js'
import 'whatwg-fetch'
import 'abortcontroller-polyfill/dist/polyfill-patch-fetch'
// Order matters: AbortController needs fetch which needs Promise.

import 'md-gum-polyfill'
import ResizeObserver from 'resize-observer-polyfill'

if (typeof window.ResizeObserver !== 'function') window.ResizeObserver = ResizeObserver

// Needed for Babel
import 'regenerator-runtime/runtime'

import './bundle.mjs'
2 changes: 0 additions & 2 deletions packages/uppy/bundle.js

This file was deleted.

7 changes: 7 additions & 0 deletions packages/uppy/bundle.mjs
@@ -0,0 +1,7 @@
// adding this directive to make sure the output file is using strict mode:

'use strict'

import * as Uppy from './index.mjs'

globalThis.Uppy = Uppy
56 changes: 0 additions & 56 deletions packages/uppy/index.js

This file was deleted.

9 changes: 4 additions & 5 deletions packages/uppy/index.mjs
Expand Up @@ -2,11 +2,10 @@
export { default as Core, debugLogger } from '@uppy/core'

// Utilities
export { default as server } from '@uppy/companion-client'
/* eslint-disable */
import ProviderView from '@uppy/provider-views'
export var views = { ProviderView }
/* eslint-enable */
export * as server from '@uppy/companion-client'

import * as ProviderView from '@uppy/provider-views'
export const views = { ProviderView }

// Stores
export { default as DefaultStore } from '@uppy/store-default'
Expand Down
2 changes: 1 addition & 1 deletion packages/uppy/package.json
Expand Up @@ -3,7 +3,7 @@
"description": "Extensible JavaScript file upload widget with support for drag&drop, resumable uploads, previews, restrictions, file processing/encoding, remote providers like Instagram, Dropbox, Google Drive, S3 and more :dog:",
"version": "3.0.0-beta",
"license": "MIT",
"main": "index.js",
"main": "index.mjs",
"module": "index.mjs",
"unpkg": "dist/uppy.min.js",
"style": "dist/uppy.min.css",
Expand Down

0 comments on commit e00b9ed

Please sign in to comment.