Skip to content

Commit

Permalink
Improve flexibility for multiple versions of react-native-macos
Browse files Browse the repository at this point in the history
Summary:
The initial approach to resolving react-native-macos core JS modules from either `//xplat/js/react-native-github` or `//third-party/microsoft-fork-of-react-native` left the monorepo in a state where any JS folder that supported `macos` was limited to APIs available in React Native v0.71.

This is not sufficient, as apps that upgrade to the latest version of react-native-macos also likely want to start using the latest React and React Native features.

To circumvent this limitation, we're minting a new platform moniker, `macos_legacy`. In general though, this platform moniker should not be used as a JS platform override extension (with a minor exception described below). Instead, this `macos_legacy` extension uses Metro `sourceExts` configuration to allow resolution of `*.macos.js` files.

The exception to this rule is for haste resolved modules. Metro today does not have sufficient affordance to override the configured platform moniker from a context resolver override. Rather than add such capabilities to Metro for what we expect to be a short-lived feature in our configuration of fb-metro, we add `*.macos_legacy.js` platform overrides for a handful of haste-resolved modules. Specifically:
- xplat:DEPRECATED_FBTouchableHighlight
- xplat:GreenhouseAsyncStorage
- xplat:Shimmer
- xplat:WebView
- xplat:ReactNativePrivateAPI
- socialvr:L10nAPI

The remaining changes do the following:
1. Set up a BUCK config setting for apps that use `-c user.rn_macos`
2. Wires up the config setting in buck2 js_library platform moniker resolution to match to `macos_legacy`
3. Adds the new (temporary) platform moniker to fb-config/haste-impl and exclude from flow checks (similar to existing flow check suppression for *.macos.js).
4. Partially back out the previous hacks used to allow multi-version targeting of react-native-macos (D67049837 and D67161193).
5. Add logic to fb-config/metro to inject *.macos sourceExts when `macos_legacy` is used
6. Adds `macos_legacy` to fb-config/dependency-analysis to any `PlatformsByPrefix` entry that previously allowed `macos`.
7. Disables `inlinePlatform` transform option when target platform is `macos_legacy`, or, in the case of metro BUCK, when `-c user.rn_macos` config setting is matched.
8. Fixes the metro-buck-transform-worker to accommodate mismatched platform and file monikers.
9. Makes the default platform moniker for //third-party/microsoft-fork-of-react-native `macos_legacy` in dev builds.
10. Updates various generated config files from `js1 build buckfiles`.

Reviewed By: sbuggay

Differential Revision: D68246115

fbshipit-source-id: 6cfe329114c4c401ac85cbaaf30eea4401f59ade
  • Loading branch information
rozele authored and facebook-github-bot committed Jan 23, 2025
1 parent 1907e5a commit a450ec4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions prelude/js/js.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def _select_platform():
"config//os/constraints:macos": "macos",
"config//os/constraints:windows": "windows",
}),
# TODO(T210407097): Remove after deleting //third-party/microsoft-fork-of-react-native
"fbsource//tools/build_defs/js/config:macos_legacy": "macos_legacy",
"fbsource//tools/build_defs/js/config:platform_override_android": "android",
"fbsource//tools/build_defs/js/config:platform_override_ios": "ios",
"fbsource//tools/build_defs/js/config:platform_override_macos": "macos",
Expand Down
6 changes: 3 additions & 3 deletions prelude/js/js_utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ ASSET_EXTENSIONS = [
]

# Matches the default value for resolver.platforms in metro-config
ASSET_PLATFORMS = ["ios", "android", "windows", "macos", "web"]
ASSET_PLATFORMS = ["ios", "android", "windows", "macos", "macos_legacy", "web"]

def get_apple_resource_providers_for_js_bundle(ctx: AnalysisContext, js_bundle_info: JsBundleInfo, platform: str, skip_resources: bool) -> list[ResourceGraphInfo]:
if platform != "ios" and platform != "macos":
if platform != "ios" and platform != "macos" and platform != "macos_legacy":
return []

# `skip_resources` controls whether the JS resources should be skipped, not whether
Expand Down Expand Up @@ -126,7 +126,7 @@ def get_bundle_name(ctx: AnalysisContext, default_bundle_name: str) -> str:
flavors = bundle_name_for_flavor_map.keys()
for flavor in flavors:
expect(
flavor == "android" or flavor == "ios" or flavor == "macos" or flavor == "windows" or flavor == "vr",
flavor == "android" or flavor == "ios" or flavor == "macos" or flavor == "macos_legacy" or flavor == "windows" or flavor == "vr",
"Currently only support picking bundle name by platform!",
)

Expand Down

0 comments on commit a450ec4

Please sign in to comment.