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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move macOS JS module overrides to their own files #1961

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

rozele
Copy link

@rozele rozele commented Oct 21, 2023

Please select one of the following

  • I am removing an existing difference between facebook/react-native and microsoft/react-native-macos 馃憤
  • I am cherry-picking a change from Facebook's react-native into microsoft/react-native-macos 馃憤
  • I am making a fix / change for the macOS implementation of react-native
  • I am making a change required for Microsoft usage of react-native
  • I am making react-native-macos follow better standards for out-of-tree platforms

Summary:

It would be better for any eventual "monorepo" efforts for react-native desktop if react-native-macos did not directly modify JS files from react-native mobile. This change copies most JavaScript files that have been modified for react-native-macos to a new file with a *.macos.js platform extension. It also retains history following the approach described here. Basically:
Commit 1 (from main): Move files to preferred location
Commit 2 (from main): Move files to random location
Commit 3 (from Commit 1): Merge in Commit 2
Commit 4 (from Commit 3): Move files moved in Commit 2 back to original location

Files that I explicitly did not include in this PR were *.d.ts files (as these cannot be easily forked via platform extensions AFAIK), any native files in packages/react-native/Libraries, and any test files.

In order for history to be preserved, it is critical that the pull request is merged with "Rebase" (i.e., retain all commits).

Changelog:

[INTERNAL] [FIXED] - File rename trickery to duplicate file history and move forked macOS JS files to *.macos.js

Test Plan:

I made another commit and merged it into this commit, I confirmed that the merged commit only applies to the original upstream file (so merges from facebook/react-native should continue to work as before).

TODOs

  • Fix yarn flow-check
  • Setup react-native-platform-override
  • (Optional) Consider switching the default platform in flow.config.js to macOS (from iOS)

This is a sequence of changes to move macOS files to *.macos.js files, hopefully without losing history and to show that we're not making explicit changes to macOS files. It will use a diamond pattern, where any file that was forked for macOS will be moved from it's source file first and merged with a commit that moves a file back to it's original file location. Here are the steps:

1. Move all forked JS files to *.macos.js
2. Merge in a branch that moves the forked files to *.native.js files and then back to their original file
We cannot convince git history to treat an overwrite of Image.macos.js with Image.ios.js unless the file is deleted first.
In order to preserve history of Image.ios.js, we move the file to Image.macos.js, rather than just overwriting it in the first place.
We can retain the same history for both the original and the copied file if we copy it twice and merge the commits. This copies the files to a different location to copy them back.
@rozele rozele requested a review from a team as a code owner October 21, 2023 17:12
@rozele
Copy link
Author

rozele commented Oct 21, 2023

Before merging this PR, we should probably resolve the following:

  1. Since merges from facebook/react-native now only impact the *.js file (not the *.macos.js file), we likely need to set up react-native-platform-override.
  2. We should revert the state of the *.js files to their unmodified form. This will ensure merge conflicts do not occur on these files and may make it possible to create a version of react-native-platform-override that does not require a temporary repo.

Since the iOS code no longer has macOS specific logic in it, this is the result of running `yarn test-ci -u`.

Additionally, because `@react-native/virtualized-lists` is not part of the react-native-macos monorepo, this change adds a line to jest.config.js to re-map imports to `@react-native-mac/virtualized-lists`.
@rozele rozele marked this pull request as draft October 31, 2023 01:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant