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

Feat: generate bundles for "worker" style environement #2819

Merged
merged 11 commits into from
Jul 31, 2022
26 changes: 26 additions & 0 deletions .changeset/seven-ways-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
'@emotion/babel-plugin': minor
'@emotion/babel-plugin-jsx-pragmatic': minor
'@emotion/babel-preset-css-prop': minor
'@emotion/cache': minor
'@emotion/css': minor
'@emotion/css-prettifier': minor
'@emotion/eslint-plugin': minor
'@emotion/hash': minor
'@emotion/is-prop-valid': minor
'@emotion/jest': minor
'@emotion/memoize': minor
'@emotion/native': minor
'@emotion/primitives': minor
'@emotion/primitives-core': minor
'@emotion/react': minor
'@emotion/serialize': minor
'@emotion/server': minor
'@emotion/sheet': minor
'@emotion/styled': minor
'@emotion/unitless': minor
'@emotion/utils': minor
'@emotion/weak-memoize': minor
---

`exports` field has been added to the `package.json` manifest. This fixes how our default exports are treated by Node.js when using their native support for ES modules. It also limits what files can be imported from a package but we've tried our best to allow importing all the files that were considered to be a part of the public API.
7 changes: 7 additions & 0 deletions .changeset/wet-teachers-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@emotion/react': minor
'@emotion/styled': minor
'@emotion/utils': minor
---

Thanks to the added `exports` field, the package now includes a `worker` condition that can be utilized by properly configured bundlers when targeting worker-like environments. It fixes the issue with browser-specific files being prioritized by some bundlers when targeting workers.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@
"react": "React",
"react/jsx-runtime": "ReactJSX",
"react/jsx-dev-runtime": "ReactJSXDev"
},
"exports": true,
"___experimentalFlags_WILL_CHANGE_IN_PATCH": {
"exports": true
}
},
"bugs": {
Expand Down Expand Up @@ -183,7 +187,7 @@
"@changesets/changelog-github": "^0.4.0",
"@changesets/cli": "^2.16.0",
"@manypkg/cli": "^0.19.1",
"@preconstruct/cli": "^2.1.5",
"@preconstruct/cli": "^2.2.1",
"@testing-library/react": "13.0.0-alpha.5",
"@types/jest": "^27.0.3",
"@types/node": "^12.20.37",
Expand Down
7 changes: 7 additions & 0 deletions packages/babel-plugin-jsx-pragmatic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
"description": "Insert code to load a module corresponding to JSX pragma.",
"main": "dist/emotion-babel-plugin-jsx-pragmatic.cjs.js",
"module": "dist/emotion-babel-plugin-jsx-pragmatic.esm.js",
"exports": {
".": {
"module": "./dist/emotion-babel-plugin-jsx-pragmatic.esm.js",
"default": "./dist/emotion-babel-plugin-jsx-pragmatic.cjs.js"
},
"./package.json": "./package.json"
},
"license": "MIT",
"repository": "https://github.com/emotion-js/emotion/tree/main/packages/babel-plugin-jsx-pragmatic",
"scripts": {
Expand Down
7 changes: 7 additions & 0 deletions packages/babel-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
"description": "A recommended babel preprocessing plugin for emotion, The Next Generation of CSS-in-JS.",
"main": "dist/emotion-babel-plugin.cjs.js",
"module": "dist/emotion-babel-plugin.esm.js",
"exports": {
".": {
"module": "./dist/emotion-babel-plugin.esm.js",
"default": "./dist/emotion-babel-plugin.cjs.js"
},
"./package.json": "./package.json"
},
"files": [
"src",
"lib",
Expand Down
7 changes: 7 additions & 0 deletions packages/babel-preset-css-prop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
"description": "A babel preset to automatically enable emotion's css prop",
"main": "dist/emotion-babel-preset-css-prop.cjs.js",
"module": "dist/emotion-babel-preset-css-prop.esm.js",
"exports": {
".": {
"module": "./dist/emotion-babel-preset-css-prop.esm.js",
"default": "./dist/emotion-babel-preset-css-prop.cjs.js"
},
"./package.json": "./package.json"
},
"license": "MIT",
"repository": "https://github.com/emotion-js/emotion/tree/main/packages/babel-preset-css-prop",
"scripts": {
Expand Down
20 changes: 18 additions & 2 deletions packages/cache/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@
"main": "dist/emotion-cache.cjs.js",
"module": "dist/emotion-cache.esm.js",
"browser": {
"./dist/emotion-cache.cjs.js": "./dist/emotion-cache.browser.cjs.js",
"./dist/emotion-cache.esm.js": "./dist/emotion-cache.browser.esm.js"
},
"exports": {
".": {
"module": {
"browser": "./dist/emotion-cache.browser.esm.js",
"default": "./dist/emotion-cache.esm.js"
},
"default": "./dist/emotion-cache.cjs.js"
},
"./package.json": "./package.json"
},
"types": "types/index.d.ts",
"license": "MIT",
"repository": "https://github.com/emotion-js/emotion/tree/main/packages/cache",
Expand All @@ -33,5 +42,12 @@
"src",
"dist",
"types/*.d.ts"
]
],
"preconstruct": {
"exports": {
"envConditions": [
"browser"
]
}
}
}
2 changes: 2 additions & 0 deletions packages/cache/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from '../types'
export { default } from '../types'
7 changes: 7 additions & 0 deletions packages/css-prettifier/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
"author": "Mateusz Burzyński <mateuszburzynski@gmail.com> (https://github.com/Andarist)",
"main": "dist/emotion-css-prettifier.cjs.js",
"module": "dist/emotion-css-prettifier.esm.js",
"exports": {
".": {
"module": "./dist/emotion-css-prettifier.esm.js",
"default": "./dist/emotion-css-prettifier.cjs.js"
},
"./package.json": "./package.json"
},
"types": "types/index.d.ts",
"license": "MIT",
"repository": "https://github.com/emotion-js/emotion/tree/main/packages/css-prettifier",
Expand Down
2 changes: 2 additions & 0 deletions packages/css-prettifier/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from '../types'
export { default } from '../types'
19 changes: 18 additions & 1 deletion packages/css/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,28 @@
"url": "https://github.com/emotion-js/emotion/issues"
},
"umd:main": "dist/emotion-css.umd.min.js",
"exports": {
".": {
"module": "./dist/emotion-css.esm.js",
"default": "./dist/emotion-css.cjs.js"
},
"./create-instance": {
"module": "./create-instance/dist/emotion-css-create-instance.esm.js",
"default": "./create-instance/dist/emotion-css-create-instance.cjs.js"
},
"./package.json": "./package.json",
"./macro": "./macro.js"
},
"preconstruct": {
"umdName": "emotion",
"entrypoints": [
"./index.js",
"./create-instance.js"
]
],
"exports": {
"extra": {
"./macro": "./macro.js"
}
}
}
}
2 changes: 2 additions & 0 deletions packages/css/src/create-instance.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from '../types'
export { default } from '../types'
1 change: 1 addition & 0 deletions packages/css/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '../types'
8 changes: 8 additions & 0 deletions packages/eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
],
"author": "alex-pex <alexandre.paixao@stadline.com>",
"main": "dist/emotion-eslint-plugin.cjs.js",
"module": "dist/emotion-eslint-plugin.esm.js",
"exports": {
".": {
"module": "./dist/emotion-eslint-plugin.esm.js",
"default": "./dist/emotion-eslint-plugin.cjs.js"
},
"./package.json": "./package.json"
},
"engines": {
"node": ">=6"
},
Expand Down
9 changes: 6 additions & 3 deletions packages/hash/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
"@definitelytyped/dtslint": "0.0.112",
"typescript": "^4.5.5"
},
"browser": {
"./dist/emotion-hash.cjs.js": "./dist/emotion-hash.browser.cjs.js",
"./dist/emotion-hash.esm.js": "./dist/emotion-hash.browser.esm.js"
"exports": {
".": {
"module": "./dist/emotion-hash.esm.js",
"default": "./dist/emotion-hash.cjs.js"
},
"./package.json": "./package.json"
}
}
2 changes: 2 additions & 0 deletions packages/hash/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from '../types'
export { default } from '../types'
9 changes: 6 additions & 3 deletions packages/is-prop-valid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@
"dist",
"types/*.d.ts"
],
"browser": {
"./dist/emotion-is-prop-valid.cjs.js": "./dist/emotion-is-prop-valid.browser.cjs.js",
"./dist/emotion-is-prop-valid.esm.js": "./dist/emotion-is-prop-valid.browser.esm.js"
"exports": {
".": {
"module": "./dist/emotion-is-prop-valid.esm.js",
"default": "./dist/emotion-is-prop-valid.cjs.js"
},
"./package.json": "./package.json"
}
}
2 changes: 2 additions & 0 deletions packages/is-prop-valid/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from '../types'
export { default } from '../types'
19 changes: 19 additions & 0 deletions packages/jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@
"description": "Jest utilities for emotion",
"main": "dist/emotion-jest.cjs.js",
"module": "dist/emotion-jest.esm.js",
"exports": {
".": {
"module": "./dist/emotion-jest.esm.js",
"default": "./dist/emotion-jest.cjs.js"
},
"./enzyme": {
"module": "./enzyme/dist/emotion-jest-enzyme.esm.js",
"default": "./enzyme/dist/emotion-jest-enzyme.cjs.js"
},
"./serializer": {
"module": "./serializer/dist/emotion-jest-serializer.esm.js",
"default": "./serializer/dist/emotion-jest-serializer.cjs.js"
},
"./enzyme-serializer": {
"module": "./enzyme-serializer/dist/emotion-jest-enzyme-serializer.esm.js",
"default": "./enzyme-serializer/dist/emotion-jest-enzyme-serializer.cjs.js"
},
"./package.json": "./package.json"
},
"types": "types/index.d.ts",
"files": [
"src",
Expand Down
1 change: 1 addition & 0 deletions packages/jest/src/enzyme-serializer.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '../types/enzyme-serializer'
1 change: 1 addition & 0 deletions packages/jest/src/enzyme.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '../types/enzyme'
1 change: 1 addition & 0 deletions packages/jest/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '../types'
1 change: 1 addition & 0 deletions packages/jest/src/serializer.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '../types/serializer'
9 changes: 6 additions & 3 deletions packages/memoize/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
"dist",
"types/*.d.ts"
],
"browser": {
"./dist/emotion-memoize.cjs.js": "./dist/emotion-memoize.browser.cjs.js",
"./dist/emotion-memoize.esm.js": "./dist/emotion-memoize.browser.esm.js"
"exports": {
".": {
"module": "./dist/emotion-memoize.esm.js",
"default": "./dist/emotion-memoize.cjs.js"
},
"./package.json": "./package.json"
}
}
2 changes: 2 additions & 0 deletions packages/memoize/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from '../types'
export { default } from '../types'
17 changes: 14 additions & 3 deletions packages/native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
"description": "Style and render React Native components using emotion",
"main": "dist/emotion-native.cjs.js",
"module": "dist/emotion-native.esm.js",
"exports": {
".": {
"module": "./dist/emotion-native.esm.js",
"default": "./dist/emotion-native.cjs.js"
},
"./package.json": "./package.json",
"./macro": "./macro.js"
},
"scripts": {
"test:typescript": "dtslint types"
},
Expand Down Expand Up @@ -51,8 +59,11 @@
"publishConfig": {
"access": "public"
},
"browser": {
"./dist/emotion-native.cjs.js": "./dist/emotion-native.browser.cjs.js",
"./dist/emotion-native.esm.js": "./dist/emotion-native.browser.esm.js"
"preconstruct": {
"exports": {
"extra": {
"./macro": "./macro.js"
}
}
}
}
2 changes: 2 additions & 0 deletions packages/native/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from '../types'
export { default } from '../types'
17 changes: 17 additions & 0 deletions packages/native/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"jsx": "react",
"lib": ["es6", "dom"],
"module": "commonjs",
"noEmit": true,
"skipLibCheck": true,
"skipDefaultLibCheck": true,
"resolveJsonModule": true,
"strict": true,
"target": "es5",
"types": []
}
}
18 changes: 17 additions & 1 deletion packages/primitives-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,23 @@
"access": "public"
},
"browser": {
"./dist/emotion-primitives-core.cjs.js": "./dist/emotion-primitives-core.browser.cjs.js",
"./dist/emotion-primitives-core.esm.js": "./dist/emotion-primitives-core.browser.esm.js"
},
"exports": {
".": {
"module": {
"browser": "./dist/emotion-primitives-core.browser.esm.js",
"default": "./dist/emotion-primitives-core.esm.js"
},
"default": "./dist/emotion-primitives-core.cjs.js"
},
"./package.json": "./package.json"
},
"preconstruct": {
"exports": {
"envConditions": [
"browser"
]
}
}
}
22 changes: 21 additions & 1 deletion packages/primitives/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,27 @@
"access": "public"
},
"browser": {
"./dist/emotion-primitives.cjs.js": "./dist/emotion-primitives.browser.cjs.js",
"./dist/emotion-primitives.esm.js": "./dist/emotion-primitives.browser.esm.js"
},
"exports": {
".": {
"module": {
"browser": "./dist/emotion-primitives.browser.esm.js",
"default": "./dist/emotion-primitives.esm.js"
},
"default": "./dist/emotion-primitives.cjs.js"
},
"./package.json": "./package.json",
"./macro": "./macro.js"
},
"preconstruct": {
"exports": {
"extra": {
"./macro": "./macro.js"
},
"envConditions": [
"browser"
]
}
}
}
Loading