Skip to content

Commit 3be609a

Browse files
committed
Merge branch 'master' into more-typed-wrappers
2 parents baaeff3 + 378e3e0 commit 3be609a

File tree

11 files changed

+510
-1604
lines changed

11 files changed

+510
-1604
lines changed

.github/workflows/size.yml.bak renamed to .github/workflows/size.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ jobs:
77
CI_JOB_NUMBER: 1
88
steps:
99
- uses: actions/checkout@v2
10-
- uses: andresz1/size-limit-action@v1
10+
- uses: EskiMojo14/size-limit-action@v1
1111
with:
1212
directory: packages/toolkit
1313
github_token: ${{ secrets.GITHUB_TOKEN }}
1414
build_script: build-only
15+
package_manager: yarn
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
diff --git a/get-config.js b/get-config.js
2+
index 76ebaee5455b2a4bacb986784bd1b53ad89adeb7..1b092e645b258f4a6533ca88b7d36dbcde4eb6de 100644
3+
--- a/get-config.js
4+
+++ b/get-config.js
5+
@@ -132,7 +132,7 @@ export default async function getConfig(plugins, process, args, pkg) {
6+
} else if (!check.entry) {
7+
if (pkg.packageJson.main) {
8+
processed.files = [
9+
- require.resolve(join(dirname(pkg.path), pkg.packageJson.main))
10+
+ import.meta.resolve(join(dirname(pkg.path), pkg.packageJson.main))
11+
]
12+
} else {
13+
processed.files = [join(dirname(pkg.path), 'index.js')]
14+
@@ -177,7 +177,7 @@ export default async function getConfig(plugins, process, args, pkg) {
15+
for (let i in check.import) {
16+
if (peer.includes(i)) {
17+
check.ignore = check.ignore.filter(j => j !== i)
18+
- imports[require.resolve(i, config.cwd)] = check.import[i]
19+
+ imports[import.meta.resolve(i, config.cwd)] = check.import[i]
20+
} else {
21+
imports[toAbsolute(i, config.cwd)] = check.import[i]
22+
}

CONTRIBUTING.md

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,59 @@ Before opening an issue, please search the [issue tracker](https://github.com/re
88

99
Please ask any general and implementation specific questions on [Stack Overflow with a Redux Toolkit tag](http://stackoverflow.com/questions/tagged/redux-toolkit?sort=votes&pageSize=50) for support.
1010

11-
## New Features
11+
We ask you to do this because StackOverflow has a much better job at keeping popular questions visible. Unfortunately good answers get lost and outdated on GitHub.
1212

13-
Please open an issue with a proposal for a new feature or refactoring before starting on the work. We don't want you to waste your efforts on a pull request that we won't want to accept.
13+
If your question gets closed or you don't get a reply after a few days, consider opening a [discussion](https://github.com/reduxjs/redux-toolkit/discussions) or joining the [Reactiflux](https://discord.gg/reactiflux) discord server and asking in the #redux channel.
14+
15+
### Help Us Help You
16+
17+
On both websites, it is a good idea to structure your code and question in a way that is easy to read to help people to answer it. For example, we encourage you to use syntax highlighting, indentation, and split text in paragraphs.
18+
19+
Please keep in mind that people spend their free time trying to help you. You can make it easier for them if you provide versions of the relevant libraries and a runnable small project reproducing your issue. You can put your code on [JSBin](https://jsbin.com) or, for bigger projects, on GitHub. Make sure all the necessary dependencies are declared in `package.json` so anyone can run `npm install && npm start` and reproduce your issue.
20+
21+
## Ways You Can Contribute
22+
23+
There are several ways you can contribute to the repository. Instead of developing a feature or fixing a bug, you can also contribute by updating or writing [documentation](https://github.com/reduxjs/redux-toolkit/tree/master/docs) for a specific feature or implementation if you know you are good with documentation. Alternatively, you can add [examples](https://github.com/reduxjs/redux-toolkit/tree/master/examples) of any 3rd party implementation like GraphQL or React (just an example) that would help users to understand and easily integrate Redux Toolkit with that specific framework and library.
1424

1525
## Getting started
1626

1727
Visit the [Issue tracker](https://github.com/reduxjs/redux-toolkit/issues) to find a list of open issues that need attention.
1828

29+
### Bugs and Improvements
30+
31+
We use the [Issue tracker](https://github.com/reduxjs/redux-toolkit/issues) to keep track of bugs and improvements to Redux Toolkit itself, its examples, and the documentation. We encourage you to open issues to discuss improvements, architecture, theory, internal implementation, etc. If a topic has been discussed before, we will ask you to join the previous discussion.
32+
33+
### New Features
34+
35+
Please open an [issue](https://github.com/reduxjs/redux-toolkit/issues) with a proposal for a new feature or refactoring before starting on the work. We don't want you to waste your efforts on a pull request that we won't want to accept.
36+
1937
### Fork the repository
2038

2139
Please use the GitHub UI to [fork this repository](https://github.com/reduxjs/redux-toolkit) (_read more about [Forking a repository](https://docs.github.com/en/github/getting-started-with-github/fork-a-repo)_). Redux Toolkit has forked builds enabled in the CI, so you will see the build status of your fork's branch.
2240

41+
![Fork Button](https://docs.github.com/assets/cb-40742/mw-1440/images/help/repository/fork-button.webp)
42+
43+
Fork, then clone the repo:
44+
45+
```sh
46+
git clone https://github.com/your-username/redux-toolkit.git
47+
```
48+
2349
### Install
2450

2551
```bash
2652
$ cd redux-toolkit
2753
$ yarn
2854
```
2955

56+
### Build
57+
58+
You can build the packages with the following command:
59+
60+
```
61+
yarn build
62+
```
63+
3064
### Tests
3165

3266
You can run tests for all packages with:
@@ -41,14 +75,6 @@ To continuously watch and run tests, run the following:
4175
yarn test --watch
4276
```
4377

44-
### Build
45-
46-
You can build the packages with the following command:
47-
48-
```
49-
yarn build
50-
```
51-
5278
## Git workflow / Submitting Changes
5379

5480
- Open a new issue in the [Issue tracker](https://github.com/reduxjs/redux-toolkit/issues).

docs/api/createSlice.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ create.preparedReducer(
240240

241241
Creates an async thunk instead of an action creator.
242242

243-
:::warning Setup
243+
:::caution Setup
244244

245245
To avoid pulling `createAsyncThunk` into the bundle size of `createSlice` by default, some extra setup is required to use `create.asyncThunk`.
246246

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"@types/jest": "^27",
4040
"@types/lodash": "^4.14.165",
4141
"@types/node": "^14.14.12",
42+
"@types/node-fetch": "^2.6.11",
4243
"@types/prettier": "^2.1.6",
4344
"@types/semver": "^7.3.9",
4445
"babel-jest": "^26.6.3",
@@ -49,6 +50,7 @@
4950
"husky": "^4.3.6",
5051
"jest": "^29",
5152
"msw": "^0.40.2",
53+
"node-fetch": "^2.7.0",
5254
"openapi-types": "^9.1.0",
5355
"pretty-quick": "^3.1.0",
5456
"ts-jest": "^29",

packages/toolkit/.size-limit.js renamed to packages/toolkit/.size-limit.cjs

Lines changed: 76 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,84 @@
11
const webpack = require('webpack')
22
let { join } = require('path')
33

4-
const suffixes = ['cjs.production.min.js', 'esm.js']
4+
const esmSuffixes = ['modern.mjs', 'browser.mjs', 'legacy-esm.js']
5+
const cjsSuffixes = ['development.cjs', 'production.min.cjs']
56

6-
function withRtkPath(suffix) {
7+
function withRtkPath(suffix, cjs = false) {
8+
/**
9+
* @param {string} name
10+
*/
11+
function alias(name) {
12+
return `${cjs ? 'cjs/' : ''}${name}.${suffix}`
13+
}
14+
/**
15+
* @param {webpack.Configuration} config
16+
*/
717
return (config) => {
818
config.plugins.push(
919
new webpack.NormalModuleReplacementPlugin(
1020
/@reduxjs\/toolkit\/query\/react/,
11-
join(__dirname, `query/react`),
21+
join(__dirname, 'dist/query/react/rtk-query-react.modern.mjs'),
1222
),
1323
new webpack.NormalModuleReplacementPlugin(
1424
/@reduxjs\/toolkit\/query/,
15-
join(__dirname, `query`),
25+
join(__dirname, 'dist/query/rtk-query.modern.mjs'),
26+
),
27+
new webpack.NormalModuleReplacementPlugin(
28+
/@reduxjs\/toolkit\/react/,
29+
join(__dirname, 'dist/react/redux-toolkit-react.modern.mjs'),
1630
),
1731
new webpack.NormalModuleReplacementPlugin(
1832
/@reduxjs\/toolkit/,
19-
join(__dirname),
33+
join(__dirname, 'dist/redux-toolkit.modern.mjs'),
2034
),
2135
new webpack.NormalModuleReplacementPlugin(
22-
/rtk-query-react.modern.js/,
36+
/rtk-query-react.modern.mjs/,
2337
(r) => {
2438
const old = r.request
2539
r.request = r.request.replace(
26-
/rtk-query-react.modern.js$/,
27-
`rtk-query-react.${suffix}`,
40+
/rtk-query-react.modern.mjs$/,
41+
alias('rtk-query-react'),
2842
)
29-
// console.log(old, '=>', r.request)
43+
//console.log(old, '=>', r.request)
3044
},
3145
),
32-
new webpack.NormalModuleReplacementPlugin(/rtk-query.modern.js/, (r) => {
46+
new webpack.NormalModuleReplacementPlugin(/rtk-query.modern.mjs/, (r) => {
3347
const old = r.request
3448
r.request = r.request.replace(
35-
/rtk-query.modern.js$/,
36-
`rtk-query.${suffix}`,
49+
/rtk-query.modern.mjs$/,
50+
alias('rtk-query'),
3751
)
38-
// console.log(old, '=>', r.request)
52+
//console.log(old, '=>', r.request)
3953
}),
4054
new webpack.NormalModuleReplacementPlugin(
41-
/redux-toolkit.modern.js$/,
55+
/redux-toolkit-react.modern.mjs$/,
56+
(r) => {
57+
const old = r.request
58+
r.request = r.request.replace(
59+
/redux-toolkit-react.modern.mjs$/,
60+
alias('redux-toolkit-react'),
61+
)
62+
//console.log(old, '=>', r.request)
63+
},
64+
),
65+
new webpack.NormalModuleReplacementPlugin(
66+
/redux-toolkit.modern.mjs$/,
4267
(r) => {
4368
const old = r.request
4469
r.request = r.request.replace(
45-
/redux-toolkit.modern.js$/,
46-
`redux-toolkit.${suffix}`,
70+
/redux-toolkit.modern.mjs$/,
71+
alias('redux-toolkit'),
4772
)
48-
// console.log(old, '=>', r.request)
73+
//console.log(old, '=>', r.request)
4974
},
5075
),
5176
)
52-
if (suffix === 'cjs.production.min.js') {
53-
config.resolve.mainFields = ['main', 'module']
77+
78+
if (suffix === 'production.min.cjs') {
79+
;(config.resolve ??= {}).mainFields = ['main', 'module']
5480
}
55-
config.optimization.nodeEnv = 'production'
81+
;(config.optimization ??= {}).nodeEnv = 'production'
5682
return config
5783
}
5884
}
@@ -66,42 +92,62 @@ const ignoreAll = [
6692
'redux-thunk',
6793
]
6894

69-
module.exports = [
95+
const entryPoints = [
7096
{
7197
name: `1. entry point: @reduxjs/toolkit`,
72-
path: 'dist/redux-toolkit.modern.js',
98+
path: 'dist/redux-toolkit.modern.mjs',
99+
},
100+
{
101+
name: `1. entry point: @reduxjs/toolkit/react`,
102+
path: 'dist/react/redux-toolkit-react.modern.mjs',
73103
},
74104
{
75105
name: `1. entry point: @reduxjs/toolkit/query`,
76-
path: 'dist/query/rtk-query.modern.js',
106+
path: 'dist/query/rtk-query.modern.mjs',
77107
},
78108
{
79109
name: `1. entry point: @reduxjs/toolkit/query/react`,
80-
path: 'dist/query/react/rtk-query-react.modern.js',
110+
path: 'dist/query/react/rtk-query-react.modern.mjs',
81111
},
82112
{
83113
name: `2. entry point: @reduxjs/toolkit (without dependencies)`,
84-
path: 'dist/redux-toolkit.modern.js',
114+
path: 'dist/redux-toolkit.modern.mjs',
115+
ignore: ignoreAll,
116+
},
117+
{
118+
name: `2. entry point: @reduxjs/toolkit/react (without dependencies)`,
119+
path: 'dist/react/redux-toolkit-react.modern.mjs',
85120
ignore: ignoreAll,
86121
},
87122
{
88123
name: `2. entry point: @reduxjs/toolkit/query (without dependencies)`,
89-
path: 'dist/query/rtk-query.modern.js',
124+
path: 'dist/query/rtk-query.modern.mjs',
90125
ignore: ignoreAll,
91126
},
92127
{
93128
name: `2. entry point: @reduxjs/toolkit/query/react (without dependencies)`,
94-
path: 'dist/query/react/rtk-query-react.modern.js',
129+
path: 'dist/query/react/rtk-query-react.modern.mjs',
95130
ignore: ignoreAll,
96131
},
97132
]
133+
134+
module.exports = entryPoints
98135
.flatMap((e) =>
99-
suffixes.map((suffix) => ({
136+
esmSuffixes.map((suffix) => ({
100137
...e,
101138
name: e.name + ` (${suffix})`,
102139
modifyWebpackConfig: withRtkPath(suffix),
103140
})),
104141
)
142+
.concat(
143+
entryPoints.flatMap((e) =>
144+
cjsSuffixes.map((suffix) => ({
145+
...e,
146+
name: e.name + ` (cjs, ${suffix})`,
147+
modifyWebpackConfig: withRtkPath(suffix, true),
148+
})),
149+
),
150+
)
105151
.concat(
106152
...[
107153
{
@@ -138,7 +184,7 @@ module.exports = [
138184
},
139185
].map((e) => ({
140186
...e,
141-
name: e.name + ` (esm.js)`,
142-
modifyWebpackConfig: withRtkPath('esm.js'),
187+
name: e.name + ` (.modern.mjs)`,
188+
modifyWebpackConfig: withRtkPath('modern.mjs'),
143189
})),
144190
)

packages/toolkit/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,7 @@ RTK Query includes these APIs:
104104
- `setupListeners()`: A utility used to enable refetchOnMount and refetchOnReconnect behaviors.
105105

106106
See the [**RTK Query Overview**](https://redux-toolkit.js.org/rtk-query/overview) page for more details on what RTK Query is, what problems it solves, and how to use it.
107+
108+
## Contributing
109+
110+
Please refer to our [contributing guide](/CONTRIBUTING.md) to learn about our development process, how to propose bugfixes and improvements, and how to build and test your changes to Redux Toolkit.

packages/toolkit/package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,14 @@
5252
"@arethetypeswrong/cli": "^0.13.5",
5353
"@microsoft/api-extractor": "^7.13.2",
5454
"@phryneas/ts-version": "^1.0.2",
55-
"@size-limit/preset-small-lib": "^4.11.0",
55+
"@size-limit/file": "^11.0.1",
56+
"@size-limit/webpack": "^11.0.1",
5657
"@testing-library/react": "^13.3.0",
5758
"@testing-library/user-event": "^13.1.5",
5859
"@types/json-stringify-safe": "^5.0.0",
5960
"@types/nanoid": "^2.1.0",
6061
"@types/node": "^20.11.0",
62+
"@types/node-fetch": "^2.6.11",
6163
"@types/query-string": "^6.3.0",
6264
"@types/react": "^18.0.12",
6365
"@types/react-dom": "^18.0.5",
@@ -81,11 +83,11 @@
8183
"jsdom": "^21.0.0",
8284
"json-stringify-safe": "^5.0.1",
8385
"msw": "^2.1.4",
84-
"node-fetch": "^3.3.2",
86+
"node-fetch": "^2.7.0",
8587
"prettier": "^3.2.4",
8688
"query-string": "^7.0.1",
8789
"rimraf": "^3.0.2",
88-
"size-limit": "^4.11.0",
90+
"size-limit": "^11.0.1",
8991
"tslib": "^1.10.0",
9092
"tsup": "^7.2.0",
9193
"tsx": "^3.12.2",
@@ -104,7 +106,8 @@
104106
"test": "vitest --run --typecheck",
105107
"test:watch": "vitest --watch",
106108
"type-tests": "yarn tsc -p tsconfig.test.json --noEmit",
107-
"prepack": "yarn build"
109+
"prepack": "yarn build",
110+
"size": "size-limit"
108111
},
109112
"files": [
110113
"dist/",

packages/toolkit/src/query/tests/fetchBaseQuery.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ describe('fetchBaseQuery', () => {
10031003

10041004
expect(result?.error).toEqual({
10051005
status: 'TIMEOUT_ERROR',
1006-
error: 'AbortError: The operation was aborted.',
1006+
error: expect.stringMatching(/^AbortError:/),
10071007
})
10081008
})
10091009
})
@@ -1121,7 +1121,7 @@ describe('timeout', () => {
11211121

11221122
expect(result?.error).toEqual({
11231123
status: 'TIMEOUT_ERROR',
1124-
error: 'AbortError: The operation was aborted.',
1124+
error: expect.stringMatching(/^AbortError:/),
11251125
})
11261126
})
11271127
})

packages/toolkit/tsup.config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,9 @@ export default defineConfig((options) => {
214214
} else if (generateTypedefs) {
215215
if (folder === '') {
216216
// we need to delete the declaration file and replace it with the original source file
217-
fs.rmSync(path.join(outputFolder, 'uncheckedindexed.d.ts'))
217+
fs.rmSync(path.join(outputFolder, 'uncheckedindexed.d.ts'), {
218+
force: true,
219+
})
218220

219221
fs.copyFileSync(
220222
'src/uncheckedindexed.ts',

0 commit comments

Comments
 (0)