Skip to content

Commit

Permalink
Defer to rollup TS plugin to build types (#3564)
Browse files Browse the repository at this point in the history
* Defer to rollup TS plugin to build types

* index.ts -> redux.js, redux.d.ts

* Only output one copy of the types.

This also puts them back into the types path. However, I don't know how to have them output as a single file bundle to match our other outputs.

* Remove the move


Co-authored-by: Tim Dorr <git@timdorr.com>
  • Loading branch information
jedmao and timdorr committed Sep 6, 2019
1 parent 9e71b4c commit d8417e8
Show file tree
Hide file tree
Showing 14 changed files with 23 additions and 35 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
.DS_Store
*.log
node_modules

coverage

dist
lib
es
coverage
types

website/translated_docs
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,13 @@
"format": "prettier --write \"{src,test}/**/*.{js,ts}\" index.d.ts \"**/*.md\"",
"format:check": "prettier --list-different \"{src,test}/**/*.{js,ts}\" index.d.ts \"**/*.md\"",
"lint": "eslint --ext js,ts src test",
"check-types": "tsc --noEmit",
"pretest": "npm run build",
"test": "jest",
"test:watch": "npm test -- --watch",
"test:cov": "npm test -- --coverage",
"build": "npm run build-types && rollup -c",
"build": "rollup -c",
"prepare": "npm run clean && npm run check-types && npm run format:check && npm run lint && npm test",
"build-types": "tsc --emitDeclarationOnly",
"check-types": "tsc --noEmit",
"examples:lint": "eslint --ext js,ts examples",
"examples:test": "cross-env CI=true babel-node examples/testAll.js"
},
Expand Down
12 changes: 7 additions & 5 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { terser } from 'rollup-plugin-terser'

import pkg from './package.json'

const noDeclarationFiles = { compilerOptions: { declaration: false } };

export default [
// CommonJS
{
Expand All @@ -19,7 +21,7 @@ export default [
nodeResolve({
extensions: ['.ts']
}),
typescript(),
typescript({ useTsconfigDeclarationDir: true }),
babel()
]
},
Expand All @@ -36,7 +38,7 @@ export default [
nodeResolve({
extensions: ['.ts']
}),
typescript(),
typescript({ tsconfigOverride: noDeclarationFiles }),
babel()
]
},
Expand All @@ -52,7 +54,7 @@ export default [
replace({
'process.env.NODE_ENV': JSON.stringify('production')
}),
typescript(),
typescript({ tsconfigOverride: noDeclarationFiles }),
babel({
exclude: 'node_modules/**'
}),
Expand Down Expand Up @@ -80,7 +82,7 @@ export default [
nodeResolve({
extensions: ['.ts']
}),
typescript(),
typescript({ tsconfigOverride: noDeclarationFiles }),
babel({
exclude: 'node_modules/**'
}),
Expand All @@ -103,7 +105,7 @@ export default [
nodeResolve({
extensions: ['.ts']
}),
typescript(),
typescript({ tsconfigOverride: noDeclarationFiles }),
babel({
exclude: 'node_modules/**'
}),
Expand Down
2 changes: 1 addition & 1 deletion test/typescript/actionCreators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Dispatch,
bindActionCreators,
ActionCreatorsMapObject
} from 'redux'
} from '../..'

interface AddTodoAction extends Action {
text: string
Expand Down
2 changes: 1 addition & 1 deletion test/typescript/actions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Action as ReduxAction } from 'redux'
import { Action as ReduxAction } from '../..'

namespace FSA {
interface Action<P> extends ReduxAction {
Expand Down
2 changes: 1 addition & 1 deletion test/typescript/compose.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { compose } from 'redux'
import { compose } from '../..'

// adapted from DefinitelyTyped/compose-function

Expand Down
2 changes: 1 addition & 1 deletion test/typescript/dispatch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Dispatch, AnyAction } from 'redux'
import { Dispatch } from '../..'

/**
* Default Dispatch type accepts any object with `type` property.
Expand Down
9 changes: 1 addition & 8 deletions test/typescript/enhancers.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {
StoreEnhancer,
Action,
AnyAction,
Reducer,
createStore,
PreloadedState
} from 'redux'
import { StoreEnhancer, Action, AnyAction, Reducer, createStore } from '../..'

interface State {
someField: 'string'
Expand Down
2 changes: 1 addition & 1 deletion test/typescript/injectedDispatch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Dispatch, Action } from 'redux'
import { Dispatch, Action } from '../..'

interface Component<P> {
props: P
Expand Down
3 changes: 1 addition & 2 deletions test/typescript/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import {
Middleware,
MiddlewareAPI,
applyMiddleware,
StoreEnhancer,
createStore,
Dispatch,
Reducer,
Action,
AnyAction
} from 'redux'
} from '../..'

/**
* Logger middleware doesn't add any extra types to dispatch, just logs actions
Expand Down
2 changes: 1 addition & 1 deletion test/typescript/reducers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Reducer, Action, combineReducers, ReducersMapObject } from 'redux'
import { Reducer, Action, combineReducers, ReducersMapObject } from '../..'

/**
* Simple reducer definition with no action shape checks.
Expand Down
2 changes: 1 addition & 1 deletion test/typescript/replaceReducer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { combineReducers, createStore } from 'redux'
import { combineReducers, createStore } from '../..'

/**
* verify that replaceReducer maintains strict typing if the new types change
Expand Down
4 changes: 1 addition & 3 deletions test/typescript/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import {
Reducer,
Action,
StoreEnhancer,
StoreCreator,
StoreEnhancerStoreCreator,
Unsubscribe,
Observer,
ExtendState
} from 'redux'
} from '../..'
import 'symbol-observable'

type State = {
Expand Down
5 changes: 1 addition & 4 deletions test/typescript/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
"compilerOptions": {
"lib": ["es2017", "dom"],
"strict": true,
"baseUrl": "../..",
"paths": {
"redux": ["types/index.d.ts"]
}
"baseUrl": "../.."
}
}

0 comments on commit d8417e8

Please sign in to comment.