-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fixed importing in Node ESM #3029
Conversation
🦋 Changeset detectedLatest commit: 2e01219 The changes in this PR will be included in the next version bump. This PR includes changesets to release 23 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 |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 2e01219:
|
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.
Do we care that this is kind of breaking in that you previously could have done the below thing?
import styled from '@emotion/styled'
styled.default(...)
Maybe it's fine since that would also be broken in many bundler environments so the reliable thing would have been to do styled.default || styled
?
Though it wouldn't be that hard to do styled.default = styled
and then nothing would break, idk wdyt?
I don't think so. Yes, somebody could depend on this behavior - but we never considered it to be alright. Nothing like that is in our docs. I consider this PR to be a bug fix but, of course, the lines is quite blurry here
It would work... but then it would likely complain at type-level about this stuff (which reminds... I probably need to test this PR with I'm rather against this though. There are probably not that many ESM early adopters out there that we should take this into a consideration here. |
Because there are |
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.
assuming you checked it in moduleResolution: bundler & maybe nodenext as well, looks good
packages/styled/macro.d.mts
Outdated
export * from './macro.js' | ||
export { _default as default } from './macro.default.js' |
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.
export * from './macro.js' | |
export { _default as default } from './macro.default.js' | |
export { default } from '@emotion/styled' | |
export * from '@emotion/styled' |
+ delete the macro.default.d.ts
+ do this for the other packages
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.
hm, why is that? 🤔 it seems to me that TS would trip over this without macro.default.d.ts
in certain configurations
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.
If we're in a .mts
and we're resolving @emotion/styled
, we'll hit the import
condition we have for "."
and get the already correct default
.
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.
oh, that makes sense 👍 i wouldn't use a self reference here myself (it makes sense to use it - i just wouldnt think of it myself) but it was already here and it makes sense that with it we can simplify this a little bit. (EDIT:// ah, the self reference in this particular file is part of your proposed change, nice)
"./macro": { | ||
"types": { | ||
"import": "./macro.d.mts", | ||
"default": "./macro.d.ts" |
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.
"default": "./macro.d.ts" |
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.
hm, i wasn't sure if this would "fall through" to the other default... does it? 🤔
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.
It does (but that's correct behaviour, not like TS's bug)
"./macro": { | ||
"types": { | ||
"import": "./macro.d.mts", | ||
"default": "./macro.d.ts" | ||
}, | ||
"default": "./macro.js" | ||
} |
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.
While I'm not a fan of array flavor... maybe, in here, this would actually be a little bit more obvious that the "fallthrough" is intended?
"./macro": { | |
"types": { | |
"import": "./macro.d.mts", | |
"default": "./macro.d.ts" | |
}, | |
"default": "./macro.js" | |
} | |
"./macro": [ | |
{ | |
"types": { | |
"import": "./macro.d.mts" | |
} | |
}, | |
"./macro.js" | |
] |
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.
Nevermind, just leave it how it is. (it looks like arethetypeswrong incorrectly flags this as a problem, will open an issue about that in a moment)
fixes #2973
fixes #2927
fixes #2730
fixes #2582