Repository: facebook/react
Pull request: Fix prepare-prerelease script

## Summary

Batch of fixes to allow publishing `eslint-plugin-react-hooks`. Each commit fixes a different bug. 

## How did you test this change?

```bash
$ scripts/release/prepare-release-from-npm.js --version=5.1.0-rc-ed966dac-20241007 --skipTests --skipPackages react react-dom react-server-dom-webpack react-server-dom-turbopack react-is react-reconciler react-refresh react-test-renderer use-subscription use-sync-external-store scheduler jest-react react-art

✓ Checking out "next" from NPM 5.1.0-rc-ed966dac-20241007 582 ms
✓ Guessing stable version numbers 381 ms
✓ Version for eslint-plugin-react-hooks (default 4.6.3): 5.0.0

A stable release candidate has been prepared!

You can review the contents of this release in build/node_modules/

Before publishing, consider testing this release locally with create-react-app!

You can publish this release by running:
  scripts/release/publish.js
```

Changed files:
filename: scripts/release/prepare-release-from-npm-commands/confirm-stable-version-numbers.js
patch: @@ -30,9 +30,7 @@ const run = async ({skipPackages}, versionsMap) => {
 
     let version = bestGuessVersion;
     if (
-      skipPackages.some(skipPackageName =>
-        packageNames.includes(skipPackageName)
-      )
+      skipPackages.some(skipPackageName => packages.includes(skipPackageName))
     ) {
       await confirm(
         theme`{spinnerSuccess ✓} Version for ${packageNames} will remain {version ${bestGuessVersion}}`

filename: scripts/release/prepare-release-from-npm-commands/update-stable-version-numbers.js
patch: @@ -111,62 +111,68 @@ const run = async ({cwd, packages, version}, versionsMap) => {
 
   clear();
 
-  // A separate "React version" is used for the embedded renderer version to support DevTools,
-  // since it needs to distinguish between different version ranges of React.
-  // We need to replace it as well as the "next" version number.
-  const buildInfoPath = join(nodeModulesPath, 'react', 'build-info.json');
-  const {reactVersion} = await readJson(buildInfoPath);
-
-  if (!reactVersion) {
-    console.error(
-      theme`{error Unsupported or invalid build metadata in} {path build/node_modules/react/build-info.json}` +
-        theme`{error . This could indicate that you have specified an outdated "next" version.}`
-    );
-    process.exit(1);
-  }
-
-  // We print the diff to the console for review,
-  // but it can be large so let's also write it to disk.
-  const diffPath = join(cwd, 'build', 'temp.diff');
-  let diff = '';
-  let numFilesModified = 0;
-
-  // Find-and-replace hardcoded version (in built JS) for renderers.
-  for (let i = 0; i < packages.length; i++) {
-    const packageName = packages[i];
-    const packagePath = join(nodeModulesPath, packageName);
+  if (packages.includes('react')) {
+    // A separate "React version" is used for the embedded renderer version to support DevTools,
+    // since it needs to distinguish between different version ranges of React.
+    // We need to replace it as well as the "next" version number.
+    const buildInfoPath = join(nodeModulesPath, 'react', 'build-info.json');
+    const {reactVersion} = await readJson(buildInfoPath);
+
+    if (!reactVersion) {
+      console.error(
+        theme`{error Unsupported or invalid build metadata in} {path build/node_modules/react/build-info.json}` +
+          theme`{error . This could indicate that you have specified an outdated "next" version.}`
+      );
+      process.exit(1);
+    }
 
-    let files = await execRead(
-      `find ${packagePath} -name '*.js' -exec echo {} \\;`,
-      {cwd}
+    // We print the diff to the console for review,
+    // but it can be large so let's also write it to disk.
+    const diffPath = join(cwd, 'build', 'temp.diff');
+    let diff = '';
+    let numFilesModified = 0;
+
+    // Find-and-replace hardcoded version (in built JS) for renderers.
+    for (let i = 0; i < packages.length; i++) {
+      const packageName = packages[i];
+      const packagePath = join(nodeModulesPath, packageName);
+
+      let files = await execRead(
+        `find ${packagePath} -name '*.js' -exec echo {} \\;`,
+        {cwd}
+      );
+      files = files.split('\n');
+      files.forEach(path => {
+        const newStableVersion = versionsMap.get(packageName);
+        const beforeContents = readFileSync(path, 'utf8', {cwd});
+        let afterContents = beforeContents;
+        // Replace all "next" version numbers (e.g. header @license).
+        while (afterContents.indexOf(version) >= 0) {
+          afterContents = afterContents.replace(version, newStableVersion);
+        }
+        // Replace inline renderer version numbers (e.g. shared/ReactVersion).
+        while (afterContents.indexOf(reactVersion) >= 0) {
+          afterContents = afterContents.replace(reactVersion, newStableVersion);
+        }
+        if (beforeContents !== afterContents) {
+          numFilesModified++;
+          // Using a relative path for diff helps with the snapshot test
+          diff += printDiff(relative(cwd, path), beforeContents, afterContents);
+          writeFileSync(path, afterContents, {cwd});
+        }
+      });
+    }
+    writeFileSync(diffPath, diff, {cwd});
+    console.log(theme.header(`\n${numFilesModified} files have been updated.`));
+    console.log(
+      theme`A full diff is available at {path ${relative(cwd, diffPath)}}.`
+    );
+    await confirm('Do the changes above look correct?');
+  } else {
+    console.log(
+      theme`Skipping React renderer version update because React is not included in the release.`
     );
-    files = files.split('\n');
-    files.forEach(path => {
-      const newStableVersion = versionsMap.get(packageName);
-      const beforeContents = readFileSync(path, 'utf8', {cwd});
-      let afterContents = beforeContents;
-      // Replace all "next" version numbers (e.g. header @license).
-      while (afterContents.indexOf(version) >= 0) {
-        afterContents = afterContents.replace(version, newStableVersion);
-      }
-      // Replace inline renderer version numbers (e.g. shared/ReactVersion).
-      while (afterContents.indexOf(reactVersion) >= 0) {
-        afterContents = afterContents.replace(reactVersion, newStableVersion);
-      }
-      if (beforeContents !== afterContents) {
-        numFilesModified++;
-        // Using a relative path for diff helps with the snapshot test
-        diff += printDiff(relative(cwd, path), beforeContents, afterContents);
-        writeFileSync(path, afterContents, {cwd});
-      }
-    });
   }
-  writeFileSync(diffPath, diff, {cwd});
-  console.log(theme.header(`\n${numFilesModified} files have been updated.`));
-  console.log(
-    theme`A full diff is available at {path ${relative(cwd, diffPath)}}.`
-  );
-  await confirm('Do the changes above look correct?');
 
   clear();
 };

filename: scripts/release/prepare-release-from-npm.js
patch: @@ -27,6 +27,9 @@ const run = async () => {
     }
 
     params.packages = await getPublicPackages(isExperimental);
+    params.packages = params.packages.filter(packageName => {
+      return !params.skipPackages.includes(packageName);
+    });
 
     // Map of package name to upcoming stable version.
     // This Map is initially populated with guesses based on local versions.