fix(config): config set key=value should work (#5899)

ref #5889
This commit is contained in:
Zoltan Kochan
2023-01-09 12:43:21 +02:00
committed by GitHub
parent c7b05cd9a4
commit f76a39973e
3 changed files with 51 additions and 1 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/plugin-commands-config": patch
"pnpm": patch
---
`pnpm config set key=value` should work the same as `pnpm config set key value` [#5889](https://github.com/pnpm/pnpm/issues/5889).

View File

@@ -77,7 +77,13 @@ export async function handler (opts: ConfigCommandOptions, params: string[]) {
}
switch (params[0]) {
case 'set': {
return configSet(opts, params[1], params[2] ?? '')
let [key, value] = params.slice(1)
if (value == null) {
const parts = key.split('=')
key = parts.shift()!
value = parts.join('=')
}
return configSet(opts, key, value ?? '')
}
case 'get': {
return configGet(opts, params[1])

View File

@@ -78,3 +78,41 @@ test('config set in project .npmrc file', async () => {
'fetch-retries': '1',
})
})
test('config set key=value', 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 key=value, when value contains a "="', 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', 'foo=bar=qar'])
expect(readIniFileSync(path.join(tmp, '.npmrc'))).toEqual({
'store-dir': '~/store',
foo: 'bar=qar',
})
})