Preserve Expo-generated modulemap in replace-rncore-version.js (#56335)

Summary:
When using Expo with `use_frameworks!` in the Podfile, Expo generates a `React-use-frameworks.modulemap` file inside `React-Core-prebuilt`. When `replaceRNCoreConfiguration` runs (e.g., when switching between Debug and Release builds), this file can be lost, causing subsequent builds to fail with modulemap-related errors.

The current code removes only directories inside `React-Core-prebuilt` (preserving top-level files), but `React-use-frameworks.modulemap` may reside inside one of those subdirectories depending on the Expo version. This PR explicitly saves and restores the modulemap around the directory replacement to make the intent clear and guard against this case.

The restore is placed inside the `finally` block so it runs even if `mv`/`cp` partially fails during the directory move.

## Changelog:

[IOS] [Fixed] - Preserve Expo-generated `React-use-frameworks.modulemap` across `replace-rncore-version.js` runs

Pull Request resolved: https://github.com/facebook/react-native/pull/56335

Test Plan:
- Set up an Expo project with `use_frameworks!` in Podfile
- Run `pod install` for a Debug build
- Switch to a Release build to trigger `replace-rncore-version.js`
- Verify `React-use-frameworks.modulemap` is present in `React-Core-prebuilt/` after the replacement
- Confirm the build succeeds without modulemap-related errors

Reviewed By: cortinico

Differential Revision: D99816864

Pulled By: cipolleschi

fbshipit-source-id: d518420a45f5b178142fb5a118974d0d3e449676
This commit is contained in:
Insik-Han
2026-04-08 02:42:45 -07:00
committed by meta-codesync[bot]
parent 3d8e1814ec
commit ada39220a0
+20
View File
@@ -73,6 +73,18 @@ function replaceRNCoreConfiguration(
const tmpExtractDir = path.join(tmpDir, 'React-Core-prebuilt');
fs.mkdirSync(tmpExtractDir, {recursive: true});
// Preserve Expo-generated modulemap before replacing directories
const useFrameworksModulemapName = 'React-use-frameworks.modulemap';
const useFrameworksModulemapPath = path.join(
finalLocation,
useFrameworksModulemapName,
);
let savedModulemap = null;
if (fs.existsSync(useFrameworksModulemapPath)) {
console.log('Preserving', useFrameworksModulemapName);
savedModulemap = fs.readFileSync(useFrameworksModulemapPath);
}
try {
console.log('Extracting the tarball to temp dir', tarballURLPath);
const result = spawnSync(
@@ -135,6 +147,14 @@ function replaceRNCoreConfiguration(
} finally {
// Clean up temp directory
fs.rmSync(tmpDir, {force: true, recursive: true});
// Restore Expo-generated modulemap after directory replacement.
// Runs in finally so it is not skipped if mv/cp partially fails.
if (savedModulemap != null) {
const restoredPath = path.join(finalLocation, useFrameworksModulemapName);
fs.writeFileSync(restoredPath, savedModulemap);
console.log('Restored', useFrameworksModulemapName);
}
}
}