From 1a51cd66dc5ca8a2c884acd1246070bddb8ae4ae Mon Sep 17 00:00:00 2001 From: lvqq Date: Thu, 6 Apr 2023 00:00:38 +0800 Subject: [PATCH] fix: `pnpm config get -g` returns empty when the value is a boolean --- .changeset/little-badgers-sort.md | 5 +++++ config/plugin-commands-config/src/configGet.ts | 3 ++- .../plugin-commands-config/test/configGet.test.ts | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 .changeset/little-badgers-sort.md diff --git a/.changeset/little-badgers-sort.md b/.changeset/little-badgers-sort.md new file mode 100644 index 00000000000..205f11e9749 --- /dev/null +++ b/.changeset/little-badgers-sort.md @@ -0,0 +1,5 @@ +--- +"@pnpm/plugin-commands-config": patch +--- + +`pnpm config get ` returns empty when the value is a boolean diff --git a/config/plugin-commands-config/src/configGet.ts b/config/plugin-commands-config/src/configGet.ts index 30a9f6f2ba6..78b39ba40db 100644 --- a/config/plugin-commands-config/src/configGet.ts +++ b/config/plugin-commands-config/src/configGet.ts @@ -1,5 +1,6 @@ import { type ConfigCommandOptions } from './ConfigCommandOptions' export function configGet (opts: ConfigCommandOptions, key: string) { - return opts.rawConfig[key] + const config = opts.rawConfig[key] + return typeof config === 'boolean' ? config.toString() : config } diff --git a/config/plugin-commands-config/test/configGet.test.ts b/config/plugin-commands-config/test/configGet.test.ts index b5cb69bbd56..818f5a4043a 100644 --- a/config/plugin-commands-config/test/configGet.test.ts +++ b/config/plugin-commands-config/test/configGet.test.ts @@ -13,3 +13,17 @@ test('config get', async () => { expect(configKey).toEqual('~/store') }) + +test('config get a boolean should return string format', async () => { + const configKey = await config.handler({ + dir: process.cwd(), + cliOptions: {}, + configDir: process.cwd(), + global: true, + rawConfig: { + 'update-notifier': true, + }, + }, ['get', 'update-notifier']) + + expect(configKey).toEqual('true') +})