Repository: facebook/react
Pull request: [compiler] Various fixes for publishing script

Stack from [ghstack](https://github.com/ezyang/ghstack) (oldest at bottom):
* #29083
* __->__ #29082

----

- Specify a registry for npm publish because otherwise it tries to use
  the yarn registry
- `packages` option actually works

This _should_ work now (note last line of output), will test it once we
land this since i want to publish a new version of the eslint plugin
with some important fixes.

```
npm notice
npm notice 📦  eslint-plugin-react-compiler@0.0.0-experimental-53bb89e-20240515
npm notice === Tarball Contents ===
npm notice 827B  README.md
npm notice 2.1MB dist/index.js
npm notice 1.0kB package.json
npm notice === Tarball Details ===
npm notice name:          eslint-plugin-react-compiler
npm notice version:       0.0.0-experimental-53bb89e-20240515
npm notice filename:      eslint-plugin-react-compiler-0.0.0-experimental-53bb89e-20240515.tgz
npm notice package size:  300.9 kB
npm notice unpacked size: 2.1 MB
npm notice shasum:        cb99823f3a483c74f470085cac177bd020f7a85a
npm notice integrity:     sha512-L3HV9qja1dnCl[...]IaRSZJ3P/v6yQ==
npm notice total files:   3
npm notice
npm notice Publishing to http://registry.npmjs.org/ with tag latest and default access (dry-run)
```

Changed files:
filename: compiler/scripts/publish.js
patch: @@ -24,7 +24,7 @@ const spawnHelper = util.promisify(_spawn);
 function execHelper(command, options, streamStdout = false) {
   return new Promise((resolve, reject) => {
     const proc = cp.exec(command, options, (error, stdout) =>
-      error ? reject(error) : resolve(stdout.trim())
+      error ? reject(error) : resolve(stdout.trim()),
     );
     if (streamStdout) {
       proc.stdout.pipe(process.stdout);
@@ -38,7 +38,7 @@ function sleep(ms) {
 
 async function getDateStringForCommit(commit) {
   let dateString = await execHelper(
-    `git show -s --no-show-signature --format=%cd --date=format:%Y%m%d ${commit}`
+    `git show -s --no-show-signature --format=%cd --date=format:%Y%m%d ${commit}`,
   );
 
   // On CI environment, this string is wrapped with quotes '...'s
@@ -92,14 +92,18 @@ async function main() {
     .parseSync();
 
   const { packages, forReal, debug } = argv;
+  let pkgNames = packages;
+  if (Array.isArray(packages) === false) {
+    pkgNames = [packages];
+  }
   const spinner = ora(
     `Preparing to publish ${
       forReal === true ? "(for real)" : "(dry run)"
-    } [debug=${debug}]`
+    } [debug=${debug}]`,
   ).info();
 
   spinner.info("Building packages");
-  for (const pkgName of packages) {
+  for (const pkgName of pkgNames) {
     const command = `yarn workspace ${pkgName} run build`;
     spinner.start(`Running: ${command}\n`);
     try {
@@ -114,7 +118,7 @@ async function main() {
 
   if (forReal === false) {
     spinner.info("Dry run: Report tarball contents");
-    for (const pkgName of packages) {
+    for (const pkgName of pkgNames) {
       console.log(`\n========== ${pkgName} ==========\n`);
       spinner.start(`Running npm pack --dry-run\n`);
       try {
@@ -129,7 +133,7 @@ async function main() {
       spinner.stop(`Successfully packed ${pkgName} (dry run)`);
     }
     spinner.succeed(
-      "Please confirm contents of packages before publishing. You can run this command again with --for-real to publish to npm"
+      "Please confirm contents of packages before publishing. You can run this command again with --for-real to publish to npm",
     );
   }
 
@@ -138,11 +142,11 @@ async function main() {
       "git show -s --no-show-signature --format=%h",
       {
         cwd: path.resolve(__dirname, ".."),
-      }
+      },
     );
     const dateString = await getDateStringForCommit(commit);
 
-    for (const pkgName of packages) {
+    for (const pkgName of pkgNames) {
       const pkgDir = path.resolve(__dirname, `../packages/${pkgName}`);
       const { hash } = await hashElement(pkgDir, {
         encoding: "hex",
@@ -157,40 +161,43 @@ async function main() {
           `yarn version --new-version ${newVersion} --no-git-tag-version`,
           {
             cwd: pkgDir,
-          }
+          },
         );
         await execHelper(
           `git add package.json && git commit -m "Bump version to ${newVersion}"`,
           {
             cwd: pkgDir,
-          }
+          },
         );
       } catch (e) {
         spinner.fail(e.toString());
         throw e;
       }
       spinner.succeed(
-        `Bumped ${pkgName} to ${newVersion} and added a git commit`
+        `Bumped ${pkgName} to ${newVersion} and added a git commit`,
       );
     }
 
     if (debug === false) {
       spinner.info(
         `🚨🚨🚨 About to publish to npm in ${
           TIME_TO_RECONSIDER / 1000
-        } seconds. You still have time to kill this script!`
+        } seconds. You still have time to kill this script!`,
       );
       await sleep(TIME_TO_RECONSIDER);
     }
 
-    for (const pkgName of packages) {
+    for (const pkgName of pkgNames) {
       const pkgDir = path.resolve(__dirname, `../packages/${pkgName}`);
       console.log(`\n========== ${pkgName} ==========\n`);
       spinner.start(`Publishing ${pkgName} to npm\n`);
 
       const opts = debug === true ? ["publish", "--dry-run"] : ["publish"];
       try {
-        await execHelper(`npm ${opts.join(" ")}`, { cwd: pkgDir });
+        await spawnHelper("npm", [...opts, "--registry=http://registry.npmjs.org"], {
+          cwd: pkgDir,
+          stdio: "inherit",
+        });
         console.log("\n");
       } catch (e) {
         spinner.fail(e.toString());