Skip to content

Extract ProjectRouteMap, refactor path<-->URL mappings in Server - #2015

Open
robhogan wants to merge 1 commit into
pr2013from
pr2014
Open

robhogan wants to merge 1 commit into
pr2013from
pr2014

Conversation

@robhogan

@robhogan robhogan commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

Recreating #1707 / D104223068 (@motiz88) for GH first without a diff attachment

Extracts a ProjectRouteMap class from Server, centralising the [metro-watchFolders] and [metro-project] virtual prefix resolution previously spread across _resolveWatchFolderPrefix, _sourceRequestRoutingMap, and _getModuleSourceUrl.

ProjectRouteMap provides:

  • filePathOfUrlDecodedPathname: resolves [metro-project]/... and [metro-watchFolders]/N/... prefixed pathnames to absolute file paths. Returns null for non-prefixed paths or invalid indices.
  • urlPathnameOfFilePath: maps an absolute file path to the corresponding prefixed URL pathname.

Server now delegates to ProjectRouteMap from _resolveRelativePath, _getEntryPointAbsolutePath, _getModuleSourceUrl, and source file serving.

No behavioural change is intended here, but this does incidentally fix a Windows bug that was affecting the original implementation.

Changelog:

  • [Fix]: Fix /[metro-project]/ and /[metro-watchFolders]/ bundle serving on Windows.

Test plan:
See D104223068

@robhogan
robhogan added this pull request to stack #2016 October 3, 2026 21:33
@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 3, 2026
@robhogan
robhogan marked this pull request as ready for review October 3, 2026 21:36
@robhogan
robhogan requested review from huntie and motiz88 and a balanced review from Copilot October 3, 2026 21:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

馃煝 Approval recommended

The refactor preserves existing routing semantics and includes focused unit and integration coverage for Windows behavior.

Review effort: Balanced
Findings: None

What changed in this PR

Centralizes Metro鈥檚 virtual project/watch-folder URL routing and fixes Windows bundle serving.

Changes:

  • Adds bidirectional path/URL mapping via ProjectRouteMap.
  • Refactors Server routing, asset handling, and source URLs.
  • Enables Windows integration coverage.
File Description
packages/鈥媘etro/鈥媠rc/鈥婼erver.js Delegates routing to ProjectRouteMap.
packages/鈥媘etro/鈥媠rc/鈥婼erver/鈥媉_tests__/鈥婼erver-test.js Updates asset and round-trip assertions.
packages/鈥媘etro/鈥媠rc/鈥媗ib/鈥婸rojectRouteMap.js Implements virtual-prefix mappings.
packages/鈥媘etro/鈥媠rc/鈥媗ib/鈥媉_tests__/鈥婸rojectRouteMap-test.js Tests route-map behavior.
packages/鈥媘etro/鈥媠rc/鈥媔ntegration_tests/鈥媉_tests__/鈥媠erver-test.js Enables cross-platform prefixed-route tests.

馃挕 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

*Recreating #1707 / [D104223068](https://www.internalfb.com/diff/D104223068) (@motiz88) for GH first without a diff attachment*

Extracts a `ProjectRouteMap` class from `Server`, centralising the `[metro-watchFolders]` and `[metro-project]` virtual prefix resolution previously spread across `_resolveWatchFolderPrefix`, `_sourceRequestRoutingMap`, and `_getModuleSourceUrl`.

`ProjectRouteMap` provides:
- `filePathOfUrlDecodedPathname`: resolves `[metro-project]/...` and `[metro-watchFolders]/N/...` prefixed pathnames to absolute file paths. Returns null for non-prefixed paths or invalid indices.
- `urlPathnameOfFilePath`: maps an absolute file path to the corresponding prefixed URL pathname.

Server now delegates to `ProjectRouteMap` from `_resolveRelativePath`, `_getEntryPointAbsolutePath`, `_getModuleSourceUrl`, and source file serving.

No behavioural change is intended here, but this does incidentally fix a Windows bug that was affecting the original implementation.

Changelog:

* **[Fix]:** Fix `/[metro-project]/` and `/[metro-watchFolders]/` bundle serving on Windows.

Test plan:
See [D104223068](https://www.internalfb.com/diff/D104223068)

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.

3 participants