Skip to content

Commit d8ff8a5

Browse files
authored
Update Preconstruct and use import conditions (#3198)
* Update Preconstruct and use import conditions * remove is-development redundant conditions * is-browser condition * default is-browser to a runtime check * remove top-level browser fields * remove top-level browser entries from extra entrypoints * remove yet another top-level browser field from an entrypoint * remove yet another top-level browser field from an entrypoint * use modern moduleResolution * fixes site config * add paths to handle older ts versions in type tests * fix dtslint, hopefully * use development condiiton by default in tests * try to run without the browser condition * add prod tests * fix gate types * hijack insertedRules * changesets
1 parent d57cfcb commit d8ff8a5

File tree

135 files changed

+998
-465
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+998
-465
lines changed

.changeset/tiny-jeans-check.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
'@emotion/cache': minor
3+
'@emotion/css': minor
4+
'@emotion/primitives-core': minor
5+
'@emotion/react': minor
6+
'@emotion/serialize': minor
7+
'@emotion/sheet': minor
8+
'@emotion/styled': minor
9+
'@emotion/use-insertion-effect-with-fallbacks': minor
10+
'@emotion/utils': minor
11+
---
12+
13+
Migrated away from relying on `process.env.NODE_ENV` checks to differentiate between production and development builds.
14+
15+
Development builds (and other environment-specific builds) can be used by using proper conditions (see [here](https://nodejs.org/docs/v20.15.1/api/packages.html#resolving-user-conditions)). Most modern bundlers/frameworks already preconfigure those for the user so no action has to be taken.
16+
17+
Default files should continue to work in all environments.

.changeset/witty-guests-care.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@emotion/jest': minor
3+
---
4+
5+
Adjustments to how speedy rules are obtained by the plugin.

.github/workflows/main.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ jobs:
5151
- name: Run Tests with React 18
5252
run: yarn test:react18:ci
5353

54+
test_prod:
55+
name: Test Prod
56+
runs-on: ubuntu-latest
57+
steps:
58+
- uses: actions/checkout@v3
59+
- uses: ./.github/actions/ci-setup
60+
61+
- name: Prod Tests
62+
run: yarn test:prod
63+
5464
test_dist:
5565
name: Test Dist
5666
runs-on: ubuntu-latest
@@ -59,7 +69,7 @@ jobs:
5969
- uses: ./.github/actions/ci-setup
6070

6171
- name: Dist Tests
62-
run: yarn test:prod
72+
run: yarn test:dist
6373

6474
linting:
6575
name: Linting

jest.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
module.exports = {
22
testEnvironment: 'jsdom',
3+
testEnvironmentOptions: {
4+
customExportConditions: ['development']
5+
},
36
transform: {
47
'^.+\\.(tsx|ts|js)?$': 'babel-jest'
58
},
@@ -13,7 +16,7 @@ module.exports = {
1316
'/site/',
1417
'/types/'
1518
],
16-
setupFilesAfterEnv: ['<rootDir>/test/testSetup.js'],
19+
setupFilesAfterEnv: ['test-utils/testSetup.js'],
1720
coveragePathIgnorePatterns: [
1821
'/node_modules/',
1922
'<rootDir>/packages/babel-plugin/test/util.js'

jest.prod.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const baseConfig = require('./jest.config.js')
2+
3+
module.exports = Object.assign({}, baseConfig, {
4+
testEnvironmentOptions: {
5+
...baseConfig.testEnvironmentOptions,
6+
customExportConditions:
7+
baseConfig.testEnvironmentOptions.customExportConditions.filter(
8+
c => c !== 'development'
9+
)
10+
}
11+
})

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"test:typescript": "yarn workspaces foreach --verbose --exclude emotion-monorepo run test:typescript",
1414
"test:ci": "jest --coverage --no-cache --ci --runInBand",
1515
"test:react18:ci": "yarn test:react18 --coverage --no-cache --ci --runInBand",
16-
"test:prod": "yarn build && jest -c jest.dist.js --no-cache --ci --runInBand",
16+
"test:dist": "yarn build && jest -c jest.dist.js --no-cache --ci --runInBand",
17+
"test:prod": "jest -c jest.prod.js --no-cache --ci --runInBand",
1718
"lint:check": "eslint .",
1819
"test:watch": "jest --watch",
1920
"size": "bundlesize",
@@ -131,6 +132,9 @@
131132
},
132133
"exports": {
133134
"importConditionDefaultExport": "default"
135+
},
136+
"___experimentalFlags_WILL_CHANGE_IN_PATCH": {
137+
"importsConditions": true
134138
}
135139
},
136140
"bugs": {
@@ -180,7 +184,7 @@
180184
"@changesets/changelog-github": "^0.5.0",
181185
"@changesets/cli": "^2.27.7",
182186
"@manypkg/cli": "^0.19.1",
183-
"@preconstruct/cli": "^2.6.2",
187+
"@preconstruct/cli": "^2.8.4",
184188
"@testing-library/react": "13.0.0-alpha.5",
185189
"@types/jest": "^29.5.12",
186190
"@types/node": "^12.20.37",

packages/babel-plugin-jsx-pragmatic/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
"module": "dist/emotion-babel-plugin-jsx-pragmatic.esm.js",
77
"exports": {
88
".": {
9+
"types": {
10+
"import": "./dist/emotion-babel-plugin-jsx-pragmatic.cjs.mjs",
11+
"default": "./dist/emotion-babel-plugin-jsx-pragmatic.cjs.js"
12+
},
913
"module": "./dist/emotion-babel-plugin-jsx-pragmatic.esm.js",
1014
"import": "./dist/emotion-babel-plugin-jsx-pragmatic.cjs.mjs",
1115
"default": "./dist/emotion-babel-plugin-jsx-pragmatic.cjs.js"

packages/babel-plugin/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
"module": "dist/emotion-babel-plugin.esm.js",
77
"exports": {
88
".": {
9+
"types": {
10+
"import": "./dist/emotion-babel-plugin.cjs.mjs",
11+
"default": "./dist/emotion-babel-plugin.cjs.js"
12+
},
913
"module": "./dist/emotion-babel-plugin.esm.js",
1014
"import": "./dist/emotion-babel-plugin.cjs.mjs",
1115
"default": "./dist/emotion-babel-plugin.cjs.js"

packages/babel-preset-css-prop/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
"module": "dist/emotion-babel-preset-css-prop.esm.js",
77
"exports": {
88
".": {
9+
"types": {
10+
"import": "./dist/emotion-babel-preset-css-prop.cjs.mjs",
11+
"default": "./dist/emotion-babel-preset-css-prop.cjs.js"
12+
},
913
"module": "./dist/emotion-babel-preset-css-prop.esm.js",
1014
"import": "./dist/emotion-babel-preset-css-prop.cjs.mjs",
1115
"default": "./dist/emotion-babel-preset-css-prop.cjs.js"

packages/cache/__tests__/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ test('throws correct error with invalid key', () => {
1111
}).toThrowErrorMatchingSnapshot()
1212
})
1313

14-
it('should accept insertionPoint option', () => {
14+
test('should accept insertionPoint option', () => {
1515
const head = safeQuerySelector('head')
1616

1717
head.innerHTML = `
@@ -34,7 +34,7 @@ it('should accept insertionPoint option', () => {
3434
expect(document.head).toMatchSnapshot()
3535
})
3636

37-
it('should accept container option', () => {
37+
test('should accept container option', () => {
3838
const body = safeQuerySelector('body')
3939

4040
body.innerHTML = `

0 commit comments

Comments
 (0)