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 Zoltan Kochan
parent 36eb104e99
commit 7b19077fcb
4 changed files with 41 additions and 2 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

@@ -157,7 +157,6 @@ export async function getConfig (opts: {
'bitbucket.com',
'bitbucket.org',
],
globalconfig: npmDefaults.globalconfig,
'git-branch-lockfile': false,
hoist: true,
'hoist-pattern': ['*'],
@@ -267,6 +266,8 @@ export async function getConfig (opts: {
...[...npmConfig.list].reverse(),
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

@@ -1,4 +1,5 @@
import * as ini from 'ini'
import path from 'path'
import { config } from '@pnpm/plugin-commands-config'
import { getOutputString } from './utils/index.js'
@@ -219,3 +220,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)
})