From 604624d2751f0929a0f190cf869d3864b72d17d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Bedi?= Date: Tue, 26 Mar 2019 16:30:24 +0100 Subject: [PATCH 1/3] refactor(serializableStateInvariantMiddleware): named import instead of default --- src/configureStore.ts | 2 +- src/serializableStateInvariantMiddleware.test.ts | 3 ++- src/serializableStateInvariantMiddleware.ts | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/configureStore.ts b/src/configureStore.ts index de779d8719..6477e8418d 100644 --- a/src/configureStore.ts +++ b/src/configureStore.ts @@ -14,7 +14,7 @@ import { } from 'redux' import { composeWithDevTools } from 'redux-devtools-extension' import thunk, { ThunkDispatch, ThunkMiddleware } from 'redux-thunk' -import createSerializableStateInvariantMiddleware from './serializableStateInvariantMiddleware' +import { createSerializableStateInvariantMiddleware } from './serializableStateInvariantMiddleware' import isPlainObject from './isPlainObject' diff --git a/src/serializableStateInvariantMiddleware.test.ts b/src/serializableStateInvariantMiddleware.test.ts index 4d5b3188e0..76129fd521 100644 --- a/src/serializableStateInvariantMiddleware.test.ts +++ b/src/serializableStateInvariantMiddleware.test.ts @@ -1,7 +1,8 @@ import { Reducer } from 'redux' import { configureStore } from './configureStore' -import createSerializableStateInvariantMiddleware, { +import { + createSerializableStateInvariantMiddleware, findNonSerializableValue } from './serializableStateInvariantMiddleware' diff --git a/src/serializableStateInvariantMiddleware.ts b/src/serializableStateInvariantMiddleware.ts index a6f519a655..bdd0a4a832 100644 --- a/src/serializableStateInvariantMiddleware.ts +++ b/src/serializableStateInvariantMiddleware.ts @@ -101,7 +101,7 @@ export interface SerializableStateInvariantMiddlewareOptions { * * @param options Middleware options. */ -export default function createSerializableStateInvariantMiddleware( +export function createSerializableStateInvariantMiddleware( options: SerializableStateInvariantMiddlewareOptions = {} ): Middleware { const { isSerializable = isPlain } = options From 1fca9b077fddf02ab46ab15e23a0a3011c14864a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Bedi?= Date: Tue, 26 Mar 2019 16:32:01 +0100 Subject: [PATCH 2/3] refactor(build): create types with typescript --- index.d.ts | 31 ---------------------------- package.json | 2 +- rollup.config.js | 1 + src/index.ts | 37 +++++++++++++++------------------- tsconfig.json | 7 +++++-- type-tests/files/tsconfig.json | 2 +- 6 files changed, 24 insertions(+), 56 deletions(-) delete mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 1522fb1f2e..0000000000 --- a/index.d.ts +++ /dev/null @@ -1,31 +0,0 @@ -export { default as createNextState } from 'immer' -export { - Action, - ActionCreator, - AnyAction, - Middleware, - Reducer, - Store, - StoreEnhancer, - combineReducers, - compose -} from 'redux' -export { default as createSelector } from 'selectorator' - -export { - configureStore, - ConfigureStoreOptions, - getDefaultMiddleware -} from './src/configureStore' -export { - createAction, - getType, - PayloadAction, - PayloadActionCreator -} from './src/createAction' -export { createReducer } from './src/createReducer' -export { createSlice, CreateSliceOptions, Slice } from './src/createSlice' -export { - default as createSerializableStateInvariantMiddleware, - isPlain -} from './src/serializableStateInvariantMiddleware' diff --git a/package.json b/package.json index a60e3b257f..7af9037f82 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "main": "dist/redux-starter-kit.cjs.js", "module": "dist/redux-starter-kit.esm.js", "unpkg": "dist/redux-starter-kit.umd.js", + "types": "dist/index.d.ts", "author": "Mark Erikson ", "license": "MIT", "devDependencies": { @@ -45,7 +46,6 @@ }, "files": [ "dist", - "index.d.ts", "src" ], "dependencies": { diff --git a/rollup.config.js b/rollup.config.js index 3dd26f573e..959e22eda7 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -17,6 +17,7 @@ export default [ file: pkg.unpkg, format: 'umd' }, + external: Object.keys(pkg.dependencies), plugins: [ babel({ extensions, diff --git a/src/index.ts b/src/index.ts index 59cc10f77e..8f9fe0c14d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,24 +1,19 @@ -export { combineReducers, compose } from 'redux' +export { + Action, + ActionCreator, + AnyAction, + Middleware, + Reducer, + Store, + StoreEnhancer, + combineReducers, + compose +} from 'redux' export { default as createNextState } from 'immer' export { default as createSelector } from 'selectorator' -export { configureStore, getDefaultMiddleware } from './configureStore' -export { createAction, getType } from './createAction' -export { createReducer } from './createReducer' -export { createSlice } from './createSlice' -export { - default as createSerializableStateInvariantMiddleware, - isPlain -} from './serializableStateInvariantMiddleware' - -// Unfortunately, Babel's TypeScript plugin doesn't let us re-export -// types using the `export { ... } from` syntax. Because it compiles -// modules, independently, it has no way of knowing whether an identifier -// refers to a type or value, and thus cannot strip the type re-exports -// out of the generated JS. -// -// https://github.com/babel/babel/issues/8361 -// -// As a workaround, the root of this repository contains an `index.d.ts` -// that contains all type re-exports. Whenever adding a new public function -// or type, remember to export it in `index.d.ts` as well. +export * from './configureStore' +export * from './createAction' +export * from './createReducer' +export * from './createSlice' +export * from './serializableStateInvariantMiddleware' diff --git a/tsconfig.json b/tsconfig.json index 77a0ef6200..f3718bd130 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,14 +1,17 @@ { "compilerOptions": { "allowSyntheticDefaultImports": true, + "emitDeclarationOnly": true, "esModuleInterop": true, + "declaration": true, "module": "es2015", "moduleResolution": "node", - "noEmit": true, "noUnusedLocals": true, "noUnusedParameters": true, + "outDir": "dist", "strict": true, "target": "es2018" }, - "include": ["src"] + "include": ["src"], + "exclude": ["src/*.test.ts"] } diff --git a/type-tests/files/tsconfig.json b/type-tests/files/tsconfig.json index b9f3329600..afbc02ec5b 100644 --- a/type-tests/files/tsconfig.json +++ b/type-tests/files/tsconfig.json @@ -8,7 +8,7 @@ "target": "es2018", "baseUrl": "../..", "paths": { - "redux-starter-kit": ["index.d.ts"] + "redux-starter-kit": ["dist/index.d.ts"] } } } From 32ccb5d417bb6a87e79532ab5faf1a7b2796bc80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Bedi?= Date: Tue, 26 Mar 2019 17:19:50 +0100 Subject: [PATCH 3/3] fix(build): don't add interfaces to umd/esm modules --- package.json | 2 +- rollup.config.js | 3 +-- src/index.ts | 14 -------------- src/typings.ts | 15 +++++++++++++++ type-tests/files/tsconfig.json | 2 +- 5 files changed, 18 insertions(+), 18 deletions(-) create mode 100644 src/typings.ts diff --git a/package.json b/package.json index 7af9037f82..6bb5820a78 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "main": "dist/redux-starter-kit.cjs.js", "module": "dist/redux-starter-kit.esm.js", "unpkg": "dist/redux-starter-kit.umd.js", - "types": "dist/index.d.ts", + "types": "dist/typings.d.ts", "author": "Mark Erikson ", "license": "MIT", "devDependencies": { diff --git a/rollup.config.js b/rollup.config.js index 959e22eda7..c028eb6016 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -17,11 +17,10 @@ export default [ file: pkg.unpkg, format: 'umd' }, - external: Object.keys(pkg.dependencies), plugins: [ babel({ extensions, - exclude: 'node_modules/**' + exclude }), resolve({ extensions diff --git a/src/index.ts b/src/index.ts index 8f9fe0c14d..3f31fa3293 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,17 +1,3 @@ -export { - Action, - ActionCreator, - AnyAction, - Middleware, - Reducer, - Store, - StoreEnhancer, - combineReducers, - compose -} from 'redux' -export { default as createNextState } from 'immer' -export { default as createSelector } from 'selectorator' - export * from './configureStore' export * from './createAction' export * from './createReducer' diff --git a/src/typings.ts b/src/typings.ts new file mode 100644 index 0000000000..92ed425ed3 --- /dev/null +++ b/src/typings.ts @@ -0,0 +1,15 @@ +export { + Action, + ActionCreator, + AnyAction, + Middleware, + Reducer, + Store, + StoreEnhancer, + combineReducers, + compose +} from 'redux' +export { default as createNextState } from 'immer' +export { default as createSelector } from 'selectorator' + +export * from '.' diff --git a/type-tests/files/tsconfig.json b/type-tests/files/tsconfig.json index afbc02ec5b..e2da8a5654 100644 --- a/type-tests/files/tsconfig.json +++ b/type-tests/files/tsconfig.json @@ -8,7 +8,7 @@ "target": "es2018", "baseUrl": "../..", "paths": { - "redux-starter-kit": ["dist/index.d.ts"] + "redux-starter-kit": ["dist/typings.d.ts"] } } }