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

This commit is contained in:
btea authored and GitHub committed 2024-10-01 22:21:06 +02:00
1 parent 807f2de798
commit 8080e44a74
6 files changed
+41

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"@pnpm/cache.commands": patch
---
`pnpm cache view` should specify package name
+1
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:"
+7
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,
+22
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')
})
})
+3
View File
@@ -21,6 +21,9 @@
{
"path": "../../packages/constants"
},
{
"path": "../../packages/error"
},
{
"path": "../../packages/logger"
},
+3
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