diff --git a/.changeset/empty-pugs-kick.md b/.changeset/empty-pugs-kick.md new file mode 100644 index 0000000000..561fa93f67 --- /dev/null +++ b/.changeset/empty-pugs-kick.md @@ -0,0 +1,5 @@ +--- +"@pnpm/plugin-commands-store": minor +--- + +Add `pnpm store path` command that prints the path to the current store directory. diff --git a/packages/plugin-commands-store/src/store.ts b/packages/plugin-commands-store/src/store.ts index 3c86575aec..8c720b22b1 100644 --- a/packages/plugin-commands-store/src/store.ts +++ b/packages/plugin-commands-store/src/store.ts @@ -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, { diff --git a/packages/plugin-commands-store/test/storePath.ts b/packages/plugin-commands-store/test/storePath.ts new file mode 100644 index 0000000000..4255b20826 --- /dev/null +++ b/packages/plugin-commands-store/test/storePath.ts @@ -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) +})