Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Normalize file paths for require context on Windows (#876)
Summary: On Windows, the `require.context` resolves modules to non-posix paths. This seems to diverge from the expected behavior compared to Webpack, where the modules are resolved as posix paths. Because of this, we are running into unfortunate issues like expo/router#13. When inspecting the [`contextModuleTemplates`](https://github.com/facebook/metro/blob/main/packages/metro/src/lib/contextModuleTemplates.js#L44-L46), using [this example repo](https://github.com/byCedric/expo-router-context-windows-issue), you can see this happening. ![image](https://user-images.githubusercontent.com/1203991/192898803-f5030e8f-b9b3-4b88-8f2d-636f713d7e89.png) This change normalizes the file path keys to be posix, matching the default Webpack behavior. It does not change the absolute file reference. (based on [this piece of code](https://github.com/facebook/metro/blob/main/packages/metro/src/Assets.js#L201-L204)) Pull Request resolved: #876 Test Plan: - Added a windows style test case, copied from [this test in `metro-file-map`](https://github.com/facebook/metro/blob/main/packages/metro-file-map/src/lib/__tests__/normalizePathSep-test.js#L21-L26) - Ran the tests on my local Windows machine ![image](https://user-images.githubusercontent.com/1203991/192899575-371aec94-032b-46c8-b884-cd1e1c44f1b1.png) - Patched the [test repo](https://github.com/byCedric/expo-router-context-windows-issue) with [this change](https://github.com/byCedric/expo-router-context-windows-issue/blob/main/patches/metro%2B0.72.3.patch) and validated the output on Windows ![image](https://user-images.githubusercontent.com/1203991/192900417-bd38c02c-d8c9-4598-8bc0-b39fbbdcb3c7.png) Reviewed By: huntie Differential Revision: D39923633 Pulled By: huntie fbshipit-source-id: c80eed410df0a4270e2d00d5b0ff0aca6e29ff0b
- Loading branch information
1 parent
3ab9c00
commit 4bace2a
Showing
3 changed files
with
53 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters