Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metro-file-map: Extract mocks handling into nullable MockMap #1402

Closed
wants to merge 2 commits into from

Conversation

robhogan
Copy link
Contributor

@robhogan robhogan commented Dec 10, 2024

Summary

Extract almost all mock handling logic out of FileMap and into MockMap.

Mocks are obviously a Jest concept inherited from jest-haste-map, but we're keeping them around in metro-file-map for planned re-use of metro-file-map as a custom hasteMapModulePath in Jest, at least at Meta.

This is a step towards making MockMap into a plugin or subscriber to FileMap, so that we don't need to keep it in metro-file-map's codebase and can inject it where needed.

Changelog: Internal

(No Metro-user-facing change, metro-file-map's API is explicitly experimental)

Test plan

  • New unit tests
  • mocksPattern is always null in Metro, so the new code isn't reached right now, except by tests.
  • We'll exercise this code next half when we use it in a Jest context.

@facebook-github-bot facebook-github-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 Dec 10, 2024
@facebook-github-bot
Copy link
Contributor

@robhogan has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

robhogan and others added 2 commits December 11, 2024 05:20
Summary:

Reading symlink targets with `readLink` is currently delegated to `metro-file-map`'s worker abstraction. However, due to the way the abstraction is used for symlinks, we never actually use the worker processes/threads, and always process in band.

The key here is that `readLink` is always mutually exclusive with other worker tasks, like `computeSha1` and `computeDependencies` - as it must be, because those operations don't make sense for symlink files.

This lifts the call to `readLink` out of the abstraction and explicitly into the main process, simplifying the worker and improving readability.

Changelog: Internal

Differential Revision: D66899343
Summary:
Extract almost all mock handling logic out of `FileMap` and into `MockMap`.

Mocks are obviously a Jest concept inherited from `jest-haste-map`, but we're keeping them around in `metro-file-map` for planned re-use of `metro-file-map` as a custom `hasteMapModulePath` in Jest, at least at Meta.

This is a step towards making `MockMap` into a *plugin* or subscriber to `FileMap`, so that we don't need to keep it in `metro-file-map`'s codebase and can inject it where needed.

Changelog: Internal

(No Metro-user-facing change, `metro-file-map`'s API is [explicitly experimental](https://github.com/facebook/metro/tree/main/packages/metro-file-map#experimental-metro-file-map))


Test Plan:
- New unit tests
 - `mocksPattern` is always `null` in Metro, so the new code isn't reached right now, except by tests.
 - We'll exercise this code next half when we use it in a Jest context.

Differential Revision: D67056483

Pulled By: robhogan
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D67056483

@robhogan robhogan changed the title Feat/mock map 2 metro-file-map: Extract mocks handling into nullable MockMap Dec 11, 2024
@robhogan robhogan marked this pull request as ready for review December 11, 2024 13:22
@facebook-github-bot
Copy link
Contributor

@robhogan merged this pull request in eb20032.

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. fb-exported Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants