@adobe/aio-lib-core-config
Advanced tools
Comparing version 3.1.0 to 4.0.0
{ | ||
"name": "@adobe/aio-lib-core-config", | ||
"version": "3.1.0", | ||
"version": "4.0.0", | ||
"description": "Adobe I/O Configuration Module", | ||
@@ -27,21 +27,25 @@ "main": "./src/index.js", | ||
"deepmerge": "^4.0.0", | ||
"dotenv": "8.2.0", | ||
"dotenv": "16.3.1", | ||
"hjson": "^3.1.2", | ||
"js-yaml": "^3.13.0" | ||
"js-yaml": "^4.1.0" | ||
}, | ||
"devDependencies": { | ||
"@adobe/eslint-config-aio-lib-config": "^2.0.0", | ||
"babel-runtime": "^6.26.0", | ||
"eslint": "^6.2.2", | ||
"eslint-config-standard": "^14.1.0", | ||
"eslint-plugin-import": "^2.16.0", | ||
"eslint-plugin-jest": "23.13.2", | ||
"eslint-plugin-node": "^11.0.0", | ||
"eslint-plugin-promise": "^4.0.1", | ||
"eslint-plugin-standard": "^4.0.0", | ||
"jest": "^24.9.0", | ||
"eslint": "^8.38.0", | ||
"eslint-config-standard": "^17.0.0", | ||
"eslint-plugin-import": "^2.27.5", | ||
"eslint-plugin-jest": "^23.20.0", | ||
"eslint-plugin-jsdoc": "^37.9.7", | ||
"eslint-plugin-n": "^15.7.0", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-promise": "^6.1.1", | ||
"eslint-plugin-standard": "^5.0.0", | ||
"jest": "^29.5.0", | ||
"jest-plugin-fs": "^2.9.0", | ||
"jsdoc-to-markdown": "^5.0.3", | ||
"jsdoc-to-markdown": "^8.0.0", | ||
"mock-stdin": "^1.0.0", | ||
"tsd-jsdoc": "^2.4.0" | ||
"tsd-jsdoc": "^2.4.0", | ||
"typescript": "^5.0.4" | ||
} | ||
} |
@@ -71,4 +71,21 @@ <!-- | ||
A local .env file is also loaded. This file can contain environmental variables | ||
A local .env file is also loaded. This file can contain environmental variables. | ||
Note: All environment variable names will be converted to uppercase. | ||
1. In the event that there are duplicate environment variables, if the uppercase version exists, it will be hoisted. | ||
``` | ||
aa=1 | ||
aA=2 | ||
AA=3 <-- Hoisted as AA | ||
``` | ||
2. In the event that there are duplicate environment variables with multiple case variations, the first entry will be hoisted. | ||
``` | ||
aa=1 <-- Hoisted as AA | ||
Aa=2 | ||
``` | ||
## Resolving Values | ||
@@ -75,0 +92,0 @@ |
@@ -22,4 +22,6 @@ /* | ||
* | ||
* @param {String} file | ||
* @param {string} file | ||
* @param {Function} debugFn | ||
* @returns {object} | ||
* @private | ||
*/ | ||
@@ -39,3 +41,3 @@ const readFile = (file) => { | ||
class Config { | ||
reload() { | ||
reload () { | ||
dotenv(true) | ||
@@ -79,3 +81,3 @@ // get the env var and use it as the config root key | ||
get(key = '', source) { | ||
get (key = '', source) { | ||
this.values || this.reload() | ||
@@ -93,3 +95,3 @@ let vals = this.values | ||
set(key, value, local = false) { | ||
set (key, value, local = false) { | ||
this.values || this.reload() | ||
@@ -96,0 +98,0 @@ |
@@ -23,3 +23,4 @@ /* | ||
* | ||
* @param {String} file filepath to parse | ||
* @param {string} file filepath to parse | ||
* @private | ||
*/ | ||
@@ -35,3 +36,3 @@ const parse = (file) => { | ||
* | ||
* @param {String} file filepath to parse | ||
* @param {string} file filepath to parse | ||
*/ | ||
@@ -45,3 +46,3 @@ const checkForDuplicates = (file) => { | ||
const dupKeys = [] | ||
buf.toString().split(NEWLINES_MATCH).forEach(function(line, idx) { | ||
buf.toString().split(NEWLINES_MATCH).forEach(function (line, idx) { | ||
const keyValueArr = line.match(RE_INI_KEY_VAL) | ||
@@ -74,6 +75,6 @@ if (keyValueArr != null) { | ||
* | ||
* @param {Object} o1 | ||
* @param {Object} o2 | ||
* | ||
* @return {Array} array of keys | ||
* @param {object} o1 | ||
* @param {object} o2 | ||
* @returns {Array} array of keys | ||
* @private | ||
*/ | ||
@@ -95,3 +96,3 @@ const diff = (o1, o2) => Object.keys(o1).filter(k => !(k in o2)) | ||
module.exports = function(force = false) { | ||
module.exports = function (force = false) { | ||
const file = path.join(process.cwd(), '.env') | ||
@@ -102,2 +103,14 @@ if (force || global[envFile] !== file) { | ||
const envs = parse(file) | ||
// Convert envs to uppercase | ||
for (const key in envs) { | ||
const keyName = key | ||
const uppercaseKeyName = keyName.toUpperCase() | ||
const keyValue = envs[key] | ||
if (!(uppercaseKeyName in envs)) { | ||
envs[uppercaseKeyName] = keyValue | ||
delete envs[keyName] | ||
} | ||
} | ||
const newKeys = diff(envs, process.env).sort() | ||
@@ -104,0 +117,0 @@ |
@@ -28,4 +28,5 @@ /* | ||
* @param {string} [source] 'global', 'local', or 'env'. Defaults to searching the consolidated config. | ||
* @returns {string|object} the config value | ||
*/ | ||
get(key, source) { | ||
get (key, source) { | ||
return config.get(key, source) | ||
@@ -40,4 +41,5 @@ } | ||
* @param {boolean} [local=false] Set to true to save the value in the local config. Defaults to false (save to global config). | ||
* @returns {object} the Config object itself | ||
*/ | ||
set(key, value, local) { | ||
set (key, value, local) { | ||
return config.set(key, value, local) && this | ||
@@ -51,4 +53,5 @@ } | ||
* @param {boolean} [local=false] Set to true to delete the value in the local config. Defaults to false (save to global config). | ||
* @returns {object} the Config object itself | ||
*/ | ||
delete(key, local) { | ||
delete (key, local) { | ||
return config.set(key, null, local) && this | ||
@@ -59,4 +62,6 @@ } | ||
* Reload the Config from all the config file(s) | ||
* | ||
* @returns {object} the Config object itself, if reload was successful | ||
*/ | ||
reload() { | ||
reload () { | ||
return config.reload() && this | ||
@@ -69,5 +74,5 @@ } | ||
* @function | ||
* @return {Promise<string>} | ||
* @returns {Promise<string>} tje pipe | ||
*/ | ||
get getPipedData() { | ||
get getPipedData () { | ||
return pipe | ||
@@ -80,5 +85,5 @@ } | ||
* @function | ||
* @param {Object} the dotenv object | ||
* @returns {object} the dotenv object | ||
*/ | ||
get dotenv() { | ||
get dotenv () { | ||
return dotenv | ||
@@ -85,0 +90,0 @@ } |
@@ -22,3 +22,3 @@ /* | ||
* | ||
* @param {String} dir the folder to create | ||
* @param {string} dir the folder to create | ||
*/ | ||
@@ -37,4 +37,5 @@ const mkdirp = dir => { | ||
* | ||
* @param {Object} obj | ||
* @param {String} key | ||
* @param {object} obj | ||
* @param {string} key | ||
* @private | ||
*/ | ||
@@ -46,6 +47,5 @@ const getProp = (obj, key) => obj[Object.keys(obj).find(k => k.toLowerCase() === key.toLowerCase())] | ||
* | ||
* @param {String} key | ||
* @param {Object} obj | ||
* | ||
* @return {Object} | ||
* @param {object} obj the object to get the value for the key from | ||
* @param {string} key the key | ||
* @returns {object} the value | ||
*/ | ||
@@ -60,7 +60,6 @@ const getValue = (obj, key) => { | ||
* | ||
* @param {String} key | ||
* @param {String} value | ||
* @param {Object} [obj] | ||
* | ||
* @return {Object} | ||
* @param {string} key the key | ||
* @param {string} value the value to set | ||
* @param {object} [obj] the object to set the value for the key to | ||
* @returns {object} the transformed object | ||
*/ | ||
@@ -86,4 +85,3 @@ const setValue = (key, value, obj) => { | ||
* @param {Array} objs array of objects | ||
* | ||
* @return {Object} | ||
* @returns {object} the merged object | ||
*/ | ||
@@ -102,5 +100,4 @@ const merge = (...objs) => { | ||
* | ||
* @param {Object} obj | ||
* | ||
* @return {Object} | ||
* @param {object} obj the object to shake | ||
* @returns {object} the object with empty leaves removed | ||
*/ | ||
@@ -128,5 +125,4 @@ const shake = obj => { | ||
* | ||
* @param {String} file | ||
* | ||
* @return {Object} | ||
* @param {string} file the file to load | ||
* @returns {object} object containing the file contents and format | ||
*/ | ||
@@ -145,3 +141,3 @@ const loadFile = (file) => { | ||
try { | ||
return { values: yaml.safeLoad(contents, { json: true }), format: 'yaml' } | ||
return { values: yaml.load(contents, { json: true }), format: 'yaml' } | ||
} catch (e) { | ||
@@ -158,5 +154,6 @@ throw new Error('Cannot parse yaml') | ||
* | ||
* @param {String} file | ||
* @param {Object} obj | ||
* @param {String} format | ||
* @param {string} file the file to save to | ||
* @param {object} obj the object to save | ||
* @param {string} format the format of the file to save | ||
* @returns {object} true if the file was written successfully | ||
*/ | ||
@@ -175,3 +172,3 @@ const saveFile = (file, obj, format) => { | ||
} else { | ||
str = yaml.safeDump(obj, { sortKeys: true, lineWidth: 1024, noCompatMode: true }) | ||
str = yaml.dump(obj, { sortKeys: true, lineWidth: 1024, noCompatMode: true }) | ||
} | ||
@@ -183,2 +180,9 @@ | ||
module.exports = { mkdirp, getValue, setValue, merge, loadFile, saveFile } | ||
module.exports = { | ||
mkdirp, | ||
getValue, | ||
setValue, | ||
merge, | ||
loadFile, | ||
saveFile | ||
} |
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
34852
557
122
17
+ Addedargparse@2.0.1(transitive)
+ Addeddotenv@16.3.1(transitive)
+ Addedjs-yaml@4.1.0(transitive)
- Removedargparse@1.0.10(transitive)
- Removeddotenv@8.2.0(transitive)
- Removedesprima@4.0.1(transitive)
- Removedjs-yaml@3.14.1(transitive)
- Removedsprintf-js@1.0.3(transitive)
Updateddotenv@16.3.1
Updatedjs-yaml@^4.1.0