-
Notifications
You must be signed in to change notification settings - Fork 827
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
chore: export flow types #94
Conversation
package.json
Outdated
@@ -18,6 +18,7 @@ | |||
}, | |||
"scripts": { | |||
"lint": "eslint ./", | |||
"flow": "flow --show-all-errors", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be run on commit hook as well and be addressed in another PR
scripts/prepublish.sh
Outdated
@@ -6,4 +6,5 @@ fi; | |||
# When Buildkite publishes to npm, the published files are available in the root | |||
# directory, which allows for a clean include or require of sub-modules. | |||
yarn build | |||
node ./scripts/prepublish-flow.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure whether this would work in CI?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Come to think of it, I could just add $FlowFixMe
and be done with it during rollup.
So we might end up not needing this prepublish-flow.js
.npmignore
Outdated
*.test.js | ||
*.setup.js | ||
*.stories.js | ||
stories.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*.stories.js
stories.js
Can these be combined into just stories.js
?
.npmignore
Outdated
*.stories.js | ||
stories.js | ||
*.test.js.snap | ||
test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*.test.js
*.test.js.snap
test
Can we combine these into just test
?
I'm not sure how to fix this flowtype from
|
@ardok, rollup plugin you wrote looks interesting. Can you help me understand if the same result would be achieved if we use something like flow-copy-source in our |
rollup.config.js
Outdated
@@ -9,6 +9,8 @@ import commonjs from 'rollup-plugin-commonjs'; | |||
import fs from 'fs'; | |||
import path from 'path'; | |||
|
|||
import uberFlowEntry from './scripts/rollup-plugin-flow-entry'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's not use 'uber' prefix here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okie
@DianaSuvorova Actually, we should use that |
What do you mean by an entry file? |
|
rollup.config.js
Outdated
@@ -70,6 +72,8 @@ function getSharedConfig({filePath, name}) { | |||
'node_modules/create-react-context/index.js': ['createReactContext'], | |||
}, | |||
}), | |||
flowEntry(), | |||
// flowCopySrc(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this
package.json
Outdated
"files": ["dist"], | ||
"main": "dist/baseui.js", | ||
"jsnext:main": "dist/baseui.es.js", | ||
"module": "dist/baseui.es.js", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ay, remove these
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job! Left you some comments mostly questions. so sad gen-flow-files
is so buggy that we have to do this.
scripts/flow-copy-src.js
Outdated
@@ -0,0 +1,19 @@ | |||
/* eslint-disable flowtype/require-valid-file-annotation */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why don't you just add // @flow
it shouldn't hurt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, yeah, I'll try that
scripts/rollup-plugin-flow-entry.js
Outdated
@@ -0,0 +1,73 @@ | |||
/* eslint-disable flowtype/require-valid-file-annotation */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here: // @flow
?
import path from 'path'; | ||
|
||
/* | ||
We can consider this as well: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, if you are adding this comment, can you explain why we didn't end up using it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will add more
scripts/rollup-plugin-flow-entry.js
Outdated
|
||
function getFlowFileContent(filePath) { | ||
/* | ||
Since we're going to copy `dist` dictionary into root in our publish step, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is not the case anymore. We are not copying dist into root. we are distributing dist instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will update the comments
scripts/rollup-plugin-flow-entry.js
Outdated
we will need to remove one level of the path. | ||
Hence, instead of `../src` and `../../src`, they will become `./src` and `../src` respectively. | ||
*/ | ||
const regex = new RegExp(/\.\.\//, 'g'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you explain what this regex matches. I guess some descriptive name instead of regex
would do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, will add more comments on it
@@ -13,3 +13,6 @@ export { | |||
Caption as StyledCaption, | |||
} from './styled-components'; | |||
export {STATE_CHANGE_TYPE, ADJOINED, SIZE} from './constants'; | |||
|
|||
// Flow | |||
export * from './types'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need to export these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So that you could do:
import type {BaseInputPropsT} from '@uber/baseui/input
Looks good to me |
* chore: export flow type * chore: simply flow export * chore: add comment * chore: use .js.flow files * chore: rebase with master * chore: rebase with master * chore: remove flow from scripts * chore: remove flowfixme * chore: go away unpm * chore: undo package.json changes on files and main stuff * chore: address comments * fix: flow error
Resolves: https://github.com/uber-web/baseui/issues/41
In order to export flow types, we need to include the original files that have the flow definition.
What we're going to do is to add
export * from './types.js'
from each components.Then, we will add an accompanying files inside our
dist
directory (using a rollup plugin) that will end with.js.flow
.The content of the file will only be something like:
Then, we'll use
flow-copy-source
on oursrc
directory by excluding some files using glob patterns.And voila.
Alternatives
There's
flow gen-flow-files
, but it's still "experimental" and people seem to have issues with it.facebook/flow#5519
Have tried it for baseui, and we also faced more issues:
facebook/flow#6171
facebook/flow#3281
Samples
Test
There might be other ways to test this, but this is how I test it:
yarn build
package.json
underdist
npm pack
(npm pack
will produce a tgz file).foo
, donpm install --save path/to/tgz/file
foo/node_modules/@uber/baseui
and copy the content ofdist
into the root offoo/node_modules/@uber/baseui
.dist
directory../node_modules/.bin/flow stop && ./node_modules/.bin/flow
on your project root