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/core: move Uppy class to its own module #3225

Merged
merged 6 commits into from Sep 28, 2021

Conversation

aduh95
Copy link
Member

@aduh95 aduh95 commented Sep 23, 2021

This would allow users to use Uppy without loading preact if they are not using any UIPlugin.

const { Uppy, BasePlugin } = require('@uppy/core');
// can be replaced with
const Uppy = require('@uppy/core/lib/Uppy.js');
const BasePlugin = require('@uppy/core/lib/BasePlugin.js');

Fixes: #3220

@Murderlon
Copy link
Member

Is there no other way to keep the import @uppy/core instead of the full path for all imports?

@aduh95
Copy link
Member Author

aduh95 commented Sep 23, 2021

Is there no other way to keep the import @uppy/core instead of the full path for all imports?

Users don't have to use the full path, it's only for those who need/want to opt-out of importing UIPlugin (maybe because they don't want to setup tree-shaking).

@Murderlon
Copy link
Member

Users don't have to use the full path, it's only for those who need/want to opt-out of importing UIPlugin (maybe because they don't want to setup tree-shaking).

Everyone wants to opt-out of importing UIPlugin unnecessarily, right? And from the looks of the issue the person did have tree-shaking setup and it still happened. Ideally I'm looking for a solution where we keep the user-facing imports exactly as is, but it doesn't import UIPlugin if you only import Uppy.

@aduh95
Copy link
Member Author

aduh95 commented Sep 23, 2021

If we remove UIPlugin from the exports of @uppy/core, it would be a breaking change for users who expect to have access to it from there.
If we lazy-load UIPlugin, that could work but is quite cumbersome and could also break some bundler as it's not a very common practice.

let UIPlugin;
Reflect.defineProperty(module.exports, 'UIPlugin', {
  enumerable: true,
  configurable: true,
  get() {
    return UIPlugin ??= require('./UIPlugin')
  },
  set(value) {
    UIPlugin = value
  }
})

IMHO the change in this PR is a lesser evil, unless we can think of another solution?

@Murderlon
Copy link
Member

Murderlon commented Sep 23, 2021

Thanks for explaining. I'm not knowledgeable on bundlers enough to know if there is another solution. I'm sure @goto-bus-stop would know if there is, but they are on holidays.

It's just unfortunate we did a big 2.0 launch blog post with the selling point of not bundling Preact if you import BasePlugin, and yet that happens, unless you know about this potential import trick. We would have to change the post and the docs temporarily and then change the docs back once we do 3.0 with ESM.

Perhaps good to let this sit till @arturi and @goto-bus-stop are back and then make a decision? Or is this really the only feasible way forward?

@aduh95
Copy link
Member Author

aduh95 commented Sep 23, 2021

I think we should land this nonetheless, as isolating classes in their own module is good practice anyway, and that doesn't mean we can't find a better solution in the future. Holding on this PR doesn't do our users any good, landing it doesn't make the core problem go away but at least provides a workaround.

@Murderlon
Copy link
Member

Fair enough! It would be good to add notes about these imports to the blog post and uppy core docs in this PR.

Copy link
Member

@Murderlon Murderlon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The migration guide should also be updated. And perhaps a note at the first code snippet here as well?

website/src/_posts/2021-08-2.0.md Outdated Show resolved Hide resolved
aduh95 and others added 2 commits September 23, 2021 15:35
Co-authored-by: Merlijn Vos <merlijn@soverin.net>
@arturi
Copy link
Contributor

arturi commented Sep 27, 2021

It's just unfortunate we did a big 2.0 launch blog post with the selling point of not bundling Preact if you import BasePlugin, and yet that happens, unless you know about this potential import trick. We would have to change the post and the docs temporarily and then change the docs back once we do 3.0 with ESM.

Yeah, it is unfortunate, but I guess that’s the way to go for now. At least with this PR we have that option to offer — Preact won’t be bundled via require('@uppy/core/lib/BasePlugin.js'). I am not a fan of lazy-loading here, I’d rather wait for 3.0. So I propose we merge this when you feel it’s ready and update the docs / blog post.

@aduh95 aduh95 merged commit d690315 into transloadit:main Sep 28, 2021
@aduh95 aduh95 deleted the uppy-as-a-module branch September 28, 2021 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@uppy/core bundles Preact even if you don't use UIPlugin
3 participants