async function handler()

in ng-dev/release/set-dist-tag/cli.ts [48:96]


async function handler(args: Arguments<ReleaseSetDistTagOptions>) {
  const {targetVersion: rawVersion, tagName, skipExperimentalPackages} = args;
  const config = getConfig();
  assertValidReleaseConfig(config);
  const {npmPackages, publishRegistry} = config.release;
  const version = semver.parse(rawVersion);

  if (version === null) {
    error(red(`Invalid version specified (${rawVersion}). Unable to set NPM dist tag.`));
    process.exit(1);
  } else if (isExperimentalSemver(version)) {
    error(
      red(
        `Unexpected experimental SemVer version specified. This command expects a ` +
          `non-experimental project SemVer version.`,
      ),
    );
    process.exit(1);
  }

  debug(`Setting "${tagName}" NPM dist tag for release packages to v${version}.`);
  const spinner = new Spinner('');

  for (const pkg of npmPackages) {
    // If `--skip-experimental-packages` is specified, all NPM packages which
    // are marked as experimental will not receive the NPM dist tag update.
    if (pkg.experimental && skipExperimentalPackages) {
      spinner.update(`Skipping "${pkg.name}" due to it being experimental.`);
      continue;
    }

    spinner.update(`Setting NPM dist tag for "${pkg.name}"`);
    const distTagVersion = pkg.experimental ? createExperimentalSemver(version!) : version!;

    try {
      await setNpmTagForPackage(pkg.name, tagName, distTagVersion, publishRegistry);
      debug(`Successfully set "${tagName}" NPM dist tag for "${pkg.name}".`);
    } catch (e) {
      spinner.complete();
      error(e);
      error(red(`  ✘   An error occurred while setting the NPM dist tag for "${pkg.name}".`));
      process.exit(1);
    }
  }

  spinner.complete();
  info(green(`  ✓   Set NPM dist tag for all release packages.`));
  info(green(`      ${bold(tagName)} will now point to ${bold(`v${version}`)}.`));
}