fbt
fbt copied to clipboard
Need to share some common JS code between clientside fbt.js and Babel transform node modules
🚀 Feature Proposal
Currently, we have some JS constants that are defined twice on the clientside and Babel transform modules.
E.g. The Gender constant object that defines all the supported types of genders is defined in two places that need to be kept up to date manually.
- https://github.com/facebook/fbt/blob/a61a13b5a259b889dd674d30da02242a15bcd951/runtime/nonfb/GenderConst.js#L16-L32
- https://github.com/facebook/fbt/blob/a61a13b5a259b889dd674d30da02242a15bcd951/packages/babel-plugin-fbt/Gender.js#L12-L29
Motivation
Going forward, it'd make sense to avoid having to write duplicate JS constants. Some JS functions might even be shared in the future.
How to do it?
We should figure out a way to share some common constants between the node.js and client-side modules.
Maybe by having the fbt
npm module become a peerDependency of babel-plugin-fbt
?
Or by defining the shared JS code into a special folder that'd be accessible to both babel-plugin-fbt
and fbt
in Flow checks, and also bundled in these respective npm modules using some Gulp magic?