fix: pnpm cache view command should specify package name (#8582)

This commit is contained in:
btea
2024-10-02 04:21:06 +08:00
committed by GitHub
parent 807f2de798
commit 8080e44a74
6 changed files with 41 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/cache.commands": patch
---
`pnpm cache view` should specify package name

View File

@@ -43,6 +43,7 @@
"@pnpm/cli-utils": "workspace:*",
"@pnpm/config": "workspace:*",
"@pnpm/constants": "workspace:*",
"@pnpm/error": "workspace:*",
"@pnpm/store-path": "workspace:*",
"ramda": "catalog:",
"render-help": "catalog:"

View File

@@ -11,6 +11,7 @@ import {
cacheDelete,
cacheListRegistries,
} from '@pnpm/cache.api'
import { PnpmError } from '@pnpm/error'
export const rcOptionsTypes = cliOptionsTypes
@@ -81,6 +82,12 @@ export async function handler (opts: CacheCommandOptions, params: string[]): Pro
registry: opts.cliOptions['registry'],
}, params.slice(1))
case 'view': {
if (!params[1]) {
throw new PnpmError('MISSING_PACKAGE_NAME', '`pnpm cache view` requires the package name')
}
if (params.length > 2) {
throw new PnpmError('TOO_MANY_PARAMS', '`pnpm cache view` only accepts one package name')
}
const storeDir = await getStorePath({
pkgRoot: process.cwd(),
storePath: opts.storeDir,

View File

@@ -90,4 +90,26 @@ describe('cache view', () => {
}),
}))
})
test('lists all metadata for requested package should specify a package name', async () => {
await expect(
cache.handler({
cacheDir,
cliOptions: {},
pnpmHomeDir: process.cwd(),
storeDir,
}, ['view'])
).rejects.toThrow('`pnpm cache view` requires the package name')
})
test('lists all metadata for requested package should not accept more than one package name', async () => {
await expect(
cache.handler({
cacheDir,
cliOptions: {},
pnpmHomeDir: process.cwd(),
storeDir,
}, ['view', 'is-negative', 'is-positive'])
).rejects.toThrow('`pnpm cache view` only accepts one package name')
})
})

View File

@@ -21,6 +21,9 @@
{
"path": "../../packages/constants"
},
{
"path": "../../packages/error"
},
{
"path": "../../packages/logger"
},

3
pnpm-lock.yaml generated
View File

@@ -1080,6 +1080,9 @@ importers:
'@pnpm/constants':
specifier: workspace:*
version: link:../../packages/constants
'@pnpm/error':
specifier: workspace:*
version: link:../../packages/error
'@pnpm/store-path':
specifier: workspace:*
version: link:../../store/store-path