Repository: facebook/react
File: scripts/devtools/publish-release.js (JavaScript)

Code before:
  const {otp} = await inquirer.prompt([
    {
      type: 'input',
      name: 'otp',
      message: 'Please provide an NPM two-factor auth token:',
    },
  ]);

  console.log('');

  if (!otp) {
    console.error(chalk.red(`Invalid OTP provided: "${chalk.bold(otp)}"`));
    process.exit(0);
  }

  for (let index = 0; index < NPM_PACKAGES.length; index++) {
    const npmPackage = NPM_PACKAGES[index];
    const packagePath = join(ROOT_PATH, 'packages', npmPackage);
    const {version} = readJsonSync(join(packagePath, 'package.json'));

    // Check if this package version has already been published.
    // If so we might be resuming from a previous run.
    // We could infer this by comparing the build-info.json,
    // But for now the easiest way is just to ask if this is expected.
    const info = await execRead(`npm view ${npmPackage}@${version}`)
      // Early versions of npm view gives empty response, but older versions give 404 error.
      // Catch the error to keep it consistent.
      .catch(childProcessError => {
        if (childProcessError.stderr.startsWith('npm ERR! code E404')) {
          return null;
        }

        throw childProcessError;
      });

    if (info) {
      console.log('');
      console.log(
        `${npmPackage} version ${chalk.bold(
          version
        )} has already been published.`
      );

      await confirm(`Is this expected (will skip ${npmPackage}@${version})?`);
      continue;
    }

    if (DRY_RUN) {
      console.log(`Publishing package ${chalk.bold(npmPackage)}`);
      console.log(chalk.dim(`  npm publish --otp=${otp}`));
    } else {

Review comment (suggestion):
nit: I think this was my mistake 😅 it should be "newer versions" right?
```suggestion
      // Early versions of npm view gives empty response, but newer versions give 404 error.
```

Code after:
  const {otp} = await inquirer.prompt([
    {
      type: 'input',
      name: 'otp',
      message: 'Please provide an NPM two-factor auth token:',
    },
  ]);

  console.log('');

  if (!otp) {
    console.error(chalk.red(`Invalid OTP provided: "${chalk.bold(otp)}"`));
    process.exit(0);
  }

  for (let index = 0; index < NPM_PACKAGES.length; index++) {
    const npmPackage = NPM_PACKAGES[index];
    const packagePath = join(ROOT_PATH, 'packages', npmPackage);
    const {version} = readJsonSync(join(packagePath, 'package.json'));

    // Check if this package version has already been published.
    // If so we might be resuming from a previous run.
    // We could infer this by comparing the build-info.json,
    // But for now the easiest way is just to ask if this is expected.
    const info = await execRead(`npm view ${npmPackage}@${version}`)
      // Early versions of npm view gives empty response, but newer versions give 404 error.
      // Catch the error to keep it consistent.
      .catch(childProcessError => {
        if (childProcessError.stderr.startsWith('npm ERR! code E404')) {
          return null;
        }

        throw childProcessError;
      });

    if (info) {
      console.log('');
      console.log(
        `${npmPackage} version ${chalk.bold(
          version
        )} has already been published.`
      );

      await confirm(`Is this expected (will skip ${npmPackage}@${version})?`);
      continue;
    }

    if (DRY_RUN) {
      console.log(`Publishing package ${chalk.bold(npmPackage)}`);
      console.log(chalk.dim(`  npm publish --otp=${otp}`));
    } else {