From d5d4eedeeba2d6a91aaa972813beeb21dcf84fb3 Mon Sep 17 00:00:00 2001 From: Ryo Matsukawa <76232929+ryo-manba@users.noreply.github.com> Date: Sat, 8 Nov 2025 22:14:36 +0900 Subject: [PATCH] feat: add support for `pnpm config get globalconfig` (#10090) close #9977 --- .changeset/quick-rice-hang.md | 7 ++++ config/config/src/Config.ts | 1 - config/config/src/index.ts | 3 +- .../plugin-commands-config/src/configGet.ts | 3 +- .../test/configGet.test.ts | 32 +++++++++++++++++++ 5 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 .changeset/quick-rice-hang.md diff --git a/.changeset/quick-rice-hang.md b/.changeset/quick-rice-hang.md new file mode 100644 index 0000000000..78f2f50ad1 --- /dev/null +++ b/.changeset/quick-rice-hang.md @@ -0,0 +1,7 @@ +--- +"@pnpm/plugin-commands-config": minor +"@pnpm/config": minor +"pnpm": minor +--- + +Added support for `pnpm config get globalconfig` to retrieve the global config file path [#9977](https://github.com/pnpm/pnpm/issues/9977). diff --git a/config/config/src/Config.ts b/config/config/src/Config.ts index 3ca6e3dd65..4c9316ccfe 100644 --- a/config/config/src/Config.ts +++ b/config/config/src/Config.ts @@ -201,7 +201,6 @@ export interface Config extends OptionsFromRootManifest { rootProjectManifest?: ProjectManifest userConfig: Record - globalconfig: string hoist: boolean packageLock: boolean pending: boolean diff --git a/config/config/src/index.ts b/config/config/src/index.ts index 33c55bce54..0178a391b7 100644 --- a/config/config/src/index.ts +++ b/config/config/src/index.ts @@ -160,7 +160,6 @@ export async function getConfig (opts: { 'bitbucket.com', 'bitbucket.org', ], - globalconfig: npmDefaults.globalconfig, 'git-branch-lockfile': false, hoist: true, 'hoist-pattern': ['*'], @@ -275,6 +274,8 @@ export async function getConfig (opts: { ...npmConfig.list.map(pickNpmAuthConfig).reverse(), pickNpmAuthConfig(cliOptions), { 'user-agent': pnpmConfig.userAgent }, + { globalconfig: path.join(configDir, 'rc') }, + { 'npm-globalconfig': npmDefaults.globalconfig }, ] as any) // eslint-disable-line @typescript-eslint/no-explicit-any const networkConfigs = getNetworkConfigs(pnpmConfig.rawConfig) pnpmConfig.registries = { diff --git a/config/plugin-commands-config/src/configGet.ts b/config/plugin-commands-config/src/configGet.ts index 00e2723287..6f9bb9acb4 100644 --- a/config/plugin-commands-config/src/configGet.ts +++ b/config/plugin-commands-config/src/configGet.ts @@ -40,7 +40,8 @@ function getRcConfig (rawConfig: Record, key: string, isScopedK return { value } } if (isStrictlyKebabCase(key)) { - return { value: undefined } + const value = rawConfig[key] + return { value } } return undefined } diff --git a/config/plugin-commands-config/test/configGet.test.ts b/config/plugin-commands-config/test/configGet.test.ts index 35ca8a222f..1921ee87d1 100644 --- a/config/plugin-commands-config/test/configGet.test.ts +++ b/config/plugin-commands-config/test/configGet.test.ts @@ -1,3 +1,4 @@ +import path from 'path' import { config } from '@pnpm/plugin-commands-config' import { getOutputString } from './utils/index.js' @@ -270,3 +271,34 @@ test('config get with scoped registry key that does not exist', async () => { expect(getOutputString(getResult)).toBe('undefined') }) + +test('config get globalconfig', async () => { + const configDir = process.cwd() + const expectedGlobalconfigPath = path.join(configDir, 'rc') + const getResult = await config.handler({ + dir: process.cwd(), + cliOptions: {}, + configDir, + global: true, + rawConfig: { + globalconfig: expectedGlobalconfigPath, + }, + }, ['get', 'globalconfig']) + + expect(getOutputString(getResult)).toBe(expectedGlobalconfigPath) +}) + +test('config get npm-globalconfig', async () => { + const npmGlobalconfigPath = path.join('/root', '.npmrc') + const getResult = await config.handler({ + dir: process.cwd(), + cliOptions: {}, + configDir: process.cwd(), + global: true, + rawConfig: { + 'npm-globalconfig': npmGlobalconfigPath, + }, + }, ['get', 'npm-globalconfig']) + + expect(getOutputString(getResult)).toBe(npmGlobalconfigPath) +})