Skip to content

Commit

Permalink
refactor(ng-dev): update legacy set-dist-tag release command to re-…
Browse files Browse the repository at this point in the history
…use new command

The legacy `set-dist-tag` command is kept for backwards compat and
should just re-use the new `npm-dist-tag set` command.
  • Loading branch information
devversion committed Jan 9, 2023
1 parent 9cf7591 commit 5901019
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 288 deletions.
38 changes: 3 additions & 35 deletions ng-dev/release/set-dist-tag/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,42 +1,10 @@
load("//tools:defaults.bzl", "jasmine_node_test", "ts_library")
load("//tools:defaults.bzl", "ts_library")

ts_library(
name = "set-dist-tag",
srcs = glob(
[
"**/*.ts",
],
exclude = ["*.spec.ts"],
),
srcs = glob(["**/*.ts"]),
visibility = ["//ng-dev:__subpackages__"],
deps = [
"//ng-dev/release/config",
"//ng-dev/release/versioning",
"//ng-dev/utils",
"@npm//@types/node",
"@npm//@types/semver",
"@npm//@types/yargs",
"@npm//semver",
"//ng-dev/release/npm-dist-tag/set",
],
)

ts_library(
name = "test_lib",
srcs = glob([
"*.spec.ts",
]),
deps = [
":set-dist-tag",
"//ng-dev/release/config",
"//ng-dev/release/versioning",
"//ng-dev/utils",
"//ng-dev/utils/testing",
"@npm//@types/jasmine",
"@npm//@types/node",
],
)

jasmine_node_test(
name = "test",
specs = [":test_lib"],
)
3 changes: 3 additions & 0 deletions ng-dev/release/set-dist-tag/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This alias exists for backwards compatibility. Once the new `npm-dist-tag <set/|delete>`
commands are available in most versions, this can be deleted and the publish tool external
commands can be switched over.
100 changes: 7 additions & 93 deletions ng-dev/release/set-dist-tag/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,106 +6,20 @@
* found in the LICENSE file at https://angular.io/license
*/

import {ReleaseNpmDistTagSetCommand} from '../npm-dist-tag/set/cli.js';

// ---- **IMPORTANT** ----
// This command is part of our external commands invoked by the release publish
// command. Before making changes, keep in mind that more recent `ng-dev` versions
// can still invoke this command.
// ------------------------

import semver from 'semver';
import {Argv, Arguments, CommandModule} from 'yargs';
import {getConfig} from '../../utils/config.js';

import {Log, bold, green} from '../../utils/logging.js';
import {Spinner} from '../../utils/spinner.js';
import {assertValidReleaseConfig} from '../config/index.js';
import {NpmCommand} from '../versioning/npm-command.js';
import {
createExperimentalSemver,
isExperimentalSemver,
} from '../versioning/experimental-versions.js';

/** Command line options for setting an NPM dist tag. */
export interface ReleaseSetDistTagOptions {
tagName: string;
targetVersion: string;
skipExperimentalPackages: boolean;
}

function builder(args: Argv): Argv<ReleaseSetDistTagOptions> {
return args
.positional('tagName', {
type: 'string',
demandOption: true,
description: 'Name of the NPM dist tag.',
})
.positional('targetVersion', {
type: 'string',
demandOption: true,
description:
'Version to which the NPM dist tag should be set.\nThis version will be ' +
'converted to an experimental version for experimental packages.',
})
.option('skipExperimentalPackages', {
type: 'boolean',
description: 'Whether the dist tag should not be set for experimental NPM packages.',
default: false,
});
}

/** Yargs command handler for setting an NPM dist tag. */
async function handler(args: Arguments<ReleaseSetDistTagOptions>) {
const {targetVersion: rawVersion, tagName, skipExperimentalPackages} = args;
const config = await getConfig();
assertValidReleaseConfig(config);
const {npmPackages, publishRegistry} = config.release;
const version = semver.parse(rawVersion);

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

Log.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 NpmCommand.setDistTagForPackage(pkg.name, tagName, distTagVersion, publishRegistry);
Log.debug(`Successfully set "${tagName}" NPM dist tag for "${pkg.name}".`);
} catch (e) {
spinner.complete();
Log.error(e);
Log.error(` ✘ An error occurred while setting the NPM dist tag for "${pkg.name}".`);
process.exit(1);
}
}

spinner.complete();
Log.info(green(` ✓ Set NPM dist tag for all release packages.`));
Log.info(green(` ${bold(tagName)} will now point to ${bold(`v${version}`)}.`));
}
// TODO(devversion): Remove this command in 2024 Jan. It only exists for backwards compat.
// If all active and LTS release trains support the new `release npm-dist-tag`
// command, this can be removed.

/** CLI command module for setting an NPM dist tag. */
export const ReleaseSetDistTagCommand: CommandModule<{}, ReleaseSetDistTagOptions> = {
builder,
handler,
export const ReleaseSetDistTagCommand: typeof ReleaseNpmDistTagSetCommand = {
...ReleaseNpmDistTagSetCommand,
command: 'set-dist-tag <tag-name> <target-version>',
describe: 'Sets a given NPM dist tag for all release packages.',
};
160 changes: 0 additions & 160 deletions ng-dev/release/set-dist-tag/set-dist-tag.spec.ts

This file was deleted.

0 comments on commit 5901019

Please sign in to comment.