mirror of
https://github.com/pnpm/pnpm.git
synced 2026-06-28 18:05:29 -04:00
Replace the hardcoded command name list in main.ts with a declarative recursiveByDefault property on CommandDefinition. Each command that should run workspace-wide by default now exports this property. Also adds recursiveByDefault to list, ll, and why commands.
73 lines
2.3 KiB
TypeScript
73 lines
2.3 KiB
TypeScript
import type { CommandHandlerMap } from '@pnpm/cli.command'
|
|
import { OPTIONS, UNIVERSAL_OPTIONS } from '@pnpm/cli.common-cli-options-help'
|
|
import { docsUrl } from '@pnpm/cli.utils'
|
|
import { dedupeDiffCheck } from '@pnpm/installing.dedupe.check'
|
|
import { omit } from 'ramda'
|
|
import { renderHelp } from 'render-help'
|
|
|
|
import { type InstallCommandOptions, rcOptionsTypes as installCommandRcOptionsTypes } from './install.js'
|
|
import { installDeps } from './installDeps.js'
|
|
|
|
// In general, the "pnpm dedupe" command should use .npmrc options that "pnpm install" would also accept.
|
|
export function rcOptionsTypes (): Record<string, unknown> {
|
|
// Some options on pnpm install (like --frozen-lockfile) don't make sense on pnpm dedupe.
|
|
return omit(['frozen-lockfile'], installCommandRcOptionsTypes())
|
|
}
|
|
|
|
export function cliOptionsTypes (): Record<string, unknown> {
|
|
return {
|
|
...rcOptionsTypes(),
|
|
check: Boolean,
|
|
}
|
|
}
|
|
|
|
export const commandNames = ['dedupe']
|
|
|
|
export const recursiveByDefault = true
|
|
|
|
export function help (): string {
|
|
return renderHelp({
|
|
description: 'Perform an install removing older dependencies in the lockfile if a newer version can be used.',
|
|
descriptionLists: [
|
|
{
|
|
title: 'Options',
|
|
list: [
|
|
...UNIVERSAL_OPTIONS,
|
|
{
|
|
description: 'Check if running dedupe would result in changes without installing packages or editing the lockfile. Exits with a non-zero status code if changes are possible.',
|
|
name: '--check',
|
|
},
|
|
OPTIONS.ignoreScripts,
|
|
OPTIONS.offline,
|
|
OPTIONS.preferOffline,
|
|
OPTIONS.storeDir,
|
|
OPTIONS.virtualStoreDir,
|
|
OPTIONS.globalDir,
|
|
],
|
|
},
|
|
],
|
|
url: docsUrl('dedupe'),
|
|
usages: ['pnpm dedupe'],
|
|
})
|
|
}
|
|
|
|
export interface DedupeCommandOptions extends InstallCommandOptions {
|
|
readonly check?: boolean
|
|
}
|
|
|
|
export async function handler (opts: DedupeCommandOptions, _params?: string[], commands?: CommandHandlerMap): Promise<void> {
|
|
const include = {
|
|
dependencies: opts.production !== false,
|
|
devDependencies: opts.dev !== false,
|
|
optionalDependencies: opts.optional !== false,
|
|
}
|
|
return installDeps({
|
|
...opts,
|
|
rebuildHandler: commands?.rebuild,
|
|
dedupe: true,
|
|
include,
|
|
includeDirect: include,
|
|
lockfileCheck: opts.check ? dedupeDiffCheck : undefined,
|
|
}, [])
|
|
}
|