Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate thunk package to ESM #340

Merged
merged 7 commits into from
Jan 21, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .babelrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { NODE_ENV, BABEL_ENV } = process.env
const cjs = NODE_ENV === 'test' || BABEL_ENV === 'commonjs'

module.exports = {
export default {
presets: [
[
'@babel/preset-env',
Expand Down
10 changes: 5 additions & 5 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/** @type {import('@ts-jest/dist/types').InitialOptionsTsJest} */

module.exports = {
export default {
preset: 'ts-jest',
testEnvironment: 'node',
coverageDirectory: './coverage/',
collectCoverage: true,
testRegex: 'test/test.ts',
globals: {
'ts-jest': {
tsconfig: './test/tsconfig.json',
},
},
};
tsconfig: './test/tsconfig.json'
}
}
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "redux-thunk",
"version": "2.4.2",
"version": "3.0.0-alpha.1",
"license": "MIT",
"description": "Thunk middleware for Redux.",
"repository": "github:reduxjs/redux-thunk",
Expand All @@ -14,9 +14,18 @@
"flux"
],
"author": "Dan Abramov <dan.abramov@me.com>",
"type": "module",
"main": "lib/index.js",
"module": "es/index.js",
"types": "es/index.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"types": "./es/index.d.ts",
"import": "./es/index.js",
"default": "./lib/index.js"
}
},
"sideEffects": false,
"files": [
"lib",
Expand All @@ -30,7 +39,7 @@
"prepublishOnly": "npm run clean && npm run lint && npm run test && npm run build",
"format": "prettier --write {src,test,typescript_test}/**/*.{js,ts}",
"format:check": "prettier --check {src,test,typescript_test}/**/*.{js,ts}",
"lint": "eslint '{src,test,typescript_test}/**/*.{js,ts}'",
"lint": "eslint {src,test,typescript_test}/**/*.{js,ts}",
timdorr marked this conversation as resolved.
Show resolved Hide resolved
"test": "jest",
"test:cov": "jest --coverage",
"test:typescript": "npm run test:typescript:main && npm run test:typescript:extended",
Expand Down
8 changes: 3 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function createThunkMiddleware<
return middleware
}

const thunk = createThunkMiddleware() as ThunkMiddleware & {
export const thunk = createThunkMiddleware() as ThunkMiddleware & {
withExtraArgument<
ExtraThunkArg,
State = any,
Expand All @@ -46,8 +46,6 @@ const thunk = createThunkMiddleware() as ThunkMiddleware & {
): ThunkMiddleware<State, BasicAction, ExtraThunkArg>
}

// Attach the factory function so users can create a customized version
// Export the factory function so users can create a customized version
// with whatever "extra arg" they want to inject into their thunks
thunk.withExtraArgument = createThunkMiddleware

export default thunk
export const withExtraArgument = createThunkMiddleware
4 changes: 2 additions & 2 deletions test/test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import thunkMiddleware from '../src/index'
import { thunk as thunkMiddleware, withExtraArgument } from '../src/index'

describe('thunk middleware', () => {
const doDispatch = () => {}
Expand Down Expand Up @@ -92,7 +92,7 @@ describe('thunk middleware', () => {
it('must pass the third argument', done => {
const extraArg = { lol: true }
// @ts-ignore
thunkMiddleware.withExtraArgument(extraArg)({
withExtraArgument(extraArg)({
dispatch: doDispatch,
getState: doGetState
})()((dispatch: any, getState: any, arg: any) => {
Expand Down