Skip to content

Commit ada3922

Browse files
Insik-Hanmeta-codesync[bot]
authored andcommitted
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: #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
1 parent 3d8e181 commit ada3922

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

packages/react-native/scripts/replace-rncore-version.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,18 @@ function replaceRNCoreConfiguration(
7373
const tmpExtractDir = path.join(tmpDir, 'React-Core-prebuilt');
7474
fs.mkdirSync(tmpExtractDir, {recursive: true});
7575

76+
// Preserve Expo-generated modulemap before replacing directories
77+
const useFrameworksModulemapName = 'React-use-frameworks.modulemap';
78+
const useFrameworksModulemapPath = path.join(
79+
finalLocation,
80+
useFrameworksModulemapName,
81+
);
82+
let savedModulemap = null;
83+
if (fs.existsSync(useFrameworksModulemapPath)) {
84+
console.log('Preserving', useFrameworksModulemapName);
85+
savedModulemap = fs.readFileSync(useFrameworksModulemapPath);
86+
}
87+
7688
try {
7789
console.log('Extracting the tarball to temp dir', tarballURLPath);
7890
const result = spawnSync(
@@ -135,6 +147,14 @@ function replaceRNCoreConfiguration(
135147
} finally {
136148
// Clean up temp directory
137149
fs.rmSync(tmpDir, {force: true, recursive: true});
150+
151+
// Restore Expo-generated modulemap after directory replacement.
152+
// Runs in finally so it is not skipped if mv/cp partially fails.
153+
if (savedModulemap != null) {
154+
const restoredPath = path.join(finalLocation, useFrameworksModulemapName);
155+
fs.writeFileSync(restoredPath, savedModulemap);
156+
console.log('Restored', useFrameworksModulemapName);
157+
}
138158
}
139159
}
140160

0 commit comments

Comments
 (0)