Repository: facebook/react
Pull request: [Release] Update build script to properly set React Native's renderers version

## Summary
The React Native's renderers files for OSS that are produced by CI in the `combined_artifacts` artifact used to have a wrong version. In fact, when syncing React into React Native for React 19.1, I had to manually adjust the renderer's versions and sign them again to make them work.

With this change, the build script will take care of updating the files properly. I also refactored the code a little to avoid some duplicated code.

## How did you test this change?
```
# move to this commit
yarn install
yarn build
open build/react-native/implementations/ReactFabric-dev.js
```
once the file is open, <kbd>cmd</kbd>+<kbd>F</kbd> for `version:` and observe that the versions are properly set.

| BEFORE | AFTER |
| --- | --- |
| <img width="474" height="105" alt="Screenshot 2025-07-23 at 15 55 00" src="https://github.com/user-attachments/assets/576c667d-266b-4922-a961-3a59fd40c3b8" /> | <img width="372" height="125" alt="Screenshot 2025-07-23 at 15 53 24" src="https://github.com/user-attachments/assets/ecde2c2d-31cd-4f72-82a3-1e1c3ca0c222" /> |



Changed files:
filename: scripts/rollup/build-all-release-channels.js
patch: @@ -221,8 +221,7 @@ function processStable(buildDir) {
       );
     }
 
-    const rnVersionString =
-      ReactVersion + '-native-fb-' + sha + '-' + dateString;
+    const rnVersionString = ReactVersion + '-native-fb-' + sha + '-' + dateString;
     if (fs.existsSync(buildDir + '/facebook-react-native')) {
       updatePlaceholderReactVersionInCompiledArtifacts(
         buildDir + '/facebook-react-native',
@@ -231,9 +230,16 @@ function processStable(buildDir) {
     }
 
     if (fs.existsSync(buildDir + '/react-native')) {
-      updatePlaceholderReactVersionInCompiledArtifactsFb(
+      updatePlaceholderReactVersionInCompiledArtifacts(
         buildDir + '/react-native',
-        rnVersionString
+        rnVersionString,
+        (filename) => filename.endsWith('.fb.js')
+      );
+
+      updatePlaceholderReactVersionInCompiledArtifacts(
+        buildDir + '/react-native',
+        ReactVersion,
+        (filename) => !filename.endsWith('.fb.js') && filename.endsWith('.js')
       );
     }
 
@@ -340,9 +346,16 @@ function processExperimental(buildDir, version) {
   }
 
   if (fs.existsSync(buildDir + '/react-native')) {
-    updatePlaceholderReactVersionInCompiledArtifactsFb(
+    updatePlaceholderReactVersionInCompiledArtifacts(
       buildDir + '/react-native',
-      rnVersionString
+      rnVersionString,
+      (filename) => filename.endsWith('.fb.js')
+    );
+
+    updatePlaceholderReactVersionInCompiledArtifacts(
+      buildDir + '/react-native',
+      ReactVersion,
+      (filename) => !filename.endsWith('.fb.js') && filename.endsWith('.js')
     );
   }
 
@@ -437,38 +450,15 @@ function updatePackageVersions(
 
 function updatePlaceholderReactVersionInCompiledArtifacts(
   artifactsDirectory,
-  newVersion
+  newVersion,
+  filteringClosure
 ) {
   // Update the version of React in the compiled artifacts by searching for
   // the placeholder string and replacing it with a new one.
-  const artifactFilenames = String(
-    spawnSync('grep', [
-      '-lr',
-      PLACEHOLDER_REACT_VERSION,
-      '--',
-      artifactsDirectory,
-    ]).stdout
-  )
-    .trim()
-    .split('\n')
-    .filter(filename => filename.endsWith('.js'));
-
-  for (const artifactFilename of artifactFilenames) {
-    const originalText = fs.readFileSync(artifactFilename, 'utf8');
-    const replacedText = originalText.replaceAll(
-      PLACEHOLDER_REACT_VERSION,
-      newVersion
-    );
-    fs.writeFileSync(artifactFilename, replacedText);
+  if (filteringClosure == null) {
+    filteringClosure = filename => filename.endsWith('.js')
   }
-}
 
-function updatePlaceholderReactVersionInCompiledArtifactsFb(
-  artifactsDirectory,
-  newVersion
-) {
-  // Update the version of React in the compiled artifacts by searching for
-  // the placeholder string and replacing it with a new one.
   const artifactFilenames = String(
     spawnSync('grep', [
       '-lr',
@@ -479,7 +469,7 @@ function updatePlaceholderReactVersionInCompiledArtifactsFb(
   )
     .trim()
     .split('\n')
-    .filter(filename => filename.endsWith('.fb.js'));
+    .filter(filteringClosure);
 
   for (const artifactFilename of artifactFilenames) {
     const originalText = fs.readFileSync(artifactFilename, 'utf8');
@@ -491,6 +481,7 @@ function updatePlaceholderReactVersionInCompiledArtifactsFb(
   }
 }
 
+
 /**
  * cross-platform alternative to `rsync -ar`
  * @param {string} source