Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions cli/src/npm-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<NpmExecResult> {
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 })
}
16 changes: 16 additions & 0 deletions cli/src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export const OperationTypeSchema = v.picklist([
'owner:add',
'owner:rm',
'package:init',
'package:deprecate',
])

/**
Expand Down Expand Up @@ -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
// ============================================================================
Expand Down Expand Up @@ -280,6 +293,9 @@ export function validateOperationParams(
case 'package:init':
v.parse(PackageInitParamsSchema, params)
break
case 'package:deprecate':
v.parse(PackageDeprecateParamsSchema, params)
break
}
}

Expand Down
9 changes: 9 additions & 0 deletions cli/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
ownerAdd,
ownerRemove,
packageInit,
packageDeprecate,
listUserPackages,
type NpmExecResult,
} from './npm-client.ts'
Expand Down Expand Up @@ -734,6 +735,14 @@ async function executeOperation(op: PendingOperation, otp?: string): Promise<Npm
return ownerRemove(params.user, params.pkg, otp)
case 'package:init':
return packageInit(params.name, params.author, otp)
case 'package:deprecate': {
const dryRun = params.dryRun === 'true'
const registry = params.registry?.trim() ?? undefined
return packageDeprecate(params.pkg, params.message, params.version, otp, {
dryRun: dryRun ?? undefined,
registry,
})
}
default:
return {
stdout: '',
Expand Down
1 change: 1 addition & 0 deletions cli/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type OperationType =
| 'owner:add'
| 'owner:rm'
| 'package:init'
| 'package:deprecate'

export type OperationStatus =
| 'pending'
Expand Down
Loading