From fd6ff0e8f142d90b04bccacbc500f09be7068eef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Poullain?= Date: Sat, 16 Feb 2019 17:07:32 +0100 Subject: [PATCH] Fix config order issue --- packages/core/src/core/config.spec.ts | 16 ++++++++-------- packages/core/src/core/config.ts | 20 ++++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/packages/core/src/core/config.spec.ts b/packages/core/src/core/config.spec.ts index 915a5f4bd8..7ae440e30c 100644 --- a/packages/core/src/core/config.spec.ts +++ b/packages/core/src/core/config.spec.ts @@ -158,23 +158,23 @@ describe('Config', () => { mkdirSync('config'); const dotEnvFileContent = 'BAR_FOO=foo2'; - const defaultJSONFileContent = JSON.stringify({ barFoo: 'foo3' }); - const defaultYAMLFileContent = 'barFoo: foo4'; - const envJSONFileContent = JSON.stringify({ barFoo: 'foo5' }); - const envYAMLFileContent = 'barFoo: foo6'; + const envJSONFileContent = JSON.stringify({ barFoo: 'foo3' }); + const envYAMLFileContent = 'barFoo: foo4'; + const defaultJSONFileContent = JSON.stringify({ barFoo: 'foo5' }); + const defaultYAMLFileContent = 'barFoo: foo6'; strictEqual(Config.get('barFoo', 'foo7'), 'foo7'); - writeFileSync('config/test.yml', envYAMLFileContent, 'utf8'); + writeFileSync('config/default.yml', defaultYAMLFileContent, 'utf8'); strictEqual(Config.get('barFoo', 'foo7'), 'foo6'); - writeFileSync('config/test.json', envJSONFileContent, 'utf8'); + writeFileSync('config/default.json', defaultJSONFileContent, 'utf8'); strictEqual(Config.get('barFoo', 'foo7'), 'foo5'); - writeFileSync('config/default.yml', defaultYAMLFileContent, 'utf8'); + writeFileSync('config/test.yml', envYAMLFileContent, 'utf8'); strictEqual(Config.get('barFoo', 'foo7'), 'foo4'); - writeFileSync('config/default.json', defaultJSONFileContent, 'utf8'); + writeFileSync('config/test.json', envJSONFileContent, 'utf8'); strictEqual(Config.get('barFoo', 'foo7'), 'foo3'); writeFileSync('.env', dotEnvFileContent, 'utf8'); diff --git a/packages/core/src/core/config.ts b/packages/core/src/core/config.ts index 55e61273fa..ee4e5cd07e 100644 --- a/packages/core/src/core/config.ts +++ b/packages/core/src/core/config.ts @@ -16,16 +16,6 @@ export class Config { return dotEnvValue as any; } - const defaultJSONValue = this.readJSONValue('config/default.json', key); - if (defaultJSONValue !== undefined) { - return defaultJSONValue; - } - - const defaultYAMLValue = this.readYAMLValue('config/default.yml', key); - if (defaultYAMLValue !== undefined) { - return defaultYAMLValue; - } - const envJSONFilePath = `config/${process.env.NODE_ENV || 'development'}.json`; const envJSONValue = this.readJSONValue(envJSONFilePath, key); if (envJSONValue !== undefined) { @@ -38,6 +28,16 @@ export class Config { return envYAMLValue; } + const defaultJSONValue = this.readJSONValue('config/default.json', key); + if (defaultJSONValue !== undefined) { + return defaultJSONValue; + } + + const defaultYAMLValue = this.readYAMLValue('config/default.yml', key); + if (defaultYAMLValue !== undefined) { + return defaultYAMLValue; + } + return defaultValue as T; }