require.context
/ dynamic filesystem dependencies in Metro
#1515
Replies: 2 comments 3 replies
-
Just guessing, I imagine this part could be achieved with
Also guessing, would this be something like
If I add a new file, how would the serializer know to update. Is there any existing mechanism for updating the serializer based on a file change? If not, where does this need to go?
Not sure what this means, my guess would be this. |
Beta Was this translation helpful? Give feedback.
-
I want to share a quick update on the current progress, and a longer spec / brain dump regarding what's next. tl;dr we are taking the "virtual module" approach I briefly mentioned above.
@EvanBacon is implementing this in facebook/metro#821 as a change to The current implementation is gated by the
@EvanBacon opened facebook/metro#822 to add the regex expansion functionality to DependencyGraph. The big piece left is to teach DeltaBundler to first generate, then update the necessary context modules ( = virtual modules based on NOTE: Code pointers below are based on the branch in facebook/metro#820, not Generating context modules for the first timeBuilding the graph starts with
Updating context modules on relevant file changesWhen a file (regular module) that is part of an existing dependency graph changes on disk, we start traversing from that module, which leads to NOTE: A design goal here is to avoid both false negatives (not invalidating on a relevant change) and false positives (invalidating on an irrelevant change). When a context module is added to the graph, it will be because some other module has changed and gone through The trick here is to detect when a context module has "changed". Remember that a context module has a fake path, so no filesystem event will directly mention it. Instead, a context module "changes" when the set of expanded files matching its This all boils down to the following two rules:
Code pointers:
Drawbacks of this designIf |
Beta Was this translation helpful? Give feedback.
-
Hoisting this from
#metro
on Discord for visibility - I've sketched out an idea for how Metro might support something like Webpack'srequire.context
. This is in response to a question from @EvanBacon about trying to implementrequire.context
in a transformer, and running into cache invalidation issues as a result.https://discord.com/channels/514829729862516747/514832110595604510/976020483478786100
Beta Was this translation helpful? Give feedback.
All reactions