Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions packages/react-native/scripts/replace-rncore-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ function replaceRNCoreConfiguration(
);
}

// 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);
}

// Delete all directories in finalLocation - not files, since we want to
// keep the React-VFS.yaml file
const dirs = fs
Expand Down Expand Up @@ -132,9 +144,21 @@ 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);
}
}
}

Expand Down