Home / File/ publish-to-npm.js — react Source File

publish-to-npm.js — react Source File

Architecture documentation for publish-to-npm.js, a javascript file in the react codebase.

Entity Profile

Relationship Graph

Source Code

#!/usr/bin/env node

'use strict';

const {spawnSync} = require('child_process');
const {exec} = require('child-process-promise');
const {readJsonSync} = require('fs-extra');
const {join} = require('path');
const {confirm} = require('../utils');
const theme = require('../theme');

const run = async ({cwd, dry, tags, ci}, packageName, otp) => {
  const packagePath = join(cwd, 'build/node_modules', packageName);
  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 {status} = spawnSync('npm', ['view', `${packageName}@${version}`]);
  const packageExists = status === 0;
  if (packageExists) {
    console.log(
      theme`{package ${packageName}} {version ${version}} has already been published.`
    );
    if (!ci) {
      await confirm('Is this expected?');
    }
  } else {
    console.log(
      theme`{spinnerSuccess ✓} Publishing {package ${packageName}}${dry ? ' (dry-run)' : ''}`
    );

    // Publish the package and tag it.
    if (!dry) {
      if (!ci) {
        await exec(`npm publish --tag=${tags[0]} --otp=${otp}`, {
          cwd: packagePath,
        });
        console.log(theme.command(`  cd ${packagePath}`));
        console.log(
          theme.command(`  npm publish --tag=${tags[0]} --otp=${otp}`)
        );
      } else {
        await exec(`npm publish --tag=${tags[0]}`, {
          cwd: packagePath,
        });
        console.log(theme.command(`  cd ${packagePath}`));
        console.log(theme.command(`  npm publish --tag=${tags[0]}`));
      }
    }

    for (let j = 1; j < tags.length; j++) {
      if (!dry) {
        if (!ci) {
          await exec(
            `npm dist-tag add ${packageName}@${version} ${tags[j]} --otp=${otp}`,
            {cwd: packagePath}
          );
          console.log(
            theme.command(
              `  npm dist-tag add ${packageName}@${version} ${tags[j]} --otp=${otp}`
            )
          );
        } else {
          await exec(`npm dist-tag add ${packageName}@${version} ${tags[j]}`, {
            cwd: packagePath,
          });
          console.log(
            theme.command(
              `  npm dist-tag add ${packageName}@${version} ${tags[j]}`
            )
          );
        }
      }
    }

    if (tags.includes('untagged')) {
      // npm doesn't let us publish without a tag at all,
      // so for one-off publishes we clean it up ourselves.
      if (!dry) {
        if (!ci) {
          await exec(`npm dist-tag rm ${packageName} untagged --otp=${otp}`);
          console.log(
            theme.command(
              `  npm dist-tag rm ${packageName} untagged --otp=${otp}`
            )
          );
        } else {
          await exec(`npm dist-tag rm ${packageName} untagged`);
          console.log(
            theme.command(`  npm dist-tag rm ${packageName} untagged`)
          );
        }
      }
    }
  }
};

module.exports = run;

Domain

Subdomains

Functions

Frequently Asked Questions

What does publish-to-npm.js do?
publish-to-npm.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain, Entrypoint subdomain.
What functions are defined in publish-to-npm.js?
publish-to-npm.js defines 1 function(s): run.
Where is publish-to-npm.js in the architecture?
publish-to-npm.js is located at scripts/release/publish-commands/publish-to-npm.js (domain: BabelCompiler, subdomain: Entrypoint, directory: scripts/release/publish-commands).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free