From f76a39973eb4c3a84d96a29bee8ea1aee6051e6d Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Mon, 9 Jan 2023 12:43:21 +0200 Subject: [PATCH] fix(config): config set key=value should work (#5899) ref #5889 --- .changeset/fast-chefs-sip.md | 6 +++ config/plugin-commands-config/src/config.ts | 8 +++- .../test/configSet.test.ts | 38 +++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 .changeset/fast-chefs-sip.md diff --git a/.changeset/fast-chefs-sip.md b/.changeset/fast-chefs-sip.md new file mode 100644 index 0000000000..8f6af19794 --- /dev/null +++ b/.changeset/fast-chefs-sip.md @@ -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). diff --git a/config/plugin-commands-config/src/config.ts b/config/plugin-commands-config/src/config.ts index 7d5b584ced..fe691e82e6 100644 --- a/config/plugin-commands-config/src/config.ts +++ b/config/plugin-commands-config/src/config.ts @@ -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]) diff --git a/config/plugin-commands-config/test/configSet.test.ts b/config/plugin-commands-config/test/configSet.test.ts index 1a77238ec5..ef295494ac 100644 --- a/config/plugin-commands-config/test/configSet.test.ts +++ b/config/plugin-commands-config/test/configSet.test.ts @@ -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', + }) +})