From 6444c30fde7aded106f238cdcd4edd25ba543cc1 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Thu, 21 Mar 2024 12:25:29 -0500 Subject: [PATCH 1/5] Bump `prettier` --- package.json | 2 +- yarn.lock | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 56c0a08..25d5443 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "cross-env": "^7.0.3", "eslint": "^7.32.0", "eslint-config-prettier": "^8.3.0", - "prettier": "^2.4.1", + "prettier": "^3.2.5", "redux": "^5", "rimraf": "^3.0.2", "tsup": "7.0.0", diff --git a/yarn.lock b/yarn.lock index 00efe55..6172de9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2425,12 +2425,12 @@ __metadata: languageName: node linkType: hard -"prettier@npm:^2.4.1": - version: 2.8.7 - resolution: "prettier@npm:2.8.7" +"prettier@npm:^3.2.5": + version: 3.2.5 + resolution: "prettier@npm:3.2.5" bin: - prettier: bin-prettier.js - checksum: 10/5d5acc2015dcd9ae4033c0ea3189820920149137100750c897d384bc9058c79c78af94ca892f3bc7c5b6da0661a50357e8eb9eb455c4c1da156b1d0757f54a8a + prettier: bin/prettier.cjs + checksum: 10/d509f9da0b70e8cacc561a1911c0d99ec75117faed27b95cc8534cb2349667dee6351b0ca83fa9d5703f14127faa52b798de40f5705f02d843da133fc3aa416a languageName: node linkType: hard @@ -2519,7 +2519,7 @@ __metadata: cross-env: "npm:^7.0.3" eslint: "npm:^7.32.0" eslint-config-prettier: "npm:^8.3.0" - prettier: "npm:^2.4.1" + prettier: "npm:^3.2.5" redux: "npm:^5" rimraf: "npm:^3.0.2" tsup: "npm:7.0.0" From 9114e684dda6dd1e64b91f69e936f49deb702506 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Thu, 21 Mar 2024 12:26:01 -0500 Subject: [PATCH 2/5] Remove `trailingComma` option from `.prettierrc.json` --- .prettierrc.json | 1 - 1 file changed, 1 deletion(-) diff --git a/.prettierrc.json b/.prettierrc.json index e7bcdcc..60cbbf2 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -2,6 +2,5 @@ "semi": false, "singleQuote": true, "tabWidth": 2, - "trailingComma": "none", "arrowParens": "avoid" } From 01a1e955d60f27174cfc0a9a909c068e2fc36c34 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Thu, 21 Mar 2024 12:26:31 -0500 Subject: [PATCH 3/5] Run Prettier on all files Add `.gitattributes` file to make line endings more consistent (#363) Fix webpack 4 support by setting `target: es2017` for `redux.legacy-esm.js` (#370) Revert "Run Prettier on all files" This reverts commit 39e8094221b63a161ca19b16cb95de646e1d6878. Run Prettier on all files Add `.gitattributes` file to make line endings more consistent (#363) --- .babelrc.js | 10 ++++----- .gitattributes | 1 + .github/workflows/test.yml | 2 +- README.md | 40 +++++++++++++++++------------------ src/index.ts | 4 ++-- src/types.ts | 14 ++++++------ test/test.ts | 4 ++-- tsup.config.ts | 28 ++++++++++++------------ typescript_test/typescript.ts | 28 ++++++++++++------------ vitest.config.ts | 8 +++---- 10 files changed, 71 insertions(+), 68 deletions(-) create mode 100644 .gitattributes diff --git a/.babelrc.js b/.babelrc.js index c77ebd6..1977f41 100644 --- a/.babelrc.js +++ b/.babelrc.js @@ -7,13 +7,13 @@ export default { '@babel/preset-env', { targets: { - ie: 11 + ie: 11, }, loose: true, - modules: cjs ? 'cjs' : false - } + modules: cjs ? 'cjs' : false, + }, ], - '@babel/preset-typescript' + '@babel/preset-typescript', ], - plugins: [cjs && ['@babel/transform-modules-commonjs']].filter(Boolean) + plugins: [cjs && ['@babel/transform-modules-commonjs']].filter(Boolean), } diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..6313b56 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f6aa63e..26b4396 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -98,7 +98,7 @@ jobs: 'node-standard', 'node-esm', 'react-native', - 'expo' + 'expo', ] steps: - name: Checkout repo diff --git a/README.md b/README.md index e3c5a3b..c09e789 100644 --- a/README.md +++ b/README.md @@ -23,8 +23,8 @@ import filtersReducer from './features/filters/filtersSlice' const store = configureStore({ reducer: { todos: todosReducer, - filters: filtersReducer - } + filters: filtersReducer, + }, }) // The thunk middleware was automatically added @@ -86,9 +86,9 @@ const store = configureStore({ middleware: getDefaultMiddleware => getDefaultMiddleware({ thunk: { - extraArgument: myCustomApiService - } - }) + extraArgument: myCustomApiService, + }, + }), }) // later @@ -110,10 +110,10 @@ const store = configureStore({ thunk: { extraArgument: { api: myCustomApiService, - otherValue: 42 - } - } - }) + otherValue: 42, + }, + }, + }), }) // later @@ -188,7 +188,7 @@ const INCREMENT_COUNTER = 'INCREMENT_COUNTER' function increment() { return { - type: INCREMENT_COUNTER + type: INCREMENT_COUNTER, } } @@ -264,7 +264,7 @@ function makeASandwich(forPerson, secretSauce) { return { type: 'MAKE_SANDWICH', forPerson, - secretSauce + secretSauce, } } @@ -273,14 +273,14 @@ function apologize(fromPerson, toPerson, error) { type: 'APOLOGIZE', fromPerson, toPerson, - error + error, } } function withdrawMoney(amount) { return { type: 'WITHDRAW', - amount + amount, } } @@ -302,7 +302,7 @@ function makeASandwichWithSecretSauce(forPerson) { return function (dispatch) { return fetchSecretSauce().then( sauce => dispatch(makeASandwich(forPerson, sauce)), - error => dispatch(apologize('The Sandwich Shop', forPerson, error)) + error => dispatch(apologize('The Sandwich Shop', forPerson, error)), ) } } @@ -339,16 +339,16 @@ function makeSandwichesForEverybody() { .then(() => Promise.all([ dispatch(makeASandwichWithSecretSauce('Me')), - dispatch(makeASandwichWithSecretSauce('My wife')) - ]) + dispatch(makeASandwichWithSecretSauce('My wife')), + ]), ) .then(() => dispatch(makeASandwichWithSecretSauce('Our kids'))) .then(() => dispatch( getState().myMoney > 42 ? withdrawMoney(42) - : apologize('Me', 'The Sandwich Shop') - ) + : apologize('Me', 'The Sandwich Shop'), + ), ) } } @@ -359,7 +359,7 @@ function makeSandwichesForEverybody() { store .dispatch(makeSandwichesForEverybody()) .then(() => - response.send(ReactDOMServer.renderToString()) + response.send(ReactDOMServer.renderToString()), ) // I can also dispatch a thunk async action from a component @@ -385,7 +385,7 @@ class SandwichShop extends Component { } export default connect(state => ({ - sandwiches: state.sandwiches + sandwiches: state.sandwiches, }))(SandwichShop) ``` diff --git a/src/index.ts b/src/index.ts index 58bab3d..f925288 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,7 @@ export type { ThunkAction, ThunkDispatch, ThunkActionDispatch, - ThunkMiddleware + ThunkMiddleware, } from './types' /** A function that accepts a potential "extra argument" value to be injected later, @@ -15,7 +15,7 @@ export type { function createThunkMiddleware< State = any, BasicAction extends Action = AnyAction, - ExtraThunkArg = undefined + ExtraThunkArg = undefined, >(extraArgument?: ExtraThunkArg) { // Standard Redux middleware definition pattern: // See: https://redux.js.org/tutorials/fundamentals/part-4-store#writing-custom-middleware diff --git a/src/types.ts b/src/types.ts index 973e4ac..41a01c7 100644 --- a/src/types.ts +++ b/src/types.ts @@ -14,14 +14,14 @@ import type { Action, AnyAction, Middleware } from 'redux' export interface ThunkDispatch< State, ExtraThunkArg, - BasicAction extends Action + BasicAction extends Action, > { // When the thunk middleware is added, `store.dispatch` now has three overloads (NOTE: the order here matters for correct behavior and is very fragile - do not reorder these!): // 1) The specific thunk function overload /** Accepts a thunk function, runs it, and returns whatever the thunk itself returns */ ( - thunkAction: ThunkAction + thunkAction: ThunkAction, ): ReturnType // 2) The base overload. @@ -32,7 +32,7 @@ export interface ThunkDispatch< // with TS inference ( see https://github.com/microsoft/TypeScript/issues/14107 ) /** A union of the other two overloads for TS inference purposes */ ( - action: Action | ThunkAction + action: Action | ThunkAction, ): Action | ReturnType } @@ -53,11 +53,11 @@ export type ThunkAction< ReturnType, State, ExtraThunkArg, - BasicAction extends Action + BasicAction extends Action, > = ( dispatch: ThunkDispatch, getState: () => State, - extraArgument: ExtraThunkArg + extraArgument: ExtraThunkArg, ) => ReturnType /** @@ -69,7 +69,7 @@ export type ThunkAction< * @template ActionCreator Thunk action creator to be wrapped */ export type ThunkActionDispatch< - ActionCreator extends (...args: any[]) => ThunkAction + ActionCreator extends (...args: any[]) => ThunkAction, > = ( ...args: Parameters ) => ReturnType> @@ -83,7 +83,7 @@ export type ThunkActionDispatch< export type ThunkMiddleware< State = any, BasicAction extends Action = AnyAction, - ExtraThunkArg = undefined + ExtraThunkArg = undefined, > = Middleware< ThunkDispatch, State, diff --git a/test/test.ts b/test/test.ts index 15b403d..1c22a62 100644 --- a/test/test.ts +++ b/test/test.ts @@ -5,7 +5,7 @@ describe('thunk middleware', () => { const doGetState = () => 42 const nextHandler = thunkMiddleware({ dispatch: doDispatch, - getState: doGetState + getState: doGetState, }) it('must return a function to handle next', () => { @@ -90,7 +90,7 @@ describe('thunk middleware', () => { // @ts-ignore withExtraArgument(extraArg)({ dispatch: doDispatch, - getState: doGetState + getState: doGetState, })()((dispatch: any, getState: any, arg: any) => { expect(dispatch).toBe(doDispatch) expect(getState).toBe(doGetState) diff --git a/tsup.config.ts b/tsup.config.ts index 22b3528..9e37a8c 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -1,12 +1,12 @@ -import { defineConfig, Options } from 'tsup' -import fs from 'fs' +import type { Options } from 'tsup' +import { defineConfig } from 'tsup' export default defineConfig(options => { const commonOptions: Partial = { entry: { - 'redux-thunk': 'src/index.ts' + 'redux-thunk': 'src/index.ts', }, - ...options + ...options, } return [ @@ -16,19 +16,21 @@ export default defineConfig(options => { outExtension: () => ({ js: '.mjs' }), dts: true, clean: true, - onSuccess() { - // Support Webpack 4 by pointing `"module"` to a file with a `.js` extension - fs.copyFileSync( - 'dist/redux-thunk.mjs', - 'dist/redux-thunk.legacy-esm.js' - ) - } + }, + // Support Webpack 4 by pointing `"module"` to a file with a `.js` extension + { + ...commonOptions, + format: ['esm'], + target: 'es2017', + dts: false, + outExtension: () => ({ js: '.js' }), + entry: { 'redux-thunk.legacy-esm': 'src/index.ts' }, }, { ...commonOptions, format: 'cjs', outDir: './dist/cjs/', - outExtension: () => ({ js: '.cjs' }) - } + outExtension: () => ({ js: '.cjs' }), + }, ] }) diff --git a/typescript_test/typescript.ts b/typescript_test/typescript.ts index c6a52b6..cde9f3f 100644 --- a/typescript_test/typescript.ts +++ b/typescript_test/typescript.ts @@ -7,7 +7,7 @@ import type { ThunkAction, ThunkActionDispatch, ThunkDispatch, - ThunkMiddleware + ThunkMiddleware, } from '../src/index' export type State = { @@ -19,7 +19,7 @@ export type Actions = { type: 'FOO' } | { type: 'BAR'; result: number } export type ThunkResult = ThunkAction export const initialState: State = { - foo: 'foo' + foo: 'foo', } export function fakeReducer(state: State = initialState): State { @@ -28,7 +28,7 @@ export function fakeReducer(state: State = initialState): State { export const store = createStore( fakeReducer, - applyMiddleware(thunk as ThunkMiddleware) + applyMiddleware(thunk as ThunkMiddleware), ) store.dispatch(dispatch => { @@ -70,8 +70,8 @@ store.dispatch(testGetState()) const storeThunkArg = createStore( fakeReducer, applyMiddleware( - withExtraArgument('bar') as ThunkMiddleware - ) + withExtraArgument('bar') as ThunkMiddleware, + ), ) storeThunkArg.dispatch({ type: 'FOO' }) @@ -85,23 +85,23 @@ storeThunkArg.dispatch((dispatch, getState, extraArg) => { }) const callDispatchAsync_anyAction = ( - dispatch: ThunkDispatch + dispatch: ThunkDispatch, ) => { const asyncThunk = (): ThunkResult> => () => - ({} as Promise) + ({}) as Promise dispatch(asyncThunk()).then(() => console.log('done')) } const callDispatchAsync_specificActions = ( - dispatch: ThunkDispatch + dispatch: ThunkDispatch, ) => { const asyncThunk = (): ThunkResult> => () => - ({} as Promise) + ({}) as Promise dispatch(asyncThunk()).then(() => console.log('done')) } const callDispatchAny = ( - dispatch: ThunkDispatch + dispatch: ThunkDispatch, ) => { - const asyncThunk = (): any => () => ({} as Promise) + const asyncThunk = (): any => () => ({}) as Promise dispatch(asyncThunk()) // result is any .then(() => console.log('done')) } @@ -127,9 +127,9 @@ const actions: ActionDispatchs = bindActionCreators( { anotherThunkAction, promiseThunkAction, - standardAction + standardAction, }, - store.dispatch + store.dispatch, ) actions.anotherThunkAction() === 'hello' @@ -152,7 +152,7 @@ function testIssue248() { const dispatch: ThunkDispatch = undefined as any function dispatchWrap( - action: Action | ThunkAction + action: Action | ThunkAction, ) { // Should not have an error here thanks to the extra union overload dispatch(action) diff --git a/vitest.config.ts b/vitest.config.ts index 4ef78f4..1732a02 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -8,10 +8,10 @@ export default defineConfig({ 'redux-thunk': './src/index.ts', // @remap-prod-remove-line // this mapping is disabled as we want `dist` imports in the tests only to be used for "type-only" imports which don't play a role for jest - '@internal/': './src/' + '@internal/': './src/', }, deps: { - interopDefault: true - } - } + interopDefault: true, + }, + }, }) From 3c42ec2d5c1aa6bd0474ed38cb41cec325e37d06 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Mon, 24 Jun 2024 16:37:38 -0500 Subject: [PATCH 4/5] Bump Prettier to version 3.3.2 --- package.json | 2 +- yarn.lock | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 25d5443..c102512 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "cross-env": "^7.0.3", "eslint": "^7.32.0", "eslint-config-prettier": "^8.3.0", - "prettier": "^3.2.5", + "prettier": "^3.3.2", "redux": "^5", "rimraf": "^3.0.2", "tsup": "7.0.0", diff --git a/yarn.lock b/yarn.lock index 6172de9..54b63ff 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2425,12 +2425,12 @@ __metadata: languageName: node linkType: hard -"prettier@npm:^3.2.5": - version: 3.2.5 - resolution: "prettier@npm:3.2.5" +"prettier@npm:^3.3.2": + version: 3.3.2 + resolution: "prettier@npm:3.3.2" bin: prettier: bin/prettier.cjs - checksum: 10/d509f9da0b70e8cacc561a1911c0d99ec75117faed27b95cc8534cb2349667dee6351b0ca83fa9d5703f14127faa52b798de40f5705f02d843da133fc3aa416a + checksum: 10/83214e154afa5aa9b664c2506640212323eb1376b13379b2413dc351b7de0687629dca3f00ff2ec895ebd7e3a2adb7d7e231b6c77606e2358137f2150807405b languageName: node linkType: hard @@ -2519,7 +2519,7 @@ __metadata: cross-env: "npm:^7.0.3" eslint: "npm:^7.32.0" eslint-config-prettier: "npm:^8.3.0" - prettier: "npm:^3.2.5" + prettier: "npm:^3.3.2" redux: "npm:^5" rimraf: "npm:^3.0.2" tsup: "npm:7.0.0" From ed61c30f8c1423828fdfb7d053a2f7279bf1ab90 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 16 Jul 2024 16:27:37 -0500 Subject: [PATCH 5/5] Bump Prettier to version 3.3.3 --- package.json | 2 +- yarn.lock | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 760da30..d3dc692 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "cross-env": "^7.0.3", "eslint": "^7.32.0", "eslint-config-prettier": "^8.3.0", - "prettier": "^3.3.2", + "prettier": "^3.3.3", "redux": "^5", "rimraf": "^3.0.2", "tsup": "7.0.0", diff --git a/yarn.lock b/yarn.lock index 6bcea6c..50aba5c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2842,12 +2842,12 @@ __metadata: languageName: node linkType: hard -"prettier@npm:^3.3.2": - version: 3.3.2 - resolution: "prettier@npm:3.3.2" +"prettier@npm:^3.3.3": + version: 3.3.3 + resolution: "prettier@npm:3.3.3" bin: prettier: bin/prettier.cjs - checksum: 10/83214e154afa5aa9b664c2506640212323eb1376b13379b2413dc351b7de0687629dca3f00ff2ec895ebd7e3a2adb7d7e231b6c77606e2358137f2150807405b + checksum: 10/5beac1f30b5b40162532b8e2f7c3a4eb650910a2695e9c8512a62ffdc09dae93190c29db9107fa7f26d1b6c71aad3628ecb9b5de1ecb0911191099be109434d7 languageName: node linkType: hard @@ -2937,7 +2937,7 @@ __metadata: cross-env: "npm:^7.0.3" eslint: "npm:^7.32.0" eslint-config-prettier: "npm:^8.3.0" - prettier: "npm:^3.3.2" + prettier: "npm:^3.3.3" redux: "npm:^5" rimraf: "npm:^3.0.2" tsup: "npm:7.0.0"