@venncity/nested-config
Advanced tools
Comparing version 1.2.1 to 1.2.2
@@ -6,2 +6,13 @@ # Change Log | ||
## [1.2.2](https://github.com/venn-city/npm-shelf/compare/@venncity/nested-config@1.2.1...@venncity/nested-config@1.2.2) (2019-08-25) | ||
### Bug Fixes | ||
* **nested-config:** added fallback to parent when property not found ([38a9793](https://github.com/venn-city/npm-shelf/commit/38a9793)) | ||
## [1.2.1](https://github.com/venn-city/npm-shelf/compare/@venncity/nested-config@1.2.0...@venncity/nested-config@1.2.1) (2019-08-20) | ||
@@ -8,0 +19,0 @@ |
{ | ||
"name": "@venncity/nested-config", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"author": "Venn Engineering", | ||
@@ -44,3 +44,3 @@ "main": "src/nestedConfig.js", | ||
}, | ||
"gitHead": "06cdf2e342eb415e6e87fa23e05fb3c07647fd05" | ||
"gitHead": "e84109a501c2dfd8fe22372ba7600cda5e3e914e" | ||
} |
@@ -21,3 +21,3 @@ /* eslint-disable no-underscore-dangle,global-require */ | ||
await createFileAtPath('/inner/config/test.json', '{ "prop": "inner" }'); | ||
await createFileAtPath('/inner/package.json', '{ "prop": "123" }'); | ||
await createFileAtPath('/inner/package.json', '{ "test": "skjl" }'); | ||
const innerModulePath = await createFileAtPath('/inner/src/module.js', '{ "prop": "123" }'); | ||
@@ -32,3 +32,3 @@ | ||
await createFileAtPath('/inner/config/test.json', '{ "prop": "inner1" }'); | ||
await createFileAtPath('/inner/package.json', '{ "prop": "123" }'); | ||
await createFileAtPath('/inner/package.json', '{ "test": "skjl" }'); | ||
const firstInnerModulePath = await createFileAtPath('/inner/src/module1.js', '{ "prop": "123" }'); | ||
@@ -50,3 +50,3 @@ | ||
test('should not load or fail when no config found', async () => { | ||
await createFileAtPath('/inner/package.json', '{ "prop": "123" }'); | ||
await createFileAtPath('/inner/package.json', '{ "test": "skjl" }'); | ||
const innerModulePath = await createFileAtPath('/inner/src/module.js', '{ "prop": "123" }'); | ||
@@ -61,3 +61,3 @@ const nestedConfig = rewire(path.join(__dirname, 'nestedConfig.js')); | ||
await createFileAtPath('/inner/config/test.json', '{ "prop": "inner" }'); | ||
await createFileAtPath('/inner/package.json', '{ "prop": "123" }'); | ||
await createFileAtPath('/inner/package.json', '{ "test": "skjl" }'); | ||
const innerModulePath = await createFileAtPath('/inner/src/module.js', '{ "prop": "123" }'); | ||
@@ -69,2 +69,11 @@ | ||
}); | ||
test('should fallback to parent config when property not found', async () => { | ||
await createFileAtPath('/inner/package.json', '{ "test": "skjl" }'); | ||
const innerModulePath = await createFileAtPath('/inner/src/module.js', '{ "prop": "123" }'); | ||
const nestedConfig = require('./nestedConfig')(innerModulePath); | ||
const testValue = nestedConfig.get('prop'); | ||
expect(testValue).toEqual('outer'); | ||
}); | ||
}); | ||
@@ -75,3 +84,3 @@ | ||
await createFileAtPath('/inner/config/test.json', '{ "prop2": "inner" }'); | ||
await createFileAtPath('/inner/package.json', '{ "prop": "123" }'); | ||
await createFileAtPath('/inner/package.json', '{ "test": "skjl" }'); | ||
const innerModulePath = await createFileAtPath('/inner/src/module.js', '{ "prop2": "123" }'); | ||
@@ -84,3 +93,3 @@ const nestedConfig = require('./nestedConfig')(innerModulePath); | ||
await createFileAtPath('/inner/config/test.json', '{ "prop2": "inner" }'); | ||
await createFileAtPath('/inner/package.json', '{ "prop": "123" }'); | ||
await createFileAtPath('/inner/package.json', '{ "test": "skjl" }'); | ||
const innerModulePath = await createFileAtPath('/inner/src/module.js', '{ "prop2": "123" }'); | ||
@@ -91,2 +100,11 @@ const nestedConfig = require('./nestedConfig')(innerModulePath); | ||
}); | ||
test('should fallback to parent config when property not found', async () => { | ||
await createFileAtPath('/inner/package.json', '{ "test": "skjl" }'); | ||
const innerModulePath = await createFileAtPath('/inner/src/module.js', '{ "prop": "123" }'); | ||
const nestedConfig = require('./nestedConfig')(innerModulePath); | ||
const testValue = nestedConfig.has('prop'); | ||
expect(testValue).toBeTruthy(); | ||
}); | ||
}); | ||
@@ -93,0 +111,0 @@ |
@@ -41,3 +41,8 @@ process.env.ALLOW_CONFIG_MUTATIONS = true; | ||
} | ||
return config.get(`${packagePathToConfigKeyPrefix.get(packagePath)}.${key}`); | ||
try { | ||
return config.get(`${packagePathToConfigKeyPrefix.get(packagePath)}.${key}`); | ||
} catch (e) { | ||
console.info(`Property ${key} not found, fallback to parent config`, e); | ||
return config.get(key); | ||
} | ||
}, | ||
@@ -48,5 +53,10 @@ has: (key, options = { getConfigFromParent: false }) => { | ||
} | ||
return config.has(`${packagePathToConfigKeyPrefix.get(packagePath)}.${key}`); | ||
let innerConfigHas = config.has(`${packagePathToConfigKeyPrefix.get(packagePath)}.${key}`); | ||
if (!innerConfigHas) { | ||
console.info(`Property ${key} not found, fallback to parent config`); | ||
innerConfigHas = config.has(key); | ||
} | ||
return innerConfigHas; | ||
} | ||
}; | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13253
201