From aa0db478736cd90dd0b12fc4b12dd3875e33a0aa Mon Sep 17 00:00:00 2001 From: Igor Redchuk Date: Thu, 12 Jan 2017 23:04:00 +0100 Subject: [PATCH] Set boolean config values correctly * Fixes #2434 --- __tests__/commands/{cache.js => config.js} | 18 ++++++++++++++++++ src/cli/commands/config.js | 4 ++-- src/registries/yarn-registry.js | 2 ++ 3 files changed, 22 insertions(+), 2 deletions(-) rename __tests__/commands/{cache.js => config.js} (65%) diff --git a/__tests__/commands/cache.js b/__tests__/commands/config.js similarity index 65% rename from __tests__/commands/cache.js rename to __tests__/commands/config.js index a169a64067..54c5db38f1 100644 --- a/__tests__/commands/cache.js +++ b/__tests__/commands/config.js @@ -31,3 +31,21 @@ test('cache-folder flag has higher priorities than .yarnrc file', (): Promise => { + return runConfig(['set', 'strict-ssl', ''], {}, '', (config) => { + expect(config.registries.yarn.homeConfig['strict-ssl']).toBe(true); + }); +}); + +test('set value "false" to an option', (): Promise => { + return runConfig(['set', 'strict-ssl', 'false'], {}, '', (config) => { + expect(config.registries.yarn.homeConfig['strict-ssl']).toBe(false); + }); +}); + +test('set value "true" to an option', (): Promise => { + return runConfig(['set', 'strict-ssl', 'true'], {}, '', (config) => { + expect(config.registries.yarn.homeConfig['strict-ssl']).toBe(true); + }); +}); diff --git a/src/cli/commands/config.js b/src/cli/commands/config.js index 96102003d1..f2b5c64ed9 100644 --- a/src/cli/commands/config.js +++ b/src/cli/commands/config.js @@ -19,8 +19,8 @@ export const {run, setFlags} = buildSubCommands('config', { if (args.length === 0 || args.length > 2) { return false; } - - const [key, val = true] = args; + const key = args[0]; + const val = args[1] || true; const yarnConfig = config.registries.yarn; await yarnConfig.saveHomeConfig({[key]: val}); reporter.success(reporter.lang('configSet', key, val)); diff --git a/src/registries/yarn-registry.js b/src/registries/yarn-registry.js index 09fcaa4e0f..270a6a18f7 100644 --- a/src/registries/yarn-registry.js +++ b/src/registries/yarn-registry.js @@ -101,6 +101,8 @@ export default class YarnRegistry extends NpmRegistry { } async saveHomeConfig(config: Object): Promise { + YarnRegistry.normalizeConfig(config); + for (const key in config) { const val = config[key];