Skip to content

Commit fd7743e

Browse files
committed
add deprecate command
1 parent b914c04 commit fd7743e

4 files changed

Lines changed: 53 additions & 0 deletions

File tree

cli/src/npm-client.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,3 +424,30 @@ export async function packageInit(
424424
})
425425
}
426426
}
427+
428+
/**
429+
* Deprecate a package or a specific version with a custom message.
430+
* @param pkg Package name (e.g. "vue" or "@nuxt/kit")
431+
* @param reason Deprecation message shown to users
432+
* @param version Optional version to deprecate (e.g. "1.0.0"); if omitted, deprecates the whole package
433+
* @param options.dryRun If true, passes --dry-run to npm (report what would be done without making changes)
434+
* @param options.registry Registry URL (e.g. "https://registry.npmjs.org"); if set, passes --registry
435+
*/
436+
export async function packageDeprecate(
437+
pkg: string,
438+
reason: string,
439+
version?: string,
440+
otp?: string,
441+
options?: { dryRun?: boolean; registry?: string },
442+
): Promise<NpmExecResult> {
443+
validatePackageName(pkg)
444+
const target = version ? `${pkg}@${version}` : pkg
445+
const args = ['deprecate', target, reason]
446+
if (options?.dryRun) {
447+
args.push('--dry-run')
448+
}
449+
if (options?.registry?.trim()) {
450+
args.push('--registry', options.registry.trim())
451+
}
452+
return execNpm(args, { otp })
453+
}

cli/src/schemas.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ export const OperationTypeSchema = v.picklist([
106106
'owner:add',
107107
'owner:rm',
108108
'package:init',
109+
'package:deprecate',
109110
])
110111

111112
/**
@@ -231,6 +232,18 @@ export const PackageInitParamsSchema = v.object({
231232
author: v.optional(UsernameSchema),
232233
})
233234

235+
const PackageDeprecateParamsSchema = v.object({
236+
pkg: PackageNameSchema,
237+
message: v.pipe(
238+
v.string(),
239+
v.nonEmpty('Deprecation message is required'),
240+
v.maxLength(500, 'Message is too long'),
241+
),
242+
version: v.optional(v.pipe(v.string(), v.nonEmpty())),
243+
dryRun: v.optional(v.picklist(['true', 'false'], 'dryRun must be "true" or "false"')),
244+
registry: v.optional(v.pipe(v.string(), v.minLength(1, 'Registry URL cannot be empty'))),
245+
})
246+
234247
// ============================================================================
235248
// Helper Functions
236249
// ============================================================================
@@ -280,6 +293,9 @@ export function validateOperationParams(
280293
case 'package:init':
281294
v.parse(PackageInitParamsSchema, params)
282295
break
296+
case 'package:deprecate':
297+
v.parse(PackageDeprecateParamsSchema, params)
298+
break
283299
}
284300
}
285301

cli/src/server.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
ownerAdd,
2424
ownerRemove,
2525
packageInit,
26+
packageDeprecate,
2627
listUserPackages,
2728
type NpmExecResult,
2829
} from './npm-client.ts'
@@ -734,6 +735,14 @@ async function executeOperation(op: PendingOperation, otp?: string): Promise<Npm
734735
return ownerRemove(params.user, params.pkg, otp)
735736
case 'package:init':
736737
return packageInit(params.name, params.author, otp)
738+
case 'package:deprecate': {
739+
const dryRun = params.dryRun === 'true'
740+
const registry = params.registry?.trim() ?? undefined
741+
return packageDeprecate(params.pkg, params.message, params.version, otp, {
742+
dryRun: dryRun ?? undefined,
743+
registry,
744+
})
745+
}
737746
default:
738747
return {
739748
stdout: '',

cli/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export type OperationType =
2424
| 'owner:add'
2525
| 'owner:rm'
2626
| 'package:init'
27+
| 'package:deprecate'
2728

2829
export type OperationStatus =
2930
| 'pending'

0 commit comments

Comments
 (0)