Rome detects imports that are only used in TS or Flow types and marks them when analyzing dependencies. These imports will not effect module order or be included in a bundle. Files that contain only types will never need to be included.
-
Show this thread
-
Replying to @sebmck
Nice! What happens if a module only use the types from another module that has side effects? Is this detected and taken into account? When
@mjesun and me were exploring to do tree shaking in metro these kind of things were really challenging to do in a performant way1 reply 0 retweets 4 likes -
The implementation was driven by TypeScript which doesn't have 'import type'. It resulted in a bunch of unfixable module cycles inside Rome (I'm converting it from Flow). Whether a module is marked as "only for types" isn't effected by anything about the file itself.
1 reply 0 retweets 3 likes -
Makes sense, relying on the side effects of a module that was imported just for its types is quite an edge case
i was just curious if Rome did some kind of pre-analysis of dependencies before building the graph2 replies 0 retweets 1 like -
There's a step called analyzeDependencies which is just a method in the Rome compiler that does some single-file static analysis. It's super cachable and includes stuff like if it uses top level await, where are imports used for the first time (cycle detection) etc
1 reply 0 retweets 2 likes -
You could encode some information in there, such as if the module didn't have any side effects, only exported types etc. Then you can reunify those artifacts later when constructing the actual dependency graph.
1 reply 0 retweets 1 like -
Could you use this step to encode a list of imports/exports to later do dead code elimitation of unused exports?
1 reply 0 retweets 0 likes
Yeah, that information is already collected. It's used currently to validate the existence of imports. It's also used to "resolve" complete locations when building a flat bundle. This is the current analyzeDependencies interfacehttps://gist.github.com/sebmck/33ad6649edcb3e8f19a641e16eee1a86 …
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
he/him 