From 1921ff0c0389b434c54cc2e39828f2aacf4f1c13 Mon Sep 17 00:00:00 2001 From: Khoa Nguyen Date: Wed, 17 Aug 2016 17:39:02 +0700 Subject: [PATCH] Upgrade flow to version 0.30.0 --- .flowconfig | 2 +- flow-typed/npm/classnames_v2.x.x.js | 15 ++++ flow-typed/npm/react-redux_v4.x.x.js | 81 ++++++++++++++++++++ flow-typed/npm/redux_v3.x.x.js | 32 ++++++++ interfaces/node-modules/fs-promise.js | 4 +- interfaces/node-modules/redbox-react.js | 2 +- interfaces/node-modules/simple-json-fetch.js | 2 +- package.json | 5 +- scripts/flow-check.js | 11 --- src/ContextProvider/index.js | 2 +- src/Link/index.js | 2 +- src/PageContainer/component.js | 6 +- src/client/index.js | 2 +- src/components/BodyContainer/index.js | 4 +- src/phenomic-loader-preset-markdown/index.js | 3 - src/redux/modules/pages.js | 2 +- src/static/postbuild.js | 2 +- 17 files changed, 145 insertions(+), 32 deletions(-) create mode 100644 flow-typed/npm/classnames_v2.x.x.js create mode 100644 flow-typed/npm/react-redux_v4.x.x.js create mode 100644 flow-typed/npm/redux_v3.x.x.js delete mode 100644 scripts/flow-check.js diff --git a/.flowconfig b/.flowconfig index 57247202e..699e31432 100644 --- a/.flowconfig +++ b/.flowconfig @@ -7,8 +7,8 @@ .*/.nyc_output/.* [libs] -./node_modules/flow-interfaces/interfaces/ ./interfaces/ +./flow-typed/ [options] esproposal.class_instance_fields=enable diff --git a/flow-typed/npm/classnames_v2.x.x.js b/flow-typed/npm/classnames_v2.x.x.js new file mode 100644 index 000000000..675f2a76a --- /dev/null +++ b/flow-typed/npm/classnames_v2.x.x.js @@ -0,0 +1,15 @@ +// flow-typed signature: 62bc5615b7c27f8f00718fec93336e7f +// flow-typed version: ef0148e929/classnames_v2.x.x/flow_>=v0.28.x + +type $npm$classnames$Classes = + string | + {[className: string]: ?boolean } | + Array | + void | + null + +declare module 'classnames' { + declare function exports( + ...classes: Array<$npm$classnames$Classes> + ): string; +} diff --git a/flow-typed/npm/react-redux_v4.x.x.js b/flow-typed/npm/react-redux_v4.x.x.js new file mode 100644 index 000000000..40d4fa6b5 --- /dev/null +++ b/flow-typed/npm/react-redux_v4.x.x.js @@ -0,0 +1,81 @@ +// flow-typed signature: 708adb773a9ad8abf8edbbb240cc59b4 +// flow-typed version: f86b0822d6/react-redux_v4.x.x/flow_>=v0.30.x + +/* @flow */ +type ConnectAll = , SP, DP, Dispatch: Function>( + mapStateToProps: (state: Object, ownProps: $Diff<$Diff<$Diff, SP>, D>) => SP, + mapDispatchToProps: (dispatch: Dispatch, ownProps: $Diff<$Diff<$Diff, SP>, D>) => DP, + mergeProps: null | void, + options?: {pure?: boolean, withRef?: boolean} +) => (component: Class) => Class, SP>, S>>; + +type ConnectAllStateless = ( + mapStateToProps: (state: Object, ownProps: $Diff<$Diff, SP>) => SP, + mapDispatchToProps: (dispatch: Dispatch, ownProps: $Diff<$Diff, SP>) => DP, + mergeProps: null | void, + options?: {pure?: boolean, withRef?: boolean} +) => (component: (props: P) => any) => Class, SP>, void>>; + +type ConnectMerged = , SP, DP, MP, Dispatch: Function>( + mapStateToProps: (state: Object, ownProps: $Diff<$Diff, D>) => SP, + mapDispatchToProps: (dispatch: Dispatch, ownProps: $Diff<$Diff, D>) => DP, + mergeProps: (stateProps: SP, dispatchProps: DP, ownProps: $Diff<$Diff, D>) => MP, + options?: {pure?: boolean, withRef?: boolean} +) => (component: Class) => Class, S>>; + +type ConnectMergedStateless = ( + mapStateToProps: (state: Object, ownProps: $Diff) => SP, + mapDispatchToProps: (dispatch: Dispatch, ownProps: $Diff) => DP, + mergeProps: (stateProps: SP, dispatchProps: DP, ownProps: $Diff) => MP, + options?: {pure?: boolean, withRef?: boolean} +) => (component: (props: P) => any) => Class, void>>; + +type ConnectNoState = , DP, Dispatch: Function>( + mapStateToProps: null | void, + mapDispatchToProps: (dispatch: Dispatch, ownProps: $Diff<$Diff, D>) => DP, + mergeProps: null | void, + options?: {pure?: boolean, withRef?: boolean} + ) => (component: Class) => Class, S>>; + +type ConnectNoStateStatless = ( + mapStateToProps: null | void, + mapDispatchToProps: (dispatch: Dispatch, ownProps: $Diff) => DP, + mergeProps: null | void, + options?: {pure?: boolean, withRef?: boolean} + ) => (component: (props: P) => any) => Class, void>>; + +type ConnectDispatch = , SP, Dispatch: Function>( + mapStateToProps: (state: Object, ownProps: $Diff<$Diff<$Diff, SP>, D>) => SP, + mapDispatchToProps: null | void, + mergeProps: null | void, + options?: {pure?: boolean, withRef?: boolean} +) => (component: Class) => Class, SP>, S>>; + +type ConnectDispatchStateless = ( + mapStateToProps: (state: Object, ownProps: $Diff<$Diff, SP>) => SP, + mapDispatchToProps: null | void, + mergeProps: null | void, + options?: {pure?: boolean, withRef?: boolean} +) => (component: (props: P) => any) => Class, SP>, void>>; + +type ConnectDefault = , Dispatch: Function>() => + (component: Class) => Class, S>>; + +type ConnectDefaultStateless = () => +

(component: (props: P) => any) => Class, void>>; + +declare module 'react-redux' { + declare var exports: { + connect: ConnectAll + & ConnectAllStateless + & ConnectMerged + & ConnectMergedStateless + & ConnectNoState + & ConnectNoStateStatless + & ConnectDispatch + & ConnectDispatchStateless + & ConnectDefault + & ConnectDefaultStateless; + Provider: ReactClass<{store: Object, children?: any}>; + } +} diff --git a/flow-typed/npm/redux_v3.x.x.js b/flow-typed/npm/redux_v3.x.x.js new file mode 100644 index 000000000..f4c6d3359 --- /dev/null +++ b/flow-typed/npm/redux_v3.x.x.js @@ -0,0 +1,32 @@ +// flow-typed signature: 3b60d0484a561f2e7c43ac2a5eb28d87 +// flow-typed version: f622abbe3e/redux_v3.x.x/flow_>=v0.23.x + +declare module 'redux' { + declare type State = any; + declare type Action = Object; + declare type AsyncAction = any; + declare type Reducer = (state: S, action: A) => S; + declare type BaseDispatch = (a: Action) => Action; + declare type Dispatch = (a: Action | AsyncAction) => any; + declare type ActionCreator = (...args: any) => Action | AsyncAction; + declare type MiddlewareAPI = { dispatch: Dispatch, getState: () => State }; + declare type Middleware = (api: MiddlewareAPI) => (next: Dispatch) => Dispatch; + declare type Store = { + dispatch: Dispatch, + getState: () => State, + subscribe: (listener: () => void) => () => void, + replaceReducer: (reducer: Reducer) => void + }; + declare type StoreCreator = (reducer: Reducer, initialState: ?State) => Store; + declare type StoreEnhancer = (next: StoreCreator) => StoreCreator; + declare type ActionCreatorOrObjectOfACs = ActionCreator | { [key: string]: ActionCreator }; + declare type Reducers = { [key: string]: Reducer }; + declare class Redux { + bindActionCreators(actionCreators: actionCreators, dispatch: Dispatch): actionCreators; + combineReducers(reducers: Reducers): Reducer; + createStore(reducer: Reducer, initialState?: State, enhancer?: StoreEnhancer): Store; + applyMiddleware(...middlewares: Array): StoreEnhancer; + compose(...functions: Array): Function; + } + declare var exports: Redux; +} diff --git a/interfaces/node-modules/fs-promise.js b/interfaces/node-modules/fs-promise.js index 397b15094..d33f2555c 100644 --- a/interfaces/node-modules/fs-promise.js +++ b/interfaces/node-modules/fs-promise.js @@ -1,6 +1,6 @@ declare module "fs-promise" { - declare function writeFile(to: string, content: string): Promise; - declare function mkdirs(path: string): Promise; + declare function writeFile(to: string, content: string): Promise; + declare function mkdirs(path: string): Promise; declare interface fsPromise { writeFile: writeFile, diff --git a/interfaces/node-modules/redbox-react.js b/interfaces/node-modules/redbox-react.js index 6aa0198e0..22882486c 100644 --- a/interfaces/node-modules/redbox-react.js +++ b/interfaces/node-modules/redbox-react.js @@ -1,3 +1,3 @@ declare module "redbox-react" { - declare var exports: ReactClass; + declare var exports: ReactClass; } diff --git a/interfaces/node-modules/simple-json-fetch.js b/interfaces/node-modules/simple-json-fetch.js index 6e06fd525..6c969d0df 100644 --- a/interfaces/node-modules/simple-json-fetch.js +++ b/interfaces/node-modules/simple-json-fetch.js @@ -1,6 +1,6 @@ declare module "simple-json-fetch" { declare class SimpleJsonFetch { - (uri: string): Promise; + (uri: string): Promise; } declare var exports: SimpleJsonFetch; } diff --git a/package.json b/package.json index 67eceb380..b54ab5245 100644 --- a/package.json +++ b/package.json @@ -100,8 +100,7 @@ "exec-cmd": "^2.0.1", "expect": "^1.13.4", "expect-jsx": "^2.2.1", - "flow-bin": "^0.27.0", - "flow-interfaces": "^0.5.0", + "flow-bin": "^0.30.0", "image-optim": "^3.0.0", "js-beautify": "^1.5.10", "jsdom": "^9.2.0", @@ -172,7 +171,7 @@ "prepublish": "rimraf lib && npm run transpile", "#lint:js:eslint": "https://github.com/eslint/eslint/issues/5679", "lint:js:eslint": "eslint --ignore-path .gitignore --fix src __tests__ scripts npm interfaces docs/scripts docs/src docs/web_modules boilerplate/scripts boilerplate/src boilerplate/web_modules", - "lint:js:flow": "babel-node scripts/flow-check.js", + "lint:js:flow": "flow check", "lint:js": "npm-run-all --parallel lint:js:*", "lint:css": "stylelint \"+(boilerplate|docs)/web_modules/**/*.css\"", "lint": "npm-run-all --parallel lint:*", diff --git a/scripts/flow-check.js b/scripts/flow-check.js deleted file mode 100644 index c26f9858f..000000000 --- a/scripts/flow-check.js +++ /dev/null @@ -1,11 +0,0 @@ -import { execFileSync } from "child_process" -import flowBin from "flow-bin" - -try { - if (process.platform !== "win32") { - execFileSync(flowBin, [ "check" ], { stdio: "inherit" }) - } -} -catch (e) { - process.exit(1) -} diff --git a/src/ContextProvider/index.js b/src/ContextProvider/index.js index b0a1825d7..36691ce56 100644 --- a/src/ContextProvider/index.js +++ b/src/ContextProvider/index.js @@ -27,7 +27,7 @@ export default class PhenomicContext extends Component { } } - render(): React$Element { + render(): React$Element { return Children.only(this.props.children) } } diff --git a/src/Link/index.js b/src/Link/index.js index 9900fb105..9c7edb18d 100644 --- a/src/Link/index.js +++ b/src/Link/index.js @@ -12,7 +12,7 @@ export function Link( children: any, }, { router }: { router: Object } -): React$Element { +): React$Element { return ( | void { if (props.layouts && props.layouts[layout]) { return props.layouts[layout] } } class PageContainer extends Component { - _content: Element; + _content: HTMLElement; propTypes: Props; @@ -198,7 +198,7 @@ class PageContainer extends Component { } } - saveContentRef: Function = (ref: Element): void => { + saveContentRef: Function = (ref: HTMLElement): void => { this._content = ref }; diff --git a/src/client/index.js b/src/client/index.js index 008c1b5d4..14fc70d63 100644 --- a/src/client/index.js +++ b/src/client/index.js @@ -24,7 +24,7 @@ export default function phenomic({ store, }: { metadata: Object, - routes: React$Element, + routes: React$Element, store: Object, }): void { const collection = diff --git a/src/components/BodyContainer/index.js b/src/components/BodyContainer/index.js index b09e847fb..87d690044 100644 --- a/src/components/BodyContainer/index.js +++ b/src/components/BodyContainer/index.js @@ -3,12 +3,12 @@ import React, { Component } from "react" type Props = { - children: React$Element + children: React$Element } class BodyContainer extends Component { - render(): React$Element { + render(): React$Element { const { props }: { props: Props } = this return ( diff --git a/src/phenomic-loader-preset-markdown/index.js b/src/phenomic-loader-preset-markdown/index.js index a4e032ebc..b7717cedf 100644 --- a/src/phenomic-loader-preset-markdown/index.js +++ b/src/phenomic-loader-preset-markdown/index.js @@ -9,10 +9,7 @@ import transformBodyPropertyToHtml from "../phenomic-loader-plugin-markdown-transform-body-property-to-html" export default [ - // $FlowFixMe Missing annotation wtf? ...defaultPlugins, - // $FlowFixMe Missing annotation wtf? initHeadDescriptionPropertyFromContent, - // $FlowFixMe Missing annotation wtf? transformBodyPropertyToHtml, ] diff --git a/src/redux/modules/pages.js b/src/redux/modules/pages.js index 395d3d731..791422987 100644 --- a/src/redux/modules/pages.js +++ b/src/redux/modules/pages.js @@ -113,7 +113,7 @@ export function refresh(page: string, url: string): PromiseAction { } } -export function setNotFound(page: string): Action { +export function setNotFound(page: string): Object { return { type: ERROR, page, diff --git a/src/static/postbuild.js b/src/static/postbuild.js index b951b02a6..956181494 100644 --- a/src/static/postbuild.js +++ b/src/static/postbuild.js @@ -10,7 +10,7 @@ export default function( config: PhenomicConfig, files: Array, log: Function -): Promise { +): Promise { log(green(`✓ Static html files: ${ files.length } files written.`)) const promises = []