From f5ec0a96f2678019fa0523727e79d7d399271253 Mon Sep 17 00:00:00 2001 From: Jacob Gillespie Date: Thu, 1 Jul 2021 14:35:16 +0100 Subject: [PATCH] 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 --- .changeset/empty-pugs-kick.md | 5 ++++ packages/plugin-commands-store/src/store.ts | 2 ++ .../plugin-commands-store/test/storePath.ts | 25 +++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 .changeset/empty-pugs-kick.md create mode 100644 packages/plugin-commands-store/test/storePath.ts 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) +})