Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

Commit

Permalink
feat(js): Make flow work
Browse files Browse the repository at this point in the history
tl;dr use `flow-check` script to typecheck code.

Add a babel plugin to strip out type declarations from resulting code,
thus making it possible to actually write them and have things working
afterwards.

Also brings in `flow-result-checker`, an ugly workaround for
facebook/flow#869 - the tl;dr is Flow reports
type errors in all the `//@flow`'ed files, including ones in
`node_modules` - which isn't entirely helpful.

This affects us due to expo/ex-navigation#87,
the tl;dr for which is ex-navigation has type errors and no one seems
to be working on it ATM.

So, code can currently be typechecked as mentioned at the top of the
commit message; also, one of the components has been annotated to demonstrate.
  • Loading branch information
wldhx committed Feb 3, 2017
1 parent ec9b221 commit b9859c6
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 8 deletions.
5 changes: 4 additions & 1 deletion telemetry_ga_android/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
"presets": [
"react-native",
"react-native-stage-0/decorator-support",
]
],
"plugins": [
"transform-flow-strip-types",
],
}
1 change: 0 additions & 1 deletion telemetry_ga_android/.flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
[libs]
node_modules/react-native/Libraries/react-native/react-native-interface.js
node_modules/react-native/flow
flow/

[options]
module.system=haste
Expand Down
9 changes: 6 additions & 3 deletions telemetry_ga_android/SwitchingComponent.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export default (props) => {
const i = Math.trunc(props.flex_count / 25) % props.sources.length;
return props.sources[i];
// @flow
export default ({ flex_count, sources }:
{ flex_count: number,
sources: Array<ReactClass<*>> }) => {
const i = Math.trunc(flex_count / 25) % sources.length;
return sources[i];
};
8 changes: 6 additions & 2 deletions telemetry_ga_android/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
"name": "@motorica-org/telemetry_ga_android",
"version": "0.1.0",
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start"
"start": "node node_modules/react-native/local-cli/cli.js start",
"flow-check": "flow check | flow-result-checker"
},
"dependencies": {
"@exponent/ex-navigation": "^2.7.1",
"babel-plugin-transform-flow-strip-types": "^6.22.0",
"babel-preset-react-native-stage-0": "^1.0.1",
"react": "^15.4.2",
"react-native": "^0.40.0",
Expand All @@ -18,6 +20,8 @@
"eslint-config-airbnb": "^14.0.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^3.0.2",
"eslint-plugin-react": "^6.9.0"
"eslint-plugin-react": "^6.9.0",
"flow-bin": "0.36.0",
"flow-result-checker": "^0.1.1"
}
}
61 changes: 60 additions & 1 deletion telemetry_ga_android/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ babel-plugin-transform-export-extensions@^6.5.0:
babel-plugin-syntax-export-extensions "^6.8.0"
babel-runtime "^6.22.0"

babel-plugin-transform-flow-strip-types@^6.18.0, babel-plugin-transform-flow-strip-types@^6.5.0, babel-plugin-transform-flow-strip-types@^6.7.0, babel-plugin-transform-flow-strip-types@^6.8.0:
babel-plugin-transform-flow-strip-types@^6.18.0, babel-plugin-transform-flow-strip-types@^6.22.0, babel-plugin-transform-flow-strip-types@^6.5.0, babel-plugin-transform-flow-strip-types@^6.7.0, babel-plugin-transform-flow-strip-types@^6.8.0:
version "6.22.0"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-flow-strip-types/-/babel-plugin-transform-flow-strip-types-6.22.0.tgz#84cb672935d43714fdc32bce84568d87441cf7cf"
dependencies:
Expand Down Expand Up @@ -1011,6 +1011,16 @@ cli-cursor@^1.0.1:
dependencies:
restore-cursor "^1.0.1"

cli-cursor@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-2.1.0.tgz#b35dac376479facc3e94747d41d0d0f5238ffcb5"
dependencies:
restore-cursor "^2.0.0"

cli-spinners@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/cli-spinners/-/cli-spinners-1.0.0.tgz#ef987ed3d48391ac3dab9180b406a742180d6e6a"

cli-width@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-2.1.0.tgz#b234ca209b29ef66fc518d9b98d5847b00edf00a"
Expand Down Expand Up @@ -1707,6 +1717,19 @@ flat-cache@^1.2.1:
graceful-fs "^4.1.2"
write "^0.2.1"

[email protected]:
version "0.36.0"
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.36.0.tgz#557907bd9c2ab0670cfad9e7e906a74b0631e39a"

flow-result-checker@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/flow-result-checker/-/flow-result-checker-0.1.1.tgz#b42431448c312bb5059c17435e7da8df95f6a26c"
dependencies:
chalk "^1.1.3"
commander "^2.9.0"
mkdirp "^0.5.1"
ora "^1.1.0"

foreach@^2.0.5:
version "2.0.5"
resolved "https://registry.yarnpkg.com/foreach/-/foreach-2.0.5.tgz#0bee005018aeb260d0a3af3ae658dd0136ec1b99"
Expand Down Expand Up @@ -2379,6 +2402,12 @@ lodash@^4.0.0, lodash@^4.14.0, lodash@^4.16.6, lodash@^4.2.0, lodash@^4.2.1, lod
version "4.17.4"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"

log-symbols@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-1.0.2.tgz#376ff7b58ea3086a0f09facc74617eca501e1a18"
dependencies:
chalk "^1.0.0"

longest@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097"
Expand Down Expand Up @@ -2447,6 +2476,10 @@ [email protected], mime@^1.3.4:
version "1.3.4"
resolved "https://registry.yarnpkg.com/mime/-/mime-1.3.4.tgz#115f9e3b6b3daf2959983cb38f149a2d40eb5d53"

mimic-fn@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.1.0.tgz#e667783d92e89dbd342818b5230b9d62a672ad18"

min-document@^2.19.0:
version "2.19.0"
resolved "https://registry.yarnpkg.com/min-document/-/min-document-2.19.0.tgz#7bd282e3f5842ed295bb748cdd9f1ffa2c824685"
Expand Down Expand Up @@ -2609,6 +2642,12 @@ onetime@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/onetime/-/onetime-1.1.0.tgz#a1f7838f8314c516f05ecefcbc4ccfe04b4ed789"

onetime@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/onetime/-/onetime-2.0.0.tgz#52aa8110e52fc5126ffc667bd8ec21c2ed209ce6"
dependencies:
mimic-fn "^1.0.0"

opn@^3.0.2:
version "3.0.3"
resolved "https://registry.yarnpkg.com/opn/-/opn-3.0.3.tgz#b6d99e7399f78d65c3baaffef1fb288e9b85243a"
Expand Down Expand Up @@ -2637,6 +2676,15 @@ options@>=0.0.5:
version "0.0.6"
resolved "https://registry.yarnpkg.com/options/-/options-0.0.6.tgz#ec22d312806bb53e731773e7cdaefcf1c643128f"

ora@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/ora/-/ora-1.1.0.tgz#69aaa4a209630e43b142c5f7ff41820da87e2faf"
dependencies:
chalk "^1.1.1"
cli-cursor "^2.1.0"
cli-spinners "^1.0.0"
log-symbols "^1.0.2"

os-homedir@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/os-homedir/-/os-homedir-1.0.2.tgz#ffbc4988336e0e833de0c168c7ef152121aa7fb3"
Expand Down Expand Up @@ -3143,6 +3191,13 @@ restore-cursor@^1.0.1:
exit-hook "^1.0.0"
onetime "^1.0.0"

restore-cursor@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/restore-cursor/-/restore-cursor-2.0.0.tgz#9f7ee287f82fd326d4fd162923d62129eee0dfaf"
dependencies:
onetime "^2.0.0"
signal-exit "^3.0.2"

right-align@^0.1.1:
version "0.1.3"
resolved "https://registry.yarnpkg.com/right-align/-/right-align-0.1.3.tgz#61339b722fe6a3515689210d24e14c96148613ef"
Expand Down Expand Up @@ -3263,6 +3318,10 @@ shelljs@^0.7.5:
interpret "^1.0.0"
rechoir "^0.6.2"

signal-exit@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"

[email protected]:
version "0.1.4"
resolved "https://registry.yarnpkg.com/simple-plist/-/simple-plist-0.1.4.tgz#10eb51b47e33c556eb8ec46d5ee64d64e717db5d"
Expand Down

0 comments on commit b9859c6

Please sign in to comment.