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

Fixed importing in Node ESM #3029

Merged
merged 4 commits into from May 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions packages/css/macro.d.mts
@@ -0,0 +1 @@
export * from './macro.js'
12 changes: 8 additions & 4 deletions packages/css/package.json
Expand Up @@ -9,9 +9,7 @@
"src",
"dist",
"types",
"macro.js",
"macro.d.ts",
"macro.js.flow",
"macro.*",
"create-instance"
],
"scripts": {
Expand Down Expand Up @@ -65,7 +63,13 @@
],
"exports": {
"extra": {
"./macro": "./macro.js"
"./macro": {
"types": {
"import": "./macro.d.mts",
"default": "./macro.d.ts"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"default": "./macro.d.ts"

Copy link
Member Author

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? 🤔

Copy link
Member

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)

},
"default": "./macro.js"
}
Comment on lines +72 to +78
Copy link
Member Author

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?

Suggested change
"./macro": {
"types": {
"import": "./macro.d.mts",
"default": "./macro.d.ts"
},
"default": "./macro.js"
}
"./macro": [
{
"types": {
"import": "./macro.d.mts"
}
},
"./macro.js"
]

Copy link
Member

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)

}
}
}
Expand Down
2 changes: 2 additions & 0 deletions packages/native/macro.d.mts
@@ -0,0 +1,2 @@
export * from './macro.js'
export { _default as default } from './macro.default.js'
3 changes: 3 additions & 0 deletions packages/native/macro.d.ts
@@ -0,0 +1,3 @@
import styled from '@emotion/native'
export * from '@emotion/native'
export default styled
1 change: 1 addition & 0 deletions packages/native/macro.default.d.ts
@@ -0,0 +1 @@
export { default as _default } from './macro.js'
10 changes: 8 additions & 2 deletions packages/native/package.json
Expand Up @@ -20,7 +20,7 @@
"src",
"dist",
"types/*.d.ts",
"macro.js"
"macro.*"
],
"types": "types/index.d.ts",
"devDependencies": {
Expand Down Expand Up @@ -56,7 +56,13 @@
"preconstruct": {
"exports": {
"extra": {
"./macro": "./macro.js"
"./macro": {
"types": {
"import": "./macro.d.mts",
"default": "./macro.d.ts"
},
"default": "./macro.js"
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/primitives/package.json
Expand Up @@ -6,7 +6,7 @@
"files": [
"src",
"dist",
"macro.js"
"macro.*"
],
"dependencies": {
"@emotion/babel-plugin": "^11.10.6",
Expand Down
1 change: 1 addition & 0 deletions packages/react/macro.d.mts
@@ -0,0 +1 @@
export * from './macro.js'
12 changes: 8 additions & 4 deletions packages/react/package.json
Expand Up @@ -55,9 +55,7 @@
"jsx-dev-runtime",
"_isolated-hnrs",
"types/*.d.ts",
"macro.js",
"macro.d.ts",
"macro.js.flow"
"macro.*"
],
"sideEffects": false,
"author": "Emotion Contributors",
Expand Down Expand Up @@ -114,7 +112,13 @@
],
"extra": {
"./types/css-prop": "./types/css-prop.d.ts",
"./macro": "./macro.js"
"./macro": {
"types": {
"import": "./macro.d.mts",
"default": "./macro.d.ts"
},
"default": "./macro.js"
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions packages/styled/macro.d.mts
@@ -0,0 +1,2 @@
export * from './macro.js'
export { _default as default } from './macro.default.js'
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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

Copy link
Member Author

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

Copy link
Member

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.

Copy link
Member Author

@Andarist Andarist May 4, 2023

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)

8 changes: 3 additions & 5 deletions packages/styled/macro.d.ts
@@ -1,5 +1,3 @@
declare module '@emotion/styled/macro' {
import styled from '@emotion/styled'
export * from '@emotion/styled'
export default styled
}
import styled from '@emotion/styled'
export * from '@emotion/styled'
export default styled
1 change: 1 addition & 0 deletions packages/styled/macro.default.d.ts
@@ -0,0 +1 @@
export { default as _default } from './macro.js'
12 changes: 8 additions & 4 deletions packages/styled/package.json
Expand Up @@ -41,9 +41,7 @@
"dist",
"base",
"types/*.d.ts",
"macro.d.ts",
"macro.js",
"macro.js.flow"
"macro.*"
],
"umd:main": "dist/emotion-styled.umd.min.js",
"browser": {
Expand Down Expand Up @@ -83,7 +81,13 @@
"worker"
],
"extra": {
"./macro": "./macro.js"
"./macro": {
"types": {
"import": "./macro.d.mts",
"default": "./macro.d.ts"
},
"default": "./macro.js"
}
}
}
}
Expand Down