ezzy-environment
Advanced tools
Comparing version 0.1.22 to 0.1.23
{ | ||
"name": "ezzy-environment", | ||
"description": "A lightweight tool to provide common environment settings", | ||
"version": "0.1.22", | ||
"version": "0.1.23", | ||
"author": { | ||
@@ -18,2 +18,3 @@ "name": "Moises Romero", | ||
"test": "node node_modules/ezzy-testing", | ||
"test-debug": "node $NODE_DEBUG_OPTION node_modules/ezzy-testing", | ||
"prebuild": "npm install", | ||
@@ -25,4 +26,4 @@ "build": "npm run coverage" | ||
"deepmerge": "^1.5.2", | ||
"ezzy-argument": "^0.1.17", | ||
"ezzy-logger": "^0.1.21" | ||
"ezzy-argument": "^0.1.18", | ||
"ezzy-logger": "^0.1.22" | ||
}, | ||
@@ -29,0 +30,0 @@ "devDependencies": { |
@@ -10,2 +10,3 @@ let pkg; | ||
const deepmerge = require('deepmerge'); | ||
const logger = require('ezzy-logger').logger; | ||
let inst; | ||
@@ -79,2 +80,8 @@ | ||
/** | ||
* Shortcut to testing property. | ||
* @type {boolean} | ||
*/ | ||
this.testing = this.test; | ||
/** | ||
* If environment is in alpha. | ||
@@ -199,6 +206,21 @@ * @type {boolean} | ||
const argConfig = argument(['configuration', 'package'], undefined); | ||
if (argConfig) { | ||
try { | ||
configuration = deepmerge(argConfig, JSON.stringify(argConfig)); | ||
} catch (e) { | ||
logger.error({ | ||
title: 'Configuration', | ||
message: `The configuration provided isn't a valid json string.`, | ||
error: e | ||
}); | ||
} | ||
} | ||
let config = configuration[namespace] || configuration[`_${namespace}`]; | ||
if (typeof config === 'object' && typeof config[this.name] === 'object') { | ||
config = deepmerge(config, config[this.name]); | ||
const subEnvConfig = config[this.name] || config[`_${this.name}`] || | ||
config[this.name.toUpperCase()]; | ||
if (subEnvConfig) { | ||
config = deepmerge(config, subEnvConfig); | ||
} | ||
@@ -205,0 +227,0 @@ |
@@ -17,2 +17,3 @@ const Environment = require('./Environment'); | ||
expect(environment.test).toBe(true); | ||
expect(environment.testing).toBe(true); | ||
done(); | ||
@@ -70,2 +71,29 @@ }); | ||
it('should access private configuration options', () => { | ||
const conf = environment.getConfiguration('sample', { | ||
_sample: 'abc', | ||
TEST: { | ||
_sample: 'def' | ||
} | ||
}); | ||
expect(conf).toBe('def'); | ||
}); | ||
it('should access correct configuration option', () => { | ||
let conf = environment.getConfiguration('sample', { | ||
_sample: 'abc', | ||
TEST: { | ||
_sample: '' | ||
} | ||
}); | ||
expect(conf).toBe(''); | ||
conf = environment.getConfiguration('sample', { | ||
_sample: '', | ||
TEST: { | ||
_sample: 'abc' | ||
} | ||
}); | ||
expect(conf).toBe('abc'); | ||
}); | ||
it('should be able to access properties in dot notation', () => { | ||
@@ -102,2 +130,4 @@ const conf = { | ||
.toBe(1); | ||
expect(environment.getConfiguration('testProp.prop1.prop2.a', conf)) | ||
.toBe(1); | ||
expect(environment.getConfiguration('testProp.prop1.prop3.a', conf)) | ||
@@ -104,0 +134,0 @@ .toBe(1); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
11747
9
333
2
Updatedezzy-argument@^0.1.18
Updatedezzy-logger@^0.1.22