-
Notifications
You must be signed in to change notification settings - Fork 127
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
Migrate packages to ESM #2061
Migrate packages to ESM #2061
Conversation
🦋 Changeset detectedLatest commit: df9d81f The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
7eac9f2
to
68138ed
Compare
Codecov Report
@@ Coverage Diff @@
## next #2061 +/- ##
==========================================
+ Coverage 96.81% 96.96% +0.15%
==========================================
Files 248 258 +10
Lines 22383 23165 +782
Branches 2117 2166 +49
==========================================
+ Hits 21669 22462 +793
+ Misses 703 697 -6
+ Partials 11 6 -5
|
68138ed
to
233aab5
Compare
233aab5
to
b53895b
Compare
b53895b
to
74db9e2
Compare
import { Theme } from '@sumup/design-tokens'; | ||
|
||
// eslint-disable-next-line | ||
const styled = (_styled.default || _styled) as CreateStyled; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This hack is necessary to make Emotion.js' default exports play nice with ESM. Adapted from emotion-js/emotion#2730 (comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the ref and the comment! Hopefully we can remove this in the future, when Emotion improves ESM support (or when we drop Emotion)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likely the second 🤞
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not gonna lie, I very much skimmed through this and might have missed things (a lot of file import diff, like you said. GitHub should allow using regex to show/hide diff)
This is such an amazing cleanup of old deps that were sticking around, though! Babel! Lodash! ✨ ⭐ 🌟 💫
Side note: I'm getting mildly panicked with the scope of v7, but maybe that's just me? It's going to be a biggie and we might want to think about ways to help consumer apps opt into as many changes as possible. The build changes to support v7 only (ESM, web components if this makes it into v7, etc) are already going to be a big deal depending on the consumer app stack, so let's try to make everything else as easy to adopt as possible 🙂
(PS. "Comment" not "Approve" primarily because I'm wondering about tests for the hooks that moved to the repo.)
import { Theme } from '@sumup/design-tokens'; | ||
|
||
// eslint-disable-next-line | ||
const styled = (_styled.default || _styled) as CreateStyled; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the ref and the comment! Hopefully we can remove this in the future, when Emotion improves ESM support (or when we drop Emotion)
It's true that v7 contains many big infrastructure changes. However, the changes in userland should be minimal. Next.js supports ESM out of the box, Jest can be configured with a single line of code to support ESM dependencies. The other big change to the implementation will be the switch to Linaria, which will only require the global import of a single stylesheet. Web components will likely be introduced in v7.x as an experiment and will be fully opt-in. Or perhaps I misunderstood and you're worried about potential bugs, not the work to upgrade? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm relieved! Thank you 😌 (and thanks for the new unit test for the hooks!)
Purpose
While testing out #2020, I discovered that some required dependencies are full ESM packages. ESM cannot be imported into CJS, so we need to migrate Circuit UI to ESM to be able to use web components. This migration is inevitable anyway, and the ecosystem seems ready enough at this point (especially after #2053).
Sindre Sorhus has published an extremely helpful guide for pure ESM packages which I referenced throughout the migration.
Approach and changes
index
files) and the file extension. I usedeslint-plugin-node
's file-extension-in-import rule, global search-and-replace with complex regexes, and lots of sweat and tears to modify all imports. Changed imports make up the vast majority of the diff.package.json
fields:"type": "module"
to all packages:"exports"
field to configure the package entry point(s):"engines"
field to require Node.js 16+, the first maintained version of Node with support for ES modules.use-previous
anduse-latest
dependencies into the repository and to proxying the default exports of the@emotion/styled
and@emotion/is-prop-valid
packages.ts-node
withtsx
.eslint-import-resolver-typescript
plugin.Definition of done