Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uppy: refactor bundle package to ESM #3807

Merged
merged 1 commit into from Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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