mirror of
https://github.com/pnpm/pnpm.git
synced 2026-05-11 01:15:11 -04:00
feat(plugin-commands-store): add store path command (#3571)
Add a `pnpm store path` command to print the location of the pnpm store as the CLI would resolve it. This allows the user to inspect the current store location, as well as allows external tooling (like shell scripts) to locate the pnpm store without needing to make assumptions about its location or needing to load the `@pnpm/store-path` module. This command differs from running `pnpm get store`, as `pnpm get store` prints "undefined" in the case that no custom store path has been set, which requires external tooling to have knowledge about where pnpm locates its store in the default case. close #2575
This commit is contained in:
5
.changeset/empty-pugs-kick.md
Normal file
5
.changeset/empty-pugs-kick.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-store": minor
|
||||
---
|
||||
|
||||
Add `pnpm store path` command that prints the path to the current store directory.
|
||||
@@ -72,6 +72,8 @@ export async function handler (opts: StoreCommandOptions, params: string[]) {
|
||||
switch (params[0]) {
|
||||
case 'status':
|
||||
return statusCmd(opts)
|
||||
case 'path':
|
||||
return storePath(opts.dir, opts.storeDir)
|
||||
case 'prune': {
|
||||
store = await createOrConnectStoreController(opts)
|
||||
const storePruneOptions = Object.assign(opts, {
|
||||
|
||||
25
packages/plugin-commands-store/test/storePath.ts
Normal file
25
packages/plugin-commands-store/test/storePath.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import os from 'os'
|
||||
import { store } from '@pnpm/plugin-commands-store'
|
||||
import prepare from '@pnpm/prepare'
|
||||
import { REGISTRY_MOCK_PORT } from '@pnpm/registry-mock'
|
||||
|
||||
const REGISTRY = `http://localhost:${REGISTRY_MOCK_PORT}/`
|
||||
|
||||
test('CLI prints the current store path', async () => {
|
||||
prepare()
|
||||
|
||||
const candidateStorePath = await store.handler({
|
||||
dir: process.cwd(),
|
||||
rawConfig: {
|
||||
registry: REGISTRY,
|
||||
},
|
||||
registries: { default: REGISTRY },
|
||||
storeDir: '/home/example/.pnpm-store',
|
||||
}, ['path'])
|
||||
|
||||
const expectedStorePath = os.platform() === 'win32'
|
||||
? '\\home\\example\\.pnpm-store\\v3'
|
||||
: '/home/example/.pnpm-store/v3'
|
||||
|
||||
expect(candidateStorePath).toBe(expectedStorePath)
|
||||
})
|
||||
Reference in New Issue
Block a user