From fd7743eb44328abe965fefc28a3ea1b1aa01c051 Mon Sep 17 00:00:00 2001 From: eryue0220 Date: Mon, 2 Feb 2026 21:09:35 +0800 Subject: [PATCH] add deprecate command --- cli/src/npm-client.ts | 27 +++++++++++++++++++++++++++ cli/src/schemas.ts | 16 ++++++++++++++++ cli/src/server.ts | 9 +++++++++ cli/src/types.ts | 1 + 4 files changed, 53 insertions(+) diff --git a/cli/src/npm-client.ts b/cli/src/npm-client.ts index f21169eaf..8f668354d 100644 --- a/cli/src/npm-client.ts +++ b/cli/src/npm-client.ts @@ -424,3 +424,30 @@ export async function packageInit( }) } } + +/** + * Deprecate a package or a specific version with a custom message. + * @param pkg Package name (e.g. "vue" or "@nuxt/kit") + * @param reason Deprecation message shown to users + * @param version Optional version to deprecate (e.g. "1.0.0"); if omitted, deprecates the whole package + * @param options.dryRun If true, passes --dry-run to npm (report what would be done without making changes) + * @param options.registry Registry URL (e.g. "https://registry.npmjs.org"); if set, passes --registry + */ +export async function packageDeprecate( + pkg: string, + reason: string, + version?: string, + otp?: string, + options?: { dryRun?: boolean; registry?: string }, +): Promise { + validatePackageName(pkg) + const target = version ? `${pkg}@${version}` : pkg + const args = ['deprecate', target, reason] + if (options?.dryRun) { + args.push('--dry-run') + } + if (options?.registry?.trim()) { + args.push('--registry', options.registry.trim()) + } + return execNpm(args, { otp }) +} diff --git a/cli/src/schemas.ts b/cli/src/schemas.ts index eb3facba6..ff3289e4e 100644 --- a/cli/src/schemas.ts +++ b/cli/src/schemas.ts @@ -106,6 +106,7 @@ export const OperationTypeSchema = v.picklist([ 'owner:add', 'owner:rm', 'package:init', + 'package:deprecate', ]) /** @@ -231,6 +232,18 @@ export const PackageInitParamsSchema = v.object({ author: v.optional(UsernameSchema), }) +const PackageDeprecateParamsSchema = v.object({ + pkg: PackageNameSchema, + message: v.pipe( + v.string(), + v.nonEmpty('Deprecation message is required'), + v.maxLength(500, 'Message is too long'), + ), + version: v.optional(v.pipe(v.string(), v.nonEmpty())), + dryRun: v.optional(v.picklist(['true', 'false'], 'dryRun must be "true" or "false"')), + registry: v.optional(v.pipe(v.string(), v.minLength(1, 'Registry URL cannot be empty'))), +}) + // ============================================================================ // Helper Functions // ============================================================================ @@ -280,6 +293,9 @@ export function validateOperationParams( case 'package:init': v.parse(PackageInitParamsSchema, params) break + case 'package:deprecate': + v.parse(PackageDeprecateParamsSchema, params) + break } } diff --git a/cli/src/server.ts b/cli/src/server.ts index fc609e06f..9e4d7c620 100644 --- a/cli/src/server.ts +++ b/cli/src/server.ts @@ -23,6 +23,7 @@ import { ownerAdd, ownerRemove, packageInit, + packageDeprecate, listUserPackages, type NpmExecResult, } from './npm-client.ts' @@ -734,6 +735,14 @@ async function executeOperation(op: PendingOperation, otp?: string): Promise