-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
remove.ts
68 lines (53 loc) Β· 2.47 KB
/
remove.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import {BaseCommand, WorkspaceRequiredError} from '@yarnpkg/cli';
import {Configuration, Project, structUtils, MessageName, StreamReport, formatUtils} from '@yarnpkg/core';
import {npmHttpUtils, npmConfigUtils} from '@yarnpkg/plugin-npm';
import {Command, Option, Usage, UsageError} from 'clipanion';
import {getDistTags} from './list';
// eslint-disable-next-line arca/no-default-export
export default class NpmTagRemoveCommand extends BaseCommand {
static paths = [
[`npm`, `tag`, `remove`],
];
static usage: Usage = Command.Usage({
category: `Npm-related commands`,
description: `remove a tag from a package`,
details: `
This command will remove a tag from a package from the npm registry.
`,
examples: [[
`Remove the \`beta\` tag from package \`my-pkg\``,
`yarn npm tag remove my-pkg beta`,
]],
});
package = Option.String();
tag = Option.String();
async execute() {
if (this.tag === `latest`)
throw new UsageError(`The 'latest' tag cannot be removed.`);
const configuration = await Configuration.find(this.context.cwd, this.context.plugins);
const {project, workspace} = await Project.find(configuration, this.context.cwd);
if (!workspace)
throw new WorkspaceRequiredError(project.cwd, this.context.cwd);
const ident = structUtils.parseIdent(this.package);
const registry = npmConfigUtils.getPublishRegistry(workspace.manifest, {configuration});
const prettyTag = formatUtils.pretty(configuration, this.tag, formatUtils.Type.CODE);
const prettyIdent = formatUtils.pretty(configuration, ident, formatUtils.Type.IDENT);
const distTags = await getDistTags(ident, configuration);
if (!Object.hasOwn(distTags, this.tag))
throw new UsageError(`${prettyTag} is not a tag of package ${prettyIdent}`);
const report = await StreamReport.start({
configuration,
stdout: this.context.stdout,
}, async report => {
const url = `/-/package${npmHttpUtils.getIdentUrl(ident)}/dist-tags/${encodeURIComponent(this.tag)}`;
await npmHttpUtils.del(url, {
configuration,
registry,
ident,
jsonResponse: true,
});
report.reportInfo(MessageName.UNNAMED, `Tag ${prettyTag} removed from package ${prettyIdent}`);
});
return report.exitCode();
}
}