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 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .changeset/perfect-otters-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
'@emotion/babel-plugin': patch
'@emotion/babel-plugin-jsx-pragmatic': patch
'@emotion/babel-preset-css-prop': patch
'@emotion/cache': patch
'@emotion/css': patch
'@emotion/css-prettifier': patch
'@emotion/eslint-plugin': patch
'@emotion/hash': patch
'@emotion/is-prop-valid': patch
'@emotion/jest': patch
'@emotion/memoize': patch
'@emotion/native': patch
'@emotion/primitives': patch
'@emotion/primitives-core': patch
'@emotion/react': patch
'@emotion/serialize': patch
'@emotion/server': patch
'@emotion/sheet': patch
'@emotion/styled': patch
'@emotion/unitless': patch
'@emotion/use-insertion-effect-with-fallbacks': patch
'@emotion/utils': patch
'@emotion/weak-memoize': patch
---

Fixed importing in Node ESM
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,8 @@
"react/jsx-runtime": "ReactJSX",
"react/jsx-dev-runtime": "ReactJSXDev"
},
"exports": true,
"___experimentalFlags_WILL_CHANGE_IN_PATCH": {
"exports": true
"exports": {
"importConditionDefaultExport": "default"
}
},
"bugs": {
Expand Down Expand Up @@ -181,7 +180,7 @@
"@changesets/changelog-github": "^0.4.0",
"@changesets/cli": "^2.16.0",
"@manypkg/cli": "^0.19.1",
"@preconstruct/cli": "^2.2.1",
"@preconstruct/cli": "^2.6.2",
"@testing-library/react": "13.0.0-alpha.5",
"@types/jest": "^27.0.3",
"@types/node": "^12.20.37",
Expand Down
1 change: 1 addition & 0 deletions packages/babel-plugin-jsx-pragmatic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"exports": {
".": {
"module": "./dist/emotion-babel-plugin-jsx-pragmatic.esm.js",
"import": "./dist/emotion-babel-plugin-jsx-pragmatic.cjs.mjs",
"default": "./dist/emotion-babel-plugin-jsx-pragmatic.cjs.js"
},
"./package.json": "./package.json"
Expand Down
1 change: 1 addition & 0 deletions packages/babel-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"exports": {
".": {
"module": "./dist/emotion-babel-plugin.esm.js",
"import": "./dist/emotion-babel-plugin.cjs.mjs",
"default": "./dist/emotion-babel-plugin.cjs.js"
},
"./package.json": "./package.json"
Expand Down
1 change: 1 addition & 0 deletions packages/babel-preset-css-prop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"exports": {
".": {
"module": "./dist/emotion-babel-preset-css-prop.esm.js",
"import": "./dist/emotion-babel-preset-css-prop.cjs.mjs",
"default": "./dist/emotion-babel-preset-css-prop.cjs.js"
},
"./package.json": "./package.json"
Expand Down
1 change: 1 addition & 0 deletions packages/cache/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"browser": "./dist/emotion-cache.browser.esm.js",
"default": "./dist/emotion-cache.esm.js"
},
"import": "./dist/emotion-cache.cjs.mjs",
"default": "./dist/emotion-cache.cjs.js"
},
"./package.json": "./package.json"
Expand Down
1 change: 1 addition & 0 deletions packages/css-prettifier/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"exports": {
".": {
"module": "./dist/emotion-css-prettifier.esm.js",
"import": "./dist/emotion-css-prettifier.cjs.mjs",
"default": "./dist/emotion-css-prettifier.cjs.js"
},
"./package.json": "./package.json"
Expand Down
1 change: 1 addition & 0 deletions packages/css/macro.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './macro.js'
14 changes: 10 additions & 4 deletions packages/css/package.json
Original file line number Diff line number Diff line change
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 @@ -46,10 +44,12 @@
"exports": {
".": {
"module": "./dist/emotion-css.esm.js",
"import": "./dist/emotion-css.cjs.mjs",
"default": "./dist/emotion-css.cjs.js"
},
"./create-instance": {
"module": "./create-instance/dist/emotion-css-create-instance.esm.js",
"import": "./create-instance/dist/emotion-css-create-instance.cjs.mjs",
"default": "./create-instance/dist/emotion-css-create-instance.cjs.js"
},
"./package.json": "./package.json",
Expand All @@ -63,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
1 change: 1 addition & 0 deletions packages/eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"exports": {
".": {
"module": "./dist/emotion-eslint-plugin.esm.js",
"import": "./dist/emotion-eslint-plugin.cjs.mjs",
"default": "./dist/emotion-eslint-plugin.cjs.js"
},
"./package.json": "./package.json"
Expand Down
1 change: 1 addition & 0 deletions packages/hash/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"exports": {
".": {
"module": "./dist/emotion-hash.esm.js",
"import": "./dist/emotion-hash.cjs.mjs",
"default": "./dist/emotion-hash.cjs.js"
},
"./package.json": "./package.json"
Expand Down
1 change: 1 addition & 0 deletions packages/is-prop-valid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"exports": {
".": {
"module": "./dist/emotion-is-prop-valid.esm.js",
"import": "./dist/emotion-is-prop-valid.cjs.mjs",
"default": "./dist/emotion-is-prop-valid.cjs.js"
},
"./package.json": "./package.json"
Expand Down
4 changes: 4 additions & 0 deletions packages/jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@
"exports": {
".": {
"module": "./dist/emotion-jest.esm.js",
"import": "./dist/emotion-jest.cjs.mjs",
"default": "./dist/emotion-jest.cjs.js"
},
"./enzyme": {
"module": "./enzyme/dist/emotion-jest-enzyme.esm.js",
"import": "./enzyme/dist/emotion-jest-enzyme.cjs.mjs",
"default": "./enzyme/dist/emotion-jest-enzyme.cjs.js"
},
"./serializer": {
"module": "./serializer/dist/emotion-jest-serializer.esm.js",
"import": "./serializer/dist/emotion-jest-serializer.cjs.mjs",
"default": "./serializer/dist/emotion-jest-serializer.cjs.js"
},
"./enzyme-serializer": {
"module": "./enzyme-serializer/dist/emotion-jest-enzyme-serializer.esm.js",
"import": "./enzyme-serializer/dist/emotion-jest-enzyme-serializer.cjs.mjs",
"default": "./enzyme-serializer/dist/emotion-jest-enzyme-serializer.cjs.js"
},
"./package.json": "./package.json"
Expand Down
1 change: 1 addition & 0 deletions packages/memoize/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"exports": {
".": {
"module": "./dist/emotion-memoize.esm.js",
"import": "./dist/emotion-memoize.cjs.mjs",
"default": "./dist/emotion-memoize.cjs.js"
},
"./package.json": "./package.json"
Expand Down
2 changes: 2 additions & 0 deletions packages/native/macro.d.mts
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as _default } from './macro.js'
11 changes: 9 additions & 2 deletions packages/native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"exports": {
".": {
"module": "./dist/emotion-native.esm.js",
"import": "./dist/emotion-native.cjs.mjs",
"default": "./dist/emotion-native.cjs.js"
},
"./package.json": "./package.json",
Expand All @@ -19,7 +20,7 @@
"src",
"dist",
"types/*.d.ts",
"macro.js"
"macro.*"
],
"types": "types/index.d.ts",
"devDependencies": {
Expand Down Expand Up @@ -55,7 +56,13 @@
"preconstruct": {
"exports": {
"extra": {
"./macro": "./macro.js"
"./macro": {
"types": {
"import": "./macro.d.mts",
"default": "./macro.d.ts"
},
"default": "./macro.js"
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/primitives-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"browser": "./dist/emotion-primitives-core.browser.esm.js",
"default": "./dist/emotion-primitives-core.esm.js"
},
"import": "./dist/emotion-primitives-core.cjs.mjs",
"default": "./dist/emotion-primitives-core.cjs.js"
},
"./package.json": "./package.json"
Expand Down
3 changes: 2 additions & 1 deletion packages/primitives/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"files": [
"src",
"dist",
"macro.js"
"macro.*"
],
"dependencies": {
"@emotion/babel-plugin": "^11.10.6",
Expand Down Expand Up @@ -49,6 +49,7 @@
"browser": "./dist/emotion-primitives.browser.esm.js",
"default": "./dist/emotion-primitives.esm.js"
},
"import": "./dist/emotion-primitives.cjs.mjs",
"default": "./dist/emotion-primitives.cjs.js"
},
"./package.json": "./package.json",
Expand Down
1 change: 1 addition & 0 deletions packages/react/macro.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './macro.js'
16 changes: 12 additions & 4 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"browser": "./dist/emotion-react.browser.esm.js",
"default": "./dist/emotion-react.esm.js"
},
"import": "./dist/emotion-react.cjs.mjs",
"default": "./dist/emotion-react.cjs.js"
},
"./jsx-runtime": {
Expand All @@ -21,6 +22,7 @@
"browser": "./jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js",
"default": "./jsx-runtime/dist/emotion-react-jsx-runtime.esm.js"
},
"import": "./jsx-runtime/dist/emotion-react-jsx-runtime.cjs.mjs",
"default": "./jsx-runtime/dist/emotion-react-jsx-runtime.cjs.js"
},
"./_isolated-hnrs": {
Expand All @@ -29,6 +31,7 @@
"browser": "./_isolated-hnrs/dist/emotion-react-_isolated-hnrs.browser.esm.js",
"default": "./_isolated-hnrs/dist/emotion-react-_isolated-hnrs.esm.js"
},
"import": "./_isolated-hnrs/dist/emotion-react-_isolated-hnrs.cjs.mjs",
"default": "./_isolated-hnrs/dist/emotion-react-_isolated-hnrs.cjs.js"
},
"./jsx-dev-runtime": {
Expand All @@ -37,6 +40,7 @@
"browser": "./jsx-dev-runtime/dist/emotion-react-jsx-dev-runtime.browser.esm.js",
"default": "./jsx-dev-runtime/dist/emotion-react-jsx-dev-runtime.esm.js"
},
"import": "./jsx-dev-runtime/dist/emotion-react-jsx-dev-runtime.cjs.mjs",
"default": "./jsx-dev-runtime/dist/emotion-react-jsx-dev-runtime.cjs.js"
},
"./package.json": "./package.json",
Expand All @@ -51,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 @@ -110,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
1 change: 1 addition & 0 deletions packages/serialize/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"browser": "./dist/emotion-serialize.browser.esm.js",
"default": "./dist/emotion-serialize.esm.js"
},
"import": "./dist/emotion-serialize.cjs.mjs",
"default": "./dist/emotion-serialize.cjs.js"
},
"./package.json": "./package.json"
Expand Down
2 changes: 2 additions & 0 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@
"browser": "./dist/emotion-server.browser.esm.js",
"default": "./dist/emotion-server.esm.js"
},
"import": "./dist/emotion-server.cjs.mjs",
"default": "./dist/emotion-server.cjs.js"
},
"./create-instance": {
"module": {
"browser": "./create-instance/dist/emotion-server-create-instance.browser.esm.js",
"default": "./create-instance/dist/emotion-server-create-instance.esm.js"
},
"import": "./create-instance/dist/emotion-server-create-instance.cjs.mjs",
"default": "./create-instance/dist/emotion-server-create-instance.cjs.js"
},
"./package.json": "./package.json"
Expand Down
1 change: 1 addition & 0 deletions packages/sheet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"browser": "./dist/emotion-sheet.browser.esm.js",
"default": "./dist/emotion-sheet.esm.js"
},
"import": "./dist/emotion-sheet.cjs.mjs",
"default": "./dist/emotion-sheet.cjs.js"
},
"./package.json": "./package.json"
Expand Down
2 changes: 2 additions & 0 deletions packages/styled/macro.d.mts
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as _default } from './macro.js'
14 changes: 10 additions & 4 deletions packages/styled/package.json
Original file line number Diff line number Diff line change
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 All @@ -56,6 +54,7 @@
"browser": "./base/dist/emotion-styled-base.browser.esm.js",
"default": "./base/dist/emotion-styled-base.esm.js"
},
"import": "./base/dist/emotion-styled-base.cjs.mjs",
"default": "./base/dist/emotion-styled-base.cjs.js"
},
".": {
Expand All @@ -64,6 +63,7 @@
"browser": "./dist/emotion-styled.browser.esm.js",
"default": "./dist/emotion-styled.esm.js"
},
"import": "./dist/emotion-styled.cjs.mjs",
"default": "./dist/emotion-styled.cjs.js"
},
"./package.json": "./package.json",
Expand All @@ -81,7 +81,13 @@
"worker"
],
"extra": {
"./macro": "./macro.js"
"./macro": {
"types": {
"import": "./macro.d.mts",
"default": "./macro.d.ts"
},
"default": "./macro.js"
}
}
}
}
Expand Down
Loading