Replies: 4 comments 14 replies
-
Have you considered using {
"exports": {
".": "./index.js",
"./Libraries/Components/Text": "./Libraries/Components/TextInput/TextInput.js",
}
} // Error
import type {TextInputProps} from 'react-native/Libraries/Components/TextInput/TextInput';
// Works
import type {TextInputProps} from 'react-native/Libraries/Components/Text'; I think TypeScript should support it. Not sure about Flow. Metro is also adding support for it: facebook/metro#670 |
Beta Was this translation helpful? Give feedback.
-
Thanks for working on this, @lunaleaps! I agree with the problem statement and I think improving the directory structure with a better convention is a good idea, but I'm not sure it's the best solution for that problem. Take these 2 problems:
Having a directory structure to convey whether an API is public or private depends too much on human intervention. I think it'll be easier for certain private types/values to leak into public space, and also easy for certain public types/values to stay public for longer than necessary. You can't avoid imports from public to private, so there's always a chance that you ends up exposing something private indirectly through type definitions. I think automation could do this more efficiently instead. For example, we could have a build step that, from all the exports in |
Beta Was this translation helpful? Give feedback.
-
+1 to the recommendation to use Another thing we could consider is using Rollup to build a flat bundle and only publish that bundle instead of the source code. Then you could only import what's exported. |
Beta Was this translation helpful? Give feedback.
-
Happy to see those kind of proposals!
Adding to this, beside
I don't want to make this proposal grow too much, but I believe we should follow an holistic approach and define 'what the public API is' regardless of the platform. Similarly to JS, we can have a For C++, we could use forward headers (which we don't use nearly at all) to scope the visibility of our code.
Thanks for pointing this out. We recently fixed a major IDE incompatibility with the New Architecture due to C++ code being co-located with the Java/Kotlin code. As a rule of thumb, I'd try to stick to keeping the project layout that the platform provide (till we eventually device to depart from the platform build system, if ever). |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Note
Looking for feedback on this proposal! A lot of this thinking came from trying to enforce type consistency between our Flow and TS types which highlighted a lot of the problems we list below.
Some open questions:
ReactInstanceManager
, how should we handle those? Why aren't those part of our docs?Background
React Native currently defines its API via index.js. However index.js doesn’t fully capture the API that users interact with. Complex arguments (e.g. component props, events emitted) and types are not first class citizens of our public API.
This leads to users reaching into “internal files” for types and to understand React Native’s interface and concepts.
Example of products reaching in for types
Problems
Proposal
public
folderdeprecated
folder to clearly delineateProposed Code Structure
.js.flow
suffix indicates a type-only filepublic/
, should have a parallel.d.ts
public
should correspond to documentation__tests__
folder exist under bothpublic
andprivate
Proposed Documentation structure
Our current doc structure
If we want our documentation and
public
folder to mirror one another, our docs will also need re-structuring and additions of missing types. Proposing:View
style props?View
docsApproach
Will this be a breaking change?
Eventually yes. We would want people to stop reaching in
react-native
library and move to imports fromindex.js
For a gradual migration strategy, we can continue to keep our existing repo structure and curate our
public
APIs and have them point to current implementation locations.E.g.
js/public/Text/TextInputProps.js.flow
For the breaking change release version, we can then move internal implementations under
private/
.Future
deprecated
folder for apps that don’t use any deprecated componentsE.g. index.deprecated.js
Beta Was this translation helpful? Give feedback.
All reactions