feat: add support for pnpm config get globalconfig (#10090)

close #9977
This commit is contained in:
Ryo Matsukawa
2025-11-08 22:14:36 +09:00
committed by GitHub
parent 357490525a
commit d5d4eedeeb
5 changed files with 43 additions and 3 deletions

View File

@@ -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).

View File

@@ -201,7 +201,6 @@ export interface Config extends OptionsFromRootManifest {
rootProjectManifest?: ProjectManifest
userConfig: Record<string, string>
globalconfig: string
hoist: boolean
packageLock: boolean
pending: boolean

View File

@@ -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 = {

View File

@@ -40,7 +40,8 @@ function getRcConfig (rawConfig: Record<string, unknown>, key: string, isScopedK
return { value }
}
if (isStrictlyKebabCase(key)) {
return { value: undefined }
const value = rawConfig[key]
return { value }
}
return undefined
}

View File

@@ -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)
})