From f68c10198f2a91373a8dfb90cf38aec4978428ff Mon Sep 17 00:00:00 2001 From: Igor Redchuk Date: Tue, 18 Apr 2017 12:52:34 +0200 Subject: [PATCH] Fix bug when cannot set a config value to empty string (#3018) * Fixes regression introduced in PR #2440 * Related to #2434 --- __tests__/commands/config.js | 10 ++++++++-- src/cli/commands/config.js | 3 +-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/__tests__/commands/config.js b/__tests__/commands/config.js index 54c5db38f1..c11f043e1d 100644 --- a/__tests__/commands/config.js +++ b/__tests__/commands/config.js @@ -32,12 +32,18 @@ test('cache-folder flag has higher priorities than .yarnrc file', (): Promise => { - return runConfig(['set', 'strict-ssl', ''], {}, '', (config) => { +test('set true when option value is undefined', (): Promise => { + return runConfig(['set', 'strict-ssl'], {}, '', (config) => { expect(config.registries.yarn.homeConfig['strict-ssl']).toBe(true); }); }); +test('set empty string to an option', (): Promise => { + return runConfig(['set', 'version-tag-prefix', ''], {}, '', (config) => { + expect(config.registries.yarn.homeConfig['version-tag-prefix']).toBe(''); + }); +}); + test('set value "false" to an option', (): Promise => { return runConfig(['set', 'strict-ssl', 'false'], {}, '', (config) => { expect(config.registries.yarn.homeConfig['strict-ssl']).toBe(false); diff --git a/src/cli/commands/config.js b/src/cli/commands/config.js index f2b5c64ed9..450c6fb8fb 100644 --- a/src/cli/commands/config.js +++ b/src/cli/commands/config.js @@ -19,8 +19,7 @@ export const {run, setFlags} = buildSubCommands('config', { if (args.length === 0 || args.length > 2) { return false; } - const key = args[0]; - const val = args[1] || true; + const [key, val = true] = args; const yarnConfig = config.registries.yarn; await yarnConfig.saveHomeConfig({[key]: val}); reporter.success(reporter.lang('configSet', key, val));