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/companion: fix esm imports in production/transpiled builds #4561

Merged
merged 1 commit into from
Jul 11, 2023

Conversation

dschmidt
Copy link
Contributor

@dschmidt dschmidt commented Jul 8, 2023

see #4551 for context.

This change is needed for me to be able to sanely import the webdav library in a provider.
While not strictly necessary at this point and it can also be worked around (with eval("import('webdav')")), it seems like a good idea to be prepared for other esm libraries at some point.
Especially after I spent some time debugging this, I feel like you could benefit from this because it enables you to use esm dependencies.
Moreover, this prevents introducing new dependencies that will block esm dependencies at a later point.


TypeScript is used to transpile companion to CommonJS. require() in CommonJS is synchronous and cannot be used to import packages using ESM syntax, which are asynchronous by spec. If you want to import an ESM package, you need to use asynchronous dynamic import(). By default TypeScript transpiles this to Promise.resolve().then(() => require('webdav')) which is obviously using synchronous require internally and breaks the import of ESM packages. We need to switch moduleResolution to node16 to make TypeScript not transpile the import() call.


See https://www.typescriptlang.org/docs/handbook/esm-node.html for more information on moduleResolution

@aduh95
Copy link
Contributor

aduh95 commented Jul 10, 2023

Also constverum/stylelint-config-rational-order#39 mentions vulnerabilities in old stylelint versions - haven't looked closer or validated how much they affect this project (probably not so much, but maybe still something to take into account)

Good to know, however there's already a dependabot PR to address that, could you remove those changes from this PR?

@aduh95
Copy link
Contributor

aduh95 commented Jul 10, 2023

Styelint upgrade have landed, could you please rebase and remove the unrelated changes please?

TypeScript is used to transpile companion to CommonJS.
`require()` in CommonJS is synchronous and cannot be used to import packages using ESM syntax, which are asynchronous by spec.
If you want to import an ESM package, you need to use asynchronous dynamic `import()`.
By default TypeScript transpiles this to `Promise.resolve().then(() => require('webdav'))` which is obviously using synchronous `require` internally and breaks the import of ESM packages.
We need to switch `moduleResolution` to `node16` to make TypeScript not transpile the `import()` call.
@aduh95 aduh95 added the safe to test Add this label on trustworthy PRs to spawn the e2e test suite label Jul 10, 2023
@dschmidt
Copy link
Contributor Author

done - thanks for that fix in the other PR, that's way nicer than my approach :) (wish I had started the effort 3 days later, haha)

@github-actions github-actions bot removed the safe to test Add this label on trustworthy PRs to spawn the e2e test suite label Jul 10, 2023
@aduh95 aduh95 added the safe to test Add this label on trustworthy PRs to spawn the e2e test suite label Jul 10, 2023
@github-actions github-actions bot removed pending end-to-end tests safe to test Add this label on trustworthy PRs to spawn the e2e test suite labels Jul 10, 2023
@aduh95 aduh95 merged commit 7dcf8c2 into transloadit:main Jul 11, 2023
@github-actions github-actions bot mentioned this pull request Jul 13, 2023
github-actions bot added a commit that referenced this pull request Jul 13, 2023
| Package                | Version | Package                | Version |
| ---------------------- | ------- | ---------------------- | ------- |
| @uppy/aws-s3-multipart |   3.5.0 | @uppy/locales          |   3.2.3 |
| @uppy/box              |   2.1.2 | @uppy/onedrive         |   3.1.2 |
| @uppy/companion        |   4.7.0 | @uppy/provider-views   |   3.4.0 |
| @uppy/companion-client |   3.2.1 | @uppy/react            |   3.1.3 |
| @uppy/core             |   3.3.1 | @uppy/status-bar       |   3.2.2 |
| @uppy/dashboard        |   3.4.2 | @uppy/transloadit      |   3.2.0 |
| @uppy/dropbox          |   3.1.2 | @uppy/utils            |   5.4.1 |
| @uppy/google-drive     |   3.2.0 | uppy                   |  3.12.0 |

- @uppy/transloadit: fix error message (Antoine du Hamel / #4572)
- @uppy/provider-views: add support for remote file paths (Mikael Finstad / #4537)
- @uppy/transloadit: implement Server-sent event API (Antoine du Hamel / #4098)
- @uppy/aws-s3-multipart: add support for signing on the client (Antoine du Hamel / #4519)
- @uppy/react: allow `id` from props (Merlijn Vos / #4570)
- @uppy/aws-s3-multipart: fix lint warning (Antoine du Hamel / #4569)
- @uppy/status-bar: listen to `upload` event instead of button click (Antoine du Hamel / #4563)
- @uppy/aws-s3-multipart: fix support for non-multipart PUT upload (Antoine du Hamel / #4568)
- @uppy/companion: fix esm imports in production/transpiled builds (Dominik Schmidt / #4561)
- @uppy/locales: fix expression and spelling errors in es_ES (Rubén / #4567)
- meta: upgrade dev dependencies (dependabot\[bot\])
- meta: Don't use triage label (Artur Paikin / #4552)
- meta: update Cypress (Antoine du Hamel / #4562)
- @uppy/box,@uppy/companion,@uppy/dropbox,@uppy/google-drive,@uppy/onedrive,@uppy/provider-views: Load Google Drive / OneDrive lists 5-10x faster & always load all files (Merlijn Vos / #4513)
- @uppy/locales: Add missing pt-BR locales for ImageEditor plugin (Mateus Cruz / #4558)
@dschmidt dschmidt deleted the companion-esm-imports branch September 10, 2023 22:26
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.

3 participants