mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-27 10:30:58 -04:00
fix(config): the --location=global CLI option should work (#5843)
ref #5841
This commit is contained in:
6
.changeset/brave-coats-beam.md
Normal file
6
.changeset/brave-coats-beam.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-config": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
The config command should work with the `--location=global` CLI option [#5841](https://github.com/pnpm/pnpm/issues/5841).
|
||||
@@ -5,4 +5,7 @@ export type ConfigCommandOptions = Pick<Config,
|
||||
| 'dir'
|
||||
| 'global'
|
||||
| 'rawConfig'
|
||||
> & { json?: boolean }
|
||||
> & {
|
||||
json?: boolean
|
||||
location?: 'global' | 'project'
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ export function rcOptionsTypes () {
|
||||
export function cliOptionsTypes () {
|
||||
return {
|
||||
global: Boolean,
|
||||
location: ['global', 'project'],
|
||||
json: Boolean,
|
||||
}
|
||||
}
|
||||
@@ -71,6 +72,9 @@ export async function handler (opts: ConfigCommandOptions, params: string[]) {
|
||||
hint: help(),
|
||||
})
|
||||
}
|
||||
if (opts.location) {
|
||||
opts.global = opts.location === 'global'
|
||||
}
|
||||
switch (params[0]) {
|
||||
case 'set': {
|
||||
return configSet(opts, params[1], params[2] ?? '')
|
||||
|
||||
@@ -4,7 +4,7 @@ import { tempDir } from '@pnpm/prepare'
|
||||
import { config } from '@pnpm/plugin-commands-config'
|
||||
import { readIniFileSync } from 'read-ini-file'
|
||||
|
||||
test('config set', async () => {
|
||||
test('config set using the global option', async () => {
|
||||
const tmp = tempDir()
|
||||
const configDir = path.join(tmp, 'global-config')
|
||||
fs.mkdirSync(configDir, { recursive: true })
|
||||
@@ -22,3 +22,59 @@ test('config set', async () => {
|
||||
'fetch-retries': '1',
|
||||
})
|
||||
})
|
||||
|
||||
test('config set using the location=global option', async () => {
|
||||
const tmp = tempDir()
|
||||
const configDir = path.join(tmp, 'global-config')
|
||||
fs.mkdirSync(configDir, { recursive: true })
|
||||
fs.writeFileSync(path.join(configDir, 'rc'), 'store-dir=~/store')
|
||||
|
||||
await config.handler({
|
||||
dir: process.cwd(),
|
||||
configDir,
|
||||
location: 'global',
|
||||
rawConfig: {},
|
||||
}, ['set', 'fetch-retries', '1'])
|
||||
|
||||
expect(readIniFileSync(path.join(configDir, 'rc'))).toEqual({
|
||||
'store-dir': '~/store',
|
||||
'fetch-retries': '1',
|
||||
})
|
||||
})
|
||||
|
||||
test('config set using the location=project option', async () => {
|
||||
const tmp = tempDir()
|
||||
const configDir = path.join(tmp, 'global-config')
|
||||
fs.mkdirSync(configDir, { recursive: true })
|
||||
fs.writeFileSync(path.join(tmp, '.npmrc'), 'store-dir=~/store')
|
||||
|
||||
await config.handler({
|
||||
dir: process.cwd(),
|
||||
configDir,
|
||||
location: 'project',
|
||||
rawConfig: {},
|
||||
}, ['set', 'fetch-retries', '1'])
|
||||
|
||||
expect(readIniFileSync(path.join(tmp, '.npmrc'))).toEqual({
|
||||
'store-dir': '~/store',
|
||||
'fetch-retries': '1',
|
||||
})
|
||||
})
|
||||
|
||||
test('config set in project .npmrc file', async () => {
|
||||
const tmp = tempDir()
|
||||
const configDir = path.join(tmp, 'global-config')
|
||||
fs.writeFileSync(path.join(tmp, '.npmrc'), 'store-dir=~/store')
|
||||
|
||||
await config.handler({
|
||||
dir: process.cwd(),
|
||||
configDir,
|
||||
global: false,
|
||||
rawConfig: {},
|
||||
}, ['set', 'fetch-retries', '1'])
|
||||
|
||||
expect(readIniFileSync(path.join(tmp, '.npmrc'))).toEqual({
|
||||
'store-dir': '~/store',
|
||||
'fetch-retries': '1',
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user