From a3e0223ce4643ae5d889768d4313be9b3baba854 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Sat, 25 Feb 2023 18:15:38 +0200 Subject: [PATCH] fix: config set should write to the global config file (#6132) close #5877 close #6131 --- .changeset/serious-rice-boil.md | 6 ++++++ config/plugin-commands-config/src/ConfigCommandOptions.ts | 1 + config/plugin-commands-config/src/config.ts | 6 ++++++ config/plugin-commands-config/test/configDelete.test.ts | 1 + config/plugin-commands-config/test/configGet.test.ts | 1 + config/plugin-commands-config/test/configList.test.ts | 2 ++ config/plugin-commands-config/test/configSet.test.ts | 7 +++++++ 7 files changed, 24 insertions(+) create mode 100644 .changeset/serious-rice-boil.md diff --git a/.changeset/serious-rice-boil.md b/.changeset/serious-rice-boil.md new file mode 100644 index 0000000000..47c1c79698 --- /dev/null +++ b/.changeset/serious-rice-boil.md @@ -0,0 +1,6 @@ +--- +"@pnpm/plugin-commands-config": patch +"pnpm": patch +--- + +`pnpm config set` should write to the global config file by default [#5877](https://github.com/pnpm/pnpm/issues/5877). diff --git a/config/plugin-commands-config/src/ConfigCommandOptions.ts b/config/plugin-commands-config/src/ConfigCommandOptions.ts index a4bed578bc..b8dd210c3e 100644 --- a/config/plugin-commands-config/src/ConfigCommandOptions.ts +++ b/config/plugin-commands-config/src/ConfigCommandOptions.ts @@ -2,6 +2,7 @@ import { Config } from '@pnpm/config' export type ConfigCommandOptions = Pick', + }, ], }, ], @@ -74,6 +78,8 @@ export async function handler (opts: ConfigCommandOptions, params: string[]) { } if (opts.location) { opts.global = opts.location === 'global' + } else if (opts.cliOptions['global'] == null) { + opts.global = true } switch (params[0]) { case 'set': { diff --git a/config/plugin-commands-config/test/configDelete.test.ts b/config/plugin-commands-config/test/configDelete.test.ts index fb7ad0b64d..b38dbd5450 100644 --- a/config/plugin-commands-config/test/configDelete.test.ts +++ b/config/plugin-commands-config/test/configDelete.test.ts @@ -13,6 +13,7 @@ cache-dir=~/cache`) await config.handler({ dir: process.cwd(), + cliOptions: {}, configDir, global: true, rawConfig: {}, diff --git a/config/plugin-commands-config/test/configGet.test.ts b/config/plugin-commands-config/test/configGet.test.ts index 91cf3a4140..b5cb69bbd5 100644 --- a/config/plugin-commands-config/test/configGet.test.ts +++ b/config/plugin-commands-config/test/configGet.test.ts @@ -3,6 +3,7 @@ import { config } from '@pnpm/plugin-commands-config' test('config get', async () => { const configKey = await config.handler({ dir: process.cwd(), + cliOptions: {}, configDir: process.cwd(), global: true, rawConfig: { diff --git a/config/plugin-commands-config/test/configList.test.ts b/config/plugin-commands-config/test/configList.test.ts index 48f3b31853..2a7772ccd1 100644 --- a/config/plugin-commands-config/test/configList.test.ts +++ b/config/plugin-commands-config/test/configList.test.ts @@ -9,6 +9,7 @@ function normalizeNewlines (str: string) { test('config list', async () => { const output = await config.handler({ dir: process.cwd(), + cliOptions: {}, configDir: process.cwd(), rawConfig: { 'store-dir': '~/store', @@ -24,6 +25,7 @@ store-dir=~/store test('config list --json', async () => { const output = await config.handler({ dir: process.cwd(), + cliOptions: {}, configDir: process.cwd(), json: true, rawConfig: { diff --git a/config/plugin-commands-config/test/configSet.test.ts b/config/plugin-commands-config/test/configSet.test.ts index ef295494ac..989bf7cce0 100644 --- a/config/plugin-commands-config/test/configSet.test.ts +++ b/config/plugin-commands-config/test/configSet.test.ts @@ -12,6 +12,7 @@ test('config set using the global option', async () => { await config.handler({ dir: process.cwd(), + cliOptions: {}, configDir, global: true, rawConfig: {}, @@ -31,6 +32,7 @@ test('config set using the location=global option', async () => { await config.handler({ dir: process.cwd(), + cliOptions: {}, configDir, location: 'global', rawConfig: {}, @@ -50,6 +52,7 @@ test('config set using the location=project option', async () => { await config.handler({ dir: process.cwd(), + cliOptions: {}, configDir, location: 'project', rawConfig: {}, @@ -68,8 +71,10 @@ test('config set in project .npmrc file', async () => { await config.handler({ dir: process.cwd(), + cliOptions: {}, configDir, global: false, + location: 'project', rawConfig: {}, }, ['set', 'fetch-retries', '1']) @@ -87,6 +92,7 @@ test('config set key=value', async () => { await config.handler({ dir: process.cwd(), + cliOptions: {}, configDir, location: 'project', rawConfig: {}, @@ -106,6 +112,7 @@ test('config set key=value, when value contains a "="', async () => { await config.handler({ dir: process.cwd(), + cliOptions: {}, configDir, location: 'project', rawConfig: {},