Skip to content

Add the metro-virtual: module path namespace - #2056

Draft
robhogan wants to merge 1 commit into
pr2041from
pr2056
Draft

robhogan wants to merge 1 commit into
pr2041from
pr2056

Conversation

@robhogan

Copy link
Copy Markdown
Collaborator

Modules with no file on disk need a graph path that can't be mistaken for a real one. This reserves metro-virtual:<absolute path> for them (#2036 lets resolvers produce such modules), and updates the places where a module path leaves Metro to handle it.

A module path becomes user-visible in development module names, HMR source URLs, server-URL source paths and async bundle paths. Each derives a name from the path with path functions, which give machine-dependent results for a path that isn't absolute. They now go through one set of helpers in lib/virtualModule: dev names use metro-virtual:<relative path>, and URLs get a leading [metro-virtual] segment, following [metro-watchFolders]. getAllFiles leaves virtual modules out, since they have no file.

Nothing produces a metro-virtual: path until #2036, so existing bundles are unchanged.

Changelog: Internal

Test plan: New unit tests for the helpers, plus HMR, dev name, async path and getAllFiles cases for a virtual module. In particular, a virtual module at the same path as a real file gets distinct HMR URLs.

Modules with no file on disk need a graph path that can't be mistaken for a real one. This reserves `metro-virtual:<absolute path>` for them (#2036 lets resolvers produce such modules), and updates the places where a module path leaves Metro to handle it.

A module path becomes user-visible in development module names, HMR source URLs, server-URL source paths and async bundle paths. Each derives a name from the path with `path` functions, which give machine-dependent results for a path that isn't absolute. They now go through one set of helpers in `lib/virtualModule`: dev names use `metro-virtual:<relative path>`, and URLs get a leading `[metro-virtual]` segment, following `[metro-watchFolders]`. `getAllFiles` leaves virtual modules out, since they have no file.

Nothing produces a `metro-virtual:` path until #2036, so existing bundles are unchanged.

Changelog: Internal

Test plan: New unit tests for the helpers, plus HMR, dev name, async path and `getAllFiles` cases for a virtual module. In particular, a virtual module at the same path as a real file gets distinct HMR URLs.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 11, 2026
@robhogan
robhogan marked this pull request as draft October 11, 2026 14:41
@robhogan
robhogan added this pull request to stack #2057 October 11, 2026 14:41

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant