mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-27 18:46:18 -04:00
feat!: support lowercase options in pnpm add (-d, -p, -o, -e) (#10079)
close #9197
This commit is contained in:
12
.changeset/tangy-geckos-fry.md
Normal file
12
.changeset/tangy-geckos-fry.md
Normal file
@@ -0,0 +1,12 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-installation": major
|
||||
"@pnpm/parse-cli-args": major
|
||||
"pnpm": major
|
||||
---
|
||||
|
||||
Support lowercase options in `pnpm add`: `-d`, `-p`, `-o`, `-e` [#9197](https://github.com/pnpm/pnpm/issues/9197).
|
||||
|
||||
When using `pnpm add` command only:
|
||||
|
||||
- `-p` is now an alias for `--save-prod` instead of `--parseable`
|
||||
- `-d` is now an alias for `--save-dev` instead of `--loglevel=info`
|
||||
@@ -201,6 +201,43 @@ test('use command-specific shorthands', async () => {
|
||||
expect(options).toHaveProperty(['dev'])
|
||||
})
|
||||
|
||||
test('command-specific shorthands override universal shorthands', async () => {
|
||||
const { options } = await parseCliArgs({
|
||||
...DEFAULT_OPTS,
|
||||
getTypesByCommandName: (commandName: string) => {
|
||||
if (commandName === 'add') {
|
||||
return {
|
||||
'save-dev': Boolean,
|
||||
'save-prod': Boolean,
|
||||
'save-optional': Boolean,
|
||||
'save-exact': Boolean,
|
||||
loglevel: String,
|
||||
parseable: Boolean,
|
||||
}
|
||||
}
|
||||
return {}
|
||||
},
|
||||
universalShorthands: {
|
||||
d: '--loglevel',
|
||||
p: '--parseable',
|
||||
},
|
||||
shorthandsByCommandName: {
|
||||
add: {
|
||||
d: '--save-dev',
|
||||
p: '--save-prod',
|
||||
o: '--save-optional',
|
||||
e: '--save-exact',
|
||||
},
|
||||
},
|
||||
}, ['add', '-d', '-p', '-o', '-e', 'package'])
|
||||
expect(options['save-dev']).toBe(true)
|
||||
expect(options['save-prod']).toBe(true)
|
||||
expect(options['save-optional']).toBe(true)
|
||||
expect(options['save-exact']).toBe(true)
|
||||
expect(options.loglevel).toBeUndefined()
|
||||
expect(options.parseable).toBeUndefined()
|
||||
})
|
||||
|
||||
test('any unknown command is treated as a script', async () => {
|
||||
const { options, cmd, params, fallbackCommandUsed } = await parseCliArgs({
|
||||
...DEFAULT_OPTS,
|
||||
|
||||
@@ -14,6 +14,10 @@ import { writeSettings } from '@pnpm/config.config-writer'
|
||||
|
||||
export const shorthands: Record<string, string> = {
|
||||
'save-catalog': '--save-catalog-name=default',
|
||||
d: '--save-dev',
|
||||
e: '--save-exact',
|
||||
o: '--save-optional',
|
||||
p: '--save-prod',
|
||||
}
|
||||
|
||||
export function rcOptionsTypes (): Record<string, unknown> {
|
||||
@@ -111,17 +115,17 @@ export function help (): string {
|
||||
{
|
||||
description: 'Save package to your `dependencies`. The default behavior',
|
||||
name: '--save-prod',
|
||||
shortAlias: '-P',
|
||||
shortAlias: '-p',
|
||||
},
|
||||
{
|
||||
description: 'Save package to your `devDependencies`',
|
||||
name: '--save-dev',
|
||||
shortAlias: '-D',
|
||||
shortAlias: '-d',
|
||||
},
|
||||
{
|
||||
description: 'Save package to your `optionalDependencies`',
|
||||
name: '--save-optional',
|
||||
shortAlias: '-O',
|
||||
shortAlias: '-o',
|
||||
},
|
||||
{
|
||||
description: 'Save package to your `peerDependencies` and `devDependencies`',
|
||||
@@ -138,7 +142,7 @@ export function help (): string {
|
||||
{
|
||||
description: 'Install exact version',
|
||||
name: '--[no-]save-exact',
|
||||
shortAlias: '-E',
|
||||
shortAlias: '-e',
|
||||
},
|
||||
{
|
||||
description: 'Save packages from the workspace with a "workspace:" protocol. True by default',
|
||||
|
||||
@@ -37,7 +37,7 @@ test('should print json format error when add dependency on workspace root', asy
|
||||
])
|
||||
writeYamlFile('pnpm-workspace.yaml', { packages: ['**', '!store/**'] })
|
||||
|
||||
const { status, stdout } = execPnpmSync(['add', 'nanoid', '-p'])
|
||||
const { status, stdout } = execPnpmSync(['add', 'nanoid', '--parseable'])
|
||||
|
||||
expect(status).toBe(1)
|
||||
const { error } = JSON.parse(stdout.toString())
|
||||
|
||||
Reference in New Issue
Block a user