Skip to content

Commit 942f2f0

Browse files
committed
Merge branch 'master' into combineslices-example
2 parents 40cdc44 + 5edd11c commit 942f2f0

File tree

196 files changed

+14789
-6459
lines changed

Some content is hidden

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

196 files changed

+14789
-6459
lines changed

.github/workflows/test-codegen.yml

Lines changed: 112 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
22
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
33

4-
name: RTK-Query OpenAPI Codegen Tests
4+
name: RTKQ OpenAPI Codegen
55
defaults:
66
run:
77
working-directory: ./packages/rtk-query-codegen-openapi
@@ -23,24 +23,128 @@ jobs:
2323
codegen:
2424
- 'packages/rtk-query-codegen-openapi/**'
2525
- 'yarn.lock'
26+
- '.github/workflows/test-codegen.yml'
2627
2728
build:
28-
needs: changes
29+
needs: [changes]
2930
if: ${{ needs.changes.outputs.codegen == 'true' }}
3031

31-
runs-on: ubuntu-latest
32+
defaults:
33+
run:
34+
working-directory: ./packages/rtk-query-codegen-openapi
35+
36+
runs-on: ${{ matrix.os }}
37+
38+
name: 'Build artifact: ${{ matrix.os }} + Node ${{ matrix.node-version }}'
3239

3340
strategy:
3441
matrix:
3542
node-version: ['20.x']
43+
os: [ubuntu-latest]
3644

3745
steps:
38-
- uses: actions/checkout@v4
39-
- name: Use Node.js ${{ matrix.node-version }}
46+
- name: Checkout repository
47+
uses: actions/checkout@v4
48+
49+
- name: Setup Node ${{ matrix.node-version }}
50+
uses: actions/setup-node@v4
51+
with:
52+
node-version: ${{ matrix.node-version }}
53+
cache: 'yarn'
54+
55+
- name: Install dependencies
56+
run: yarn install
57+
58+
- name: Pack
59+
run: yarn pack
60+
61+
- name: Upload artifact
62+
uses: actions/upload-artifact@v4
63+
id: artifact-upload-step
64+
with:
65+
name: package
66+
path: ./packages/rtk-query-codegen-openapi/package.tgz
67+
68+
- name: Did we fail?
69+
if: failure()
70+
run: ls -lR
71+
72+
test:
73+
needs: build
74+
defaults:
75+
run:
76+
working-directory: ./packages/rtk-query-codegen-openapi
77+
name: 'Test build artifact: ${{ matrix.os }} + Node ${{ matrix.node-version }}'
78+
runs-on: ${{ matrix.os }}
79+
strategy:
80+
fail-fast: false
81+
matrix:
82+
node-version: [20.x]
83+
os: [ubuntu-latest]
84+
85+
steps:
86+
- name: Checkout repository
87+
uses: actions/checkout@v4
88+
89+
- name: Setup Node ${{ matrix.node-version }}
4090
uses: actions/setup-node@v4
4191
with:
42-
node-version: ${{ matrix.node }}
92+
node-version: ${{ matrix.node-version }}
4393
cache: 'yarn'
4494

45-
- run: yarn install
46-
- run: yarn test
95+
- name: Download artifact
96+
id: download-artifact
97+
uses: actions/download-artifact@v4
98+
with:
99+
path: ./packages/rtk-query-codegen-openapi
100+
name: package
101+
102+
- name: Install dependencies
103+
run: yarn install
104+
105+
- name: Install build artifact
106+
run: yarn add ./package.tgz
107+
108+
- name: Remove path alias
109+
run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.json
110+
111+
- name: Run tests
112+
run: yarn test
113+
env:
114+
TEST_DIST: true
115+
116+
- name: Did we fail?
117+
if: failure()
118+
run: ls -R
119+
120+
are-the-types-wrong:
121+
name: Check package definition with are-the-types-wrong
122+
123+
needs: [build]
124+
runs-on: ubuntu-latest
125+
strategy:
126+
fail-fast: false
127+
matrix:
128+
node-version: [20.x]
129+
steps:
130+
- name: Checkout repo
131+
uses: actions/checkout@v4
132+
133+
- name: Use node ${{ matrix.node-version }}
134+
uses: actions/setup-node@v4
135+
with:
136+
node-version: ${{ matrix.node-version }}
137+
cache: 'yarn'
138+
139+
- name: Install deps
140+
run: yarn install
141+
142+
- name: Download artifact
143+
id: download-artifact
144+
uses: actions/download-artifact@v4
145+
with:
146+
path: ./packages/rtk-query-codegen-openapi
147+
name: package
148+
149+
- name: Run are-the-types-wrong
150+
run: yarn dlx @arethetypeswrong/cli@latest ./package.tgz --format table

.github/workflows/tests.yml

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,21 +92,26 @@ jobs:
9292
- name: Install build artifact
9393
run: yarn workspace @reduxjs/toolkit add $(pwd)/package.tgz
9494

95-
- run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.base.json ./vitest.config.mts ./src/tests/*.* ./src/query/tests/*.*
95+
- run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.base.json
9696

9797
- name: Run tests, against dist
98+
env:
99+
TEST_DIST: true
98100
run: yarn test
99101

102+
- name: Run type tests with `moduleResolution Bundler`
103+
run: rm -rf dist && yarn tsc -p . --moduleResolution Bundler --module ESNext --noEmit false --declaration --emitDeclarationOnly --outDir dist --target ESNext && rm -rf dist
104+
100105
test-types:
101-
name: Test Types with TypeScript ${{ matrix.ts }}
106+
name: 'Test Types: TS ${{ matrix.ts }}'
102107

103108
needs: [build]
104109
runs-on: ubuntu-latest
105110
strategy:
106111
fail-fast: false
107112
matrix:
108113
node: ['20.x']
109-
ts: ['4.7', '4.8', '4.9', '5.0', '5.1', '5.2', '5.3', '5.4']
114+
ts: ['4.7', '4.8', '4.9', '5.0', '5.1', '5.2', '5.3', '5.4', '5.5']
110115
steps:
111116
- name: Checkout repo
112117
uses: actions/checkout@v4
@@ -134,9 +139,11 @@ jobs:
134139
- name: Show installed RTK versions
135140
run: yarn info @reduxjs/toolkit
136141

137-
- run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.base.json ./vitest.config.mts ./src/tests/*.* ./src/query/tests/*.*
142+
- run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.base.json
138143

139144
- name: Test types
145+
env:
146+
TEST_DIST: true
140147
run: |
141148
yarn tsc --version
142149
yarn type-tests
@@ -243,3 +250,54 @@ jobs:
243250

244251
- name: Run are-the-types-wrong
245252
run: yarn attw ./package.tgz --format table --ignore-rules false-cjs
253+
254+
test-type-portability:
255+
name: 'Test Type Portability: TS ${{ matrix.ts }} + Node ${{ matrix.node }}'
256+
needs: [build]
257+
runs-on: ubuntu-latest
258+
strategy:
259+
fail-fast: false
260+
matrix:
261+
node: ['20.x']
262+
ts: ['5.3', '5.4', '5.5', 'next']
263+
example:
264+
[
265+
{ name: 'bundler', moduleResolution: 'Bundler' },
266+
{ name: 'nodenext-cjs', moduleResolution: 'NodeNext' },
267+
{ name: 'nodenext-esm', moduleResolution: 'NodeNext' },
268+
]
269+
steps:
270+
- name: Checkout repo
271+
uses: actions/checkout@v4
272+
273+
- name: Use node ${{ matrix.node }}
274+
uses: actions/setup-node@v4
275+
with:
276+
node-version: ${{ matrix.node }}
277+
cache: 'yarn'
278+
279+
- name: Install deps
280+
run: yarn install
281+
282+
- uses: actions/download-artifact@v4
283+
with:
284+
name: package
285+
path: packages/toolkit
286+
287+
- name: Install build artifact
288+
run: yarn workspace @examples-type-portability/${{ matrix.example.name }} add $(pwd)/package.tgz
289+
290+
- name: Install TypeScript ${{ matrix.ts }}
291+
run: yarn workspace @examples-type-portability/${{ matrix.example.name }} add -D typescript@${{ matrix.ts }}
292+
293+
- name: Test type portability with `moduleResolution ${{ matrix.example.moduleResolution }}`
294+
run: yarn workspace @examples-type-portability/${{ matrix.example.name }} run test
295+
296+
- name: Test type portability with `moduleResolution Node10`
297+
run: yarn workspace @examples-type-portability/${{ matrix.example.name }} run test --module CommonJS --moduleResolution Node10 --preserveSymLinks --verbatimModuleSyntax false
298+
299+
- name: Test type portability with `moduleResolution Node10` and `type module` in `package.json`
300+
if: matrix.example.name == 'nodenext-esm' || matrix.example.name == 'bundler'
301+
run: |
302+
npm --workspace=@examples-type-portability/${{ matrix.example.name }} pkg set type=module
303+
yarn workspace @examples-type-portability/${{ matrix.example.name }} run test --module ESNext --moduleResolution Node10 --preserveSymLinks --verbatimModuleSyntax false

.yarn/patches/console-testing-library-npm-0.6.1-4d9957d402.patch

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,38 @@
1+
diff --git a/package.json b/package.json
2+
index b924e066ecfdb30917b9c1056b360834da357698..15e155bd84f9d16537ffe36f9a87debcb0ec3591 100644
3+
--- a/package.json
4+
+++ b/package.json
5+
@@ -8,12 +8,15 @@
6+
"type": "module",
7+
"main": "dist/index.js",
8+
"typings": "index.d.ts",
9+
+ "types": "index.d.ts",
10+
"exports": {
11+
".": {
12+
+ "types": "./index.d.ts",
13+
"require": "./dist/index.js",
14+
"default": "./src/index.js"
15+
},
16+
"./pure": {
17+
+ "types": "./pure.d.ts",
18+
"require": "./dist/pure.js",
19+
"default": "./src/pure.js"
20+
}
21+
diff --git a/pure.d.ts b/pure.d.ts
22+
index b13bb4eb87d0b316bb51bd6094b2353c6fc8527d..ee01cc9bd3233f5e67b050d48e22202b495a4a0a 100644
23+
--- a/pure.d.ts
24+
+++ b/pure.d.ts
25+
@@ -1 +1 @@
26+
-export * from './';
27+
+export * from './index.js';
128
diff --git a/src/index.js b/src/index.js
229
index 90ff7fa3d7d4fa62dbbf638958ae4e28abd089a8..28434687b5163b7472e86bdb11bed69e0868e660 100644
330
--- a/src/index.js
431
+++ b/src/index.js
532
@@ -1,4 +1,4 @@
633
-import { mockConsole, createConsole } from './pure';
734
+import { mockConsole, createConsole } from './pure.js';
8-
35+
936
// Keep an instance of the original console and export it
1037
const originalConsole = global.console;
1138
diff --git a/src/pure.js b/src/pure.js
@@ -15,7 +42,7 @@ index b00ea2abbaea833e336676aa46e7ced2d59d6d88..42b83ed83fa16cf2234571500fe09868
1542
@@ -228,10 +228,11 @@ export function restore() {
1643
global.console = global.originalConsole;
1744
}
18-
45+
1946
+/*
2047
if (typeof expect === 'function' && typeof expect.extend === 'function') {
2148
expect.extend({
@@ -24,13 +51,13 @@ index b00ea2abbaea833e336676aa46e7ced2d59d6d88..42b83ed83fa16cf2234571500fe09868
2451
+ // Workaround for custom inline snapshot matchers
2552
const error = new Error();
2653
const stacks = error.stack.split('\n');
27-
54+
2855
@@ -245,7 +246,6 @@ if (typeof expect === 'function' && typeof expect.extend === 'function') {
2956
error.stack = stacks.join('\n');
30-
57+
3158
const context = Object.assign(this, { error });
3259
- /* -------------------------------------------------------------- */
33-
60+
3461
const testingConsoleInstance =
3562
(received && received.testingConsole) || received;
3663
@@ -270,3 +270,4 @@ if (typeof expect === 'function' && typeof expect.extend === 'function') {

.yarnrc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ enableGlobalCache: false
55
nodeLinker: node-modules
66

77
yarnPath: .yarn/releases/yarn-4.1.0.cjs
8+
9+
enableTransparentWorkspaces: false

docs/api/actionCreatorMiddleware.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ hide_title: true
1212
A custom middleware that detects if an action creator has been mistakenly dispatched, instead of being called before dispatching.
1313

1414
A common mistake is to call `dispatch(actionCreator)` instead of `dispatch(actionCreator())`.
15-
This tends to "work" as the action creator has the static `type` property, but can lead to unexpected behaviour.
15+
This tends to "work" as the action creator has the static `type` property, but can lead to unexpected behavior.
1616

1717
## Options
1818

docs/api/combineSlices.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ const reducerWithUser = rootReducer.inject(userSlice, {
213213
```
214214

215215
This may be useful for hot reload, or "removing" a reducer by replacing it with a function that always returns `null`.
216-
Note that for predictable behaviour, your types should account for all of the possible reducers you intend to occupy a path.
216+
Note that for predictable behavior, your types should account for all of the possible reducers you intend to occupy a path.
217217

218218
```ts no-transpile title="'Removing' a reducer, by replacing it with a no-op function"
219219
declare module '.' {

docs/api/createListenerMiddleware.mdx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,11 +488,14 @@ To fix this, the middleware provides types for defining "pre-typed" versions of
488488
import { createListenerMiddleware, addListener } from '@reduxjs/toolkit'
489489
import type { RootState, AppDispatch } from './store'
490490

491+
declare type ExtraArgument = {foo: string};
492+
491493
export const listenerMiddleware = createListenerMiddleware()
492494

493495
export const startAppListening = listenerMiddleware.startListening.withTypes<
494496
RootState,
495-
AppDispatch
497+
AppDispatch,
498+
ExtraArgument
496499
>()
497500

498501
export const addAppListener = addListener.withTypes<RootState, AppDispatch>()

docs/rtk-query/api/created-api/hooks.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ type UseQuerySubscriptionResult = {
460460
461461
- `arg`: The argument passed to the query defined in the endpoint.
462462
You can also pass in `skipToken` here as an alternative way of skipping the query, see [skipToken](#skiptoken)
463-
- `options`: A set of options that control the fetching behaviour of the hook
463+
- `options`: A set of options that control the fetching behavior of the hook
464464
465465
- **Returns**
466466
- An object containing a function to `refetch` the data

docs/rtk-query/internal/buildMiddleware/invalidationByTags.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const handler: ApiMiddlewareInternalHandler = (action, mwApi) => {
6464
1. invalidateTags function is called with a list of tags generated from the action metadata
6565
2. in the case of a [queryThunk] resolution an empty set of tags is always provided
6666
2. The tags calculated are added to the list of pending tags to invalidate (see [delayed](#Delayed))
67-
3. (optional: 'Delayed') the invalidateTags function is ended if the `apiSlice.invalidationBehaviour` is set to "delayed" and there are any pending thunks/queries running in that `apiSlice`
67+
3. (optional: 'Delayed') the invalidateTags function is ended if the `apiSlice.invalidationBehavior` is set to "delayed" and there are any pending thunks/queries running in that `apiSlice`
6868
4. Pending tags are reset to an empty list, if there are no tags the function ends here
6969
5. Selects all `{ endpointName, originalArgs, queryCacheKey }` combinations that would be invalidated by a specific set of tags.
7070
6. Iterates through queryCacheKeys selected and performs one of two actions if the query exists\*
@@ -102,7 +102,7 @@ Step 6 is performed within a `context.batch()` call.
102102
103103
RTKQ now has internal logic to delay tag invalidation briefly, to allow multiple invalidations to get handled together. This is controlled by a new `invalidationBehavior: 'immediate' | 'delayed'` flag on `createApi`. The new default behavior is `'delayed'`. Set it to `'immediate'` to revert to the behavior in RTK 1.9.
104104
105-
The `'delayed'` behaviour enables a check inside `invalidationByTags` that will cause any invalidation that is triggered while a query/mutation is still pending to batch the invalidation until no query/mutation is running.
105+
The `'delayed'` behavior enables a check inside `invalidationByTags` that will cause any invalidation that is triggered while a query/mutation is still pending to batch the invalidation until no query/mutation is running.
106106
107107
```ts no-transpile
108108
function invalidateTags(

0 commit comments

Comments
 (0)