Skip to content

Commit 20f4579

Browse files
fix: React-Native package exports (#4887)
* Rename `tsup.config.ts` to `tsup.config.mts` * Fix `tsup` config * Fix `exports` field in `package.json` * Fix nested `package.json` files * Fix `fixUniqueSymbolExports.mts` * Explicitly disable `--experimental-require-module` - This is done to avoid the `module-sync` condition. * Bump `tsup` * Revert nested package `main` changes and fix "dist test" config * Maybe really fix dist tests * Point nested package RN fields to legacy-esm --------- Co-authored-by: Mark Erikson <[email protected]>
1 parent 5c1e01d commit 20f4579

File tree

13 files changed

+2392
-4060
lines changed

13 files changed

+2392
-4060
lines changed

.github/workflows/tests.yml

+12-5
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,21 @@ jobs:
114114
- name: Erase path aliases
115115
run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.base.json
116116

117-
- name: Run tests, against dist
118-
env:
119-
TEST_DIST: true
120-
run: yarn test
121-
122117
- name: Run type tests with `moduleResolution Bundler`
123118
run: rm -rf dist && yarn tsc -p . --moduleResolution Bundler --module ESNext --noEmit false --declaration --emitDeclarationOnly --outDir dist --target ESNext && rm -rf dist
124119

120+
- name: Ensure there's no dist folder
121+
run: rm -rf dist
122+
123+
- name: Change RTK package name to ensure node_modules is used
124+
run: sed -i -e 's|@reduxjs/toolkit|@reduxjs/toolkit-test|' ./package.json
125+
126+
- name: Run tests, against installed artifact
127+
env:
128+
TEST_DIST: true
129+
working-directory: ./packages/toolkit
130+
run: ../../node_modules/.bin/vitest --run --typecheck
131+
125132
test-types:
126133
name: 'Test Types: TS ${{ matrix.ts }} and React ${{ matrix.react.version }}'
127134

examples/publish-ci/node-esm/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"type": "module",
66
"scripts": {
77
"build": "echo Done",
8-
"test": "node test-cjs.cjs && node test-esm.mjs"
8+
"test": "node --no-experimental-require-module test-cjs.cjs && node test-esm.mjs"
99
},
1010
"dependencies": {
1111
"@reduxjs/toolkit": "^2.0.0-rc.3",

examples/publish-ci/node-standard/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"license": "MIT",
55
"scripts": {
66
"build": "echo Done",
7-
"test": "node test-cjs.js && node test-esm.mjs"
7+
"test": "node --no-experimental-require-module test-cjs.js && node test-esm.mjs"
88
},
99
"dependencies": {
1010
"@reduxjs/toolkit": "^2.0.0-rc.3",

packages/rtk-query-codegen-openapi/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"pretty-quick": "^4.0.0",
6969
"rimraf": "^5.0.5",
7070
"ts-node": "^10.9.2",
71-
"tsup": "^8.2.4",
71+
"tsup": "^8.4.0",
7272
"vite-tsconfig-paths": "^5.0.1",
7373
"vitest": "^2.0.5",
7474
"yalc": "^1.0.0-pre.47"

packages/toolkit/package.json

+124-14
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,137 @@
2525
"module": "dist/redux-toolkit.legacy-esm.js",
2626
"main": "dist/cjs/index.js",
2727
"types": "dist/index.d.ts",
28+
"react-native": "dist/redux-toolkit.legacy-esm.js",
29+
"unpkg": "dist/redux-toolkit.browser.mjs",
2830
"exports": {
2931
"./package.json": "./package.json",
3032
".": {
31-
"types": "./dist/index.d.ts",
32-
"import": "./dist/redux-toolkit.modern.mjs",
33-
"default": "./dist/cjs/index.js"
33+
"module-sync": {
34+
"types": "./dist/index.d.mts",
35+
"default": "./dist/redux-toolkit.modern.mjs"
36+
},
37+
"module": {
38+
"types": "./dist/index.d.mts",
39+
"default": "./dist/redux-toolkit.modern.mjs"
40+
},
41+
"react-native": {
42+
"import": {
43+
"types": "./dist/index.d.mts",
44+
"default": "./dist/redux-toolkit.modern.mjs"
45+
},
46+
"default": {
47+
"types": "./dist/index.d.ts",
48+
"default": "./dist/cjs/index.js"
49+
}
50+
},
51+
"browser": {
52+
"types": "./dist/index.d.mts",
53+
"default": "./dist/redux-toolkit.browser.mjs"
54+
},
55+
"import": {
56+
"types": "./dist/index.d.mts",
57+
"default": "./dist/redux-toolkit.modern.mjs"
58+
},
59+
"default": {
60+
"types": "./dist/index.d.ts",
61+
"default": "./dist/cjs/index.js"
62+
}
3463
},
3564
"./react": {
36-
"types": "./dist/react/index.d.ts",
37-
"import": "./dist/react/redux-toolkit-react.modern.mjs",
38-
"default": "./dist/react/cjs/index.js"
65+
"module-sync": {
66+
"types": "./dist/react/index.d.mts",
67+
"default": "./dist/react/redux-toolkit-react.modern.mjs"
68+
},
69+
"module": {
70+
"types": "./dist/react/index.d.mts",
71+
"default": "./dist/react/redux-toolkit-react.modern.mjs"
72+
},
73+
"react-native": {
74+
"import": {
75+
"types": "./dist/react/index.d.mts",
76+
"default": "./dist/react/redux-toolkit-react.modern.mjs"
77+
},
78+
"default": {
79+
"types": "./dist/react/index.d.ts",
80+
"default": "./dist/react/cjs/index.js"
81+
}
82+
},
83+
"browser": {
84+
"types": "./dist/react/index.d.mts",
85+
"default": "./dist/react/redux-toolkit-react.browser.mjs"
86+
},
87+
"import": {
88+
"types": "./dist/react/index.d.mts",
89+
"default": "./dist/react/redux-toolkit-react.modern.mjs"
90+
},
91+
"default": {
92+
"types": "./dist/react/index.d.ts",
93+
"default": "./dist/react/cjs/index.js"
94+
}
3995
},
4096
"./query": {
41-
"types": "./dist/query/index.d.ts",
42-
"import": "./dist/query/rtk-query.modern.mjs",
43-
"default": "./dist/query/cjs/index.js"
97+
"module-sync": {
98+
"types": "./dist/query/index.d.mts",
99+
"default": "./dist/query/rtk-query.modern.mjs"
100+
},
101+
"module": {
102+
"types": "./dist/query/index.d.mts",
103+
"default": "./dist/query/rtk-query.modern.mjs"
104+
},
105+
"react-native": {
106+
"import": {
107+
"types": "./dist/query/index.d.mts",
108+
"default": "./dist/query/rtk-query.modern.mjs"
109+
},
110+
"default": {
111+
"types": "./dist/query/index.d.ts",
112+
"default": "./dist/query/cjs/index.js"
113+
}
114+
},
115+
"browser": {
116+
"types": "./dist/query/index.d.mts",
117+
"default": "./dist/query/rtk-query.browser.mjs"
118+
},
119+
"import": {
120+
"types": "./dist/query/index.d.mts",
121+
"default": "./dist/query/rtk-query.modern.mjs"
122+
},
123+
"default": {
124+
"types": "./dist/query/index.d.ts",
125+
"default": "./dist/query/cjs/index.js"
126+
}
44127
},
45128
"./query/react": {
46-
"types": "./dist/query/react/index.d.ts",
47-
"import": "./dist/query/react/rtk-query-react.modern.mjs",
48-
"default": "./dist/query/react/cjs/index.js"
129+
"module-sync": {
130+
"types": "./dist/query/react/index.d.mts",
131+
"default": "./dist/query/react/rtk-query-react.modern.mjs"
132+
},
133+
"module": {
134+
"types": "./dist/query/react/index.d.mts",
135+
"default": "./dist/query/react/rtk-query-react.modern.mjs"
136+
},
137+
"react-native": {
138+
"import": {
139+
"types": "./dist/query/react/index.d.mts",
140+
"default": "./dist/query/react/rtk-query-react.modern.mjs"
141+
},
142+
"default": {
143+
"types": "./dist/query/react/index.d.ts",
144+
"default": "./dist/query/react/cjs/index.js"
145+
}
146+
},
147+
"browser": {
148+
"types": "./dist/query/react/index.d.mts",
149+
"default": "./dist/query/react/rtk-query-react.browser.mjs"
150+
},
151+
"import": {
152+
"types": "./dist/query/react/index.d.mts",
153+
"default": "./dist/query/react/rtk-query-react.modern.mjs"
154+
},
155+
"default": {
156+
"types": "./dist/query/react/index.d.ts",
157+
"default": "./dist/query/react/cjs/index.js"
158+
}
49159
}
50160
},
51161
"devDependencies": {
@@ -96,7 +206,7 @@
96206
"rimraf": "^3.0.2",
97207
"size-limit": "^11.0.1",
98208
"tslib": "^1.10.0",
99-
"tsup": "^8.2.3",
209+
"tsup": "^8.4.0",
100210
"tsx": "^4.19.0",
101211
"typescript": "^5.8.2",
102212
"valibot": "^1.0.0",
@@ -106,7 +216,7 @@
106216
},
107217
"scripts": {
108218
"clean": "rimraf dist",
109-
"run-build": "tsup",
219+
"run-build": "tsup --config=$INIT_CWD/tsup.config.mts",
110220
"build": "yarn clean && yarn run-build && tsx scripts/fixUniqueSymbolExports.mts",
111221
"build-only": "yarn clean && yarn run-build",
112222
"format": "prettier --write \"(src|examples)/**/*.{ts,tsx}\" \"**/*.md\"",

packages/toolkit/query/package.json

+1-8
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,7 @@
66
"module": "../dist/query/rtk-query.legacy-esm.js",
77
"main": "../dist/query/cjs/index.js",
88
"types": "./../dist/query/index.d.ts",
9-
"exports": {
10-
"./package.json": "./package.json",
11-
".": {
12-
"types": "./../dist/query/index.d.ts",
13-
"import": "./../dist/query/rtk-query.modern.mjs",
14-
"default": "./../dist/query/cjs/index.js"
15-
}
16-
},
9+
"react-native": "./../dist/query/rtk-query.legacy-esm.js",
1710
"author": "Mark Erikson <[email protected]>",
1811
"license": "MIT",
1912
"sideEffects": false

packages/toolkit/query/react/package.json

+1-8
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,7 @@
66
"module": "../../dist/query/react/rtk-query-react.legacy-esm.js",
77
"main": "../../dist/query/react/cjs/index.js",
88
"types": "./../../dist/query/react/index.d.ts",
9-
"exports": {
10-
"./package.json": "./package.json",
11-
".": {
12-
"types": "./../../dist/query/react/index.d.ts",
13-
"import": "./../../dist/query/react/rtk-query-react.modern.mjs",
14-
"default": "./../../dist/query/react/cjs/index.js"
15-
}
16-
},
9+
"react-native": "./../../dist/query/react/rtk-query-react.legacy-esm.js",
1710
"author": "Mark Erikson <[email protected]>",
1811
"license": "MIT",
1912
"sideEffects": false

packages/toolkit/react/package.json

+2-9
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,9 @@
44
"description": "",
55
"type": "module",
66
"module": "../dist/react/redux-toolkit-react.legacy-esm.js",
7-
"main": "../dist/react/cjs/index.js",
7+
"main": "./../dist/react/redux-toolkit-react.modern.mjs",
88
"types": "./../dist/react/index.d.ts",
9-
"exports": {
10-
"./package.json": "./package.json",
11-
".": {
12-
"types": "./../dist/react/index.d.ts",
13-
"import": "./../dist/react/redux-toolkit-react.modern.mjs",
14-
"default": "./../dist/react/cjs/index.js"
15-
}
16-
},
9+
"react-native": "./../dist/react/redux-toolkit-react.modern.mjs",
1710
"author": "Mark Erikson <[email protected]>",
1811
"license": "MIT",
1912
"sideEffects": false

packages/toolkit/scripts/fixUniqueSymbolExports.mts

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
#!/usr/bin/env node --import=tsx
22

3-
import fs from 'node:fs/promises'
4-
import path from 'node:path'
5-
import { fileURLToPath } from 'node:url'
6-
7-
const __dirname = fileURLToPath(new URL('.', import.meta.url))
3+
import * as fs from 'node:fs/promises'
4+
import * as path from 'node:path'
85

96
const entryPointDirectories = ['', 'react', 'query', 'query/react']
107

11-
const typeDefinitionEntryFiles = entryPointDirectories.map((filePath) =>
12-
path.resolve(__dirname, '..', 'dist', filePath, 'index.d.ts'),
8+
const typeDefinitionEntryFiles = entryPointDirectories.flatMap(
9+
(filePath) =>
10+
[
11+
path.join(import.meta.dirname, '..', 'dist', filePath, 'index.d.ts'),
12+
path.join(import.meta.dirname, '..', 'dist', filePath, 'index.d.mts'),
13+
] as const,
1314
)
1415

1516
const filePathsToContentMap = new Map<string, string>(
1617
await Promise.all(
1718
typeDefinitionEntryFiles.map(
1819
async (filePath) =>
19-
[filePath, await fs.readFile(filePath, 'utf-8')] as const,
20+
[filePath, await fs.readFile(filePath, { encoding: 'utf-8' })] as const,
2021
),
2122
),
2223
)
@@ -30,8 +31,8 @@ const main = async () => {
3031
const lines = content.split('\n')
3132

3233
const allUniqueSymbols = lines
33-
.filter((line) => /declare const (\w+)\: unique symbol;/.test(line))
34-
.map((line) => line.match(/declare const (\w+)\: unique symbol;/)?.[1])
34+
.filter((line) => /declare const (\w+): unique symbol;/.test(line))
35+
.map((line) => line.match(/declare const (\w+): unique symbol;/)?.[1])
3536

3637
if (allUniqueSymbols.length === 0) {
3738
console.log(`${filePath} does not have any unique symbols.`)
@@ -69,8 +70,8 @@ const main = async () => {
6970
)
7071
})
7172

72-
await fs.writeFile(filePath, newContent)
73+
await fs.writeFile(filePath, newContent, { encoding: 'utf-8' })
7374
})
7475
}
7576

76-
main()
77+
void main()

0 commit comments

Comments
 (0)