config 3.2.6 → 3.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/History.md +24 -0
- package/README.md +5 -5
- package/lib/config.js +28 -10
- package/package.json +2 -2
- package/parser.js +28 -1
package/History.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
3.3.3 / 2020-11-26
|
|
2
|
+
==================
|
|
3
|
+
|
|
4
|
+
* FIX #460 - Strict mode warning refer to appropriate env variable @iCodeOkay
|
|
5
|
+
* Use Buffer.alloc and Buffer.from instead of contrsuctor @Fcmam5
|
|
6
|
+
* Add support for experimental .cjs modules @lenkan
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
3.3.2 / 2020-09-24
|
|
10
|
+
==================
|
|
11
|
+
|
|
12
|
+
* Fixed issue with Buffers in config throwing error in util.makeImmutable (#608) - Michal Wadas
|
|
13
|
+
* Added boolean and numeric types to custom environment variables - Ankur Narkhede @ankurnarkhede
|
|
14
|
+
|
|
15
|
+
3.3.1 / 2020-03-25
|
|
16
|
+
==================
|
|
17
|
+
|
|
18
|
+
* Fix security vulnerability in json5 dependency - @twkel
|
|
19
|
+
|
|
20
|
+
3.3.0 / 2020-02-26
|
|
21
|
+
==================
|
|
22
|
+
|
|
23
|
+
* Allow all defined values in `substituteDeep` - @fostyfost
|
|
24
|
+
|
|
1
25
|
3.2.6 / 2020-02-21
|
|
2
26
|
==================
|
|
3
27
|
|
package/README.md
CHANGED
|
@@ -147,23 +147,23 @@ Contributors
|
|
|
147
147
|
<td><img src=https://avatars2.githubusercontent.com/u/1656140?v=4><a href="https://github.com/eheikes">eheikes</a></td>
|
|
148
148
|
<td><img src=https://avatars3.githubusercontent.com/u/138707?v=4><a href="https://github.com/th507">th507</a></td>
|
|
149
149
|
</tr><tr><td><img src=https://avatars2.githubusercontent.com/u/506460?v=4><a href="https://github.com/Osterjour">Osterjour</a></td>
|
|
150
|
+
<td><img src=https://avatars3.githubusercontent.com/u/1751645?v=4><a href="https://github.com/cunneen">cunneen</a></td>
|
|
150
151
|
<td><img src=https://avatars0.githubusercontent.com/u/842998?v=4><a href="https://github.com/nsabovic">nsabovic</a></td>
|
|
151
152
|
<td><img src=https://avatars0.githubusercontent.com/u/5138570?v=4><a href="https://github.com/BadgerBadgerBadgerBadger">BadgerBadgerBadgerBadger</a></td>
|
|
152
153
|
<td><img src=https://avatars2.githubusercontent.com/u/2529835?v=4><a href="https://github.com/simon-scherzinger">simon-scherzinger</a></td>
|
|
153
154
|
<td><img src=https://avatars3.githubusercontent.com/u/8650543?v=4><a href="https://github.com/leonardovillela">leonardovillela</a></td>
|
|
154
|
-
|
|
155
|
-
|
|
155
|
+
</tr><tr><td><img src=https://avatars1.githubusercontent.com/u/175627?v=4><a href="https://github.com/axelhzf">axelhzf</a></td>
|
|
156
|
+
<td><img src=https://avatars3.githubusercontent.com/u/7782055?v=4><a href="https://github.com/benkroeger">benkroeger</a></td>
|
|
156
157
|
<td><img src=https://avatars3.githubusercontent.com/u/1872824?v=4><a href="https://github.com/fgheorghe">fgheorghe</a></td>
|
|
157
158
|
<td><img src=https://avatars3.githubusercontent.com/u/1443067?v=4><a href="https://github.com/IvanVergiliev">IvanVergiliev</a></td>
|
|
158
159
|
<td><img src=https://avatars0.githubusercontent.com/u/1736957?v=4><a href="https://github.com/jpwilliams">jpwilliams</a></td>
|
|
159
160
|
<td><img src=https://avatars2.githubusercontent.com/u/1246875?v=4><a href="https://github.com/jaylynch">jaylynch</a></td>
|
|
160
|
-
|
|
161
|
-
|
|
161
|
+
</tr><tr><td><img src=https://avatars1.githubusercontent.com/u/145742?v=4><a href="https://github.com/jberrisch">jberrisch</a></td>
|
|
162
|
+
<td><img src=https://avatars1.githubusercontent.com/u/9355665?v=4><a href="https://github.com/kgoerlitz">kgoerlitz</a></td>
|
|
162
163
|
<td><img src=https://avatars0.githubusercontent.com/u/8525267?v=4><a href="https://github.com/bertho-zero">bertho-zero</a></td>
|
|
163
164
|
<td><img src=https://avatars3.githubusercontent.com/u/1918551?v=4><a href="https://github.com/nitzan-shaked">nitzan-shaked</a></td>
|
|
164
165
|
<td><img src=https://avatars3.githubusercontent.com/u/3058150?v=4><a href="https://github.com/robertrossmann">robertrossmann</a></td>
|
|
165
166
|
<td><img src=https://avatars2.githubusercontent.com/u/498929?v=4><a href="https://github.com/roncli">roncli</a></td>
|
|
166
|
-
<td><img src=https://avatars2.githubusercontent.com/u/1355559?v=4><a href="https://github.com/superoven">superoven</a></td>
|
|
167
167
|
</tr></table>
|
|
168
168
|
|
|
169
169
|
License
|
package/lib/config.js
CHANGED
|
@@ -15,7 +15,7 @@ var deferConfig = require('../defer').deferConfig,
|
|
|
15
15
|
// Static members
|
|
16
16
|
var DEFAULT_CLONE_DEPTH = 20,
|
|
17
17
|
NODE_CONFIG, CONFIG_DIR, RUNTIME_JSON_FILENAME, NODE_ENV, APP_INSTANCE,
|
|
18
|
-
HOST, HOSTNAME, ALLOW_CONFIG_MUTATIONS, CONFIG_SKIP_GITCRYPT,
|
|
18
|
+
HOST, HOSTNAME, ALLOW_CONFIG_MUTATIONS, CONFIG_SKIP_GITCRYPT, NODE_ENV_VAR_NAME,
|
|
19
19
|
NODE_CONFIG_PARSER,
|
|
20
20
|
env = {},
|
|
21
21
|
privateUtil = {},
|
|
@@ -369,6 +369,9 @@ util.makeHidden = function(object, property, value) {
|
|
|
369
369
|
* @return object {object} - The original object is returned - for chaining.
|
|
370
370
|
*/
|
|
371
371
|
util.makeImmutable = function(object, property, value) {
|
|
372
|
+
if (Buffer.isBuffer(object)) {
|
|
373
|
+
return object;
|
|
374
|
+
}
|
|
372
375
|
var properties = null;
|
|
373
376
|
|
|
374
377
|
// Backwards compatibility mode where property/value can be specified
|
|
@@ -510,11 +513,26 @@ util.loadFileConfigs = function(configDir) {
|
|
|
510
513
|
var t = this,
|
|
511
514
|
config = {};
|
|
512
515
|
|
|
513
|
-
//
|
|
514
|
-
|
|
516
|
+
// Specify variables that can be used to define the environment
|
|
517
|
+
var node_env_var_names = ['NODE_CONFIG_ENV', 'NODE_ENV'];
|
|
518
|
+
|
|
519
|
+
// Loop through the variables to try and set environment
|
|
520
|
+
for (node_env_var_name of node_env_var_names) {
|
|
521
|
+
NODE_ENV = util.initParam(node_env_var_name);
|
|
522
|
+
if (!!NODE_ENV) {
|
|
523
|
+
NODE_ENV_VAR_NAME = node_env_var_name;
|
|
524
|
+
break;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
515
527
|
|
|
516
|
-
//
|
|
517
|
-
|
|
528
|
+
// If we haven't successfully set the environment using the variables, we'll default it
|
|
529
|
+
if (!NODE_ENV) {
|
|
530
|
+
NODE_ENV = 'development';
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
node_env_var_names.forEach(node_env_var_name => {
|
|
534
|
+
env[node_env_var_name] = NODE_ENV;
|
|
535
|
+
});
|
|
518
536
|
|
|
519
537
|
// Split files name, for loading multiple files.
|
|
520
538
|
NODE_ENV = NODE_ENV.split(',');
|
|
@@ -949,7 +967,7 @@ util.cloneDeep = function cloneDeep(parent, depth, circular, prototype) {
|
|
|
949
967
|
} else if (Utils.isDate(parent)) {
|
|
950
968
|
child = new Date(parent.getTime());
|
|
951
969
|
} else if (useBuffer && Buffer.isBuffer(parent)) {
|
|
952
|
-
child =
|
|
970
|
+
child = Buffer.alloc(parent.length);
|
|
953
971
|
parent.copy(child);
|
|
954
972
|
return child;
|
|
955
973
|
} else {
|
|
@@ -1033,12 +1051,12 @@ util.substituteDeep = function (substitutionMap, variables) {
|
|
|
1033
1051
|
for (var prop in map) {
|
|
1034
1052
|
var value = map[prop];
|
|
1035
1053
|
if (typeof(value) === 'string') { // We found a leaf variable name
|
|
1036
|
-
if (vars[value]) { // if the vars provide a value set the value in the result map
|
|
1054
|
+
if (vars[value] !== undefined) { // if the vars provide a value set the value in the result map
|
|
1037
1055
|
util.setPath(result, pathTo.concat(prop), vars[value]);
|
|
1038
1056
|
}
|
|
1039
1057
|
}
|
|
1040
1058
|
else if (util.isObject(value)) { // work on the subtree, giving it a clone of the pathTo
|
|
1041
|
-
if('__name' in value && '__format' in value && vars[value.__name]) {
|
|
1059
|
+
if ('__name' in value && '__format' in value && vars[value.__name] !== undefined) {
|
|
1042
1060
|
try {
|
|
1043
1061
|
var parsedValue = util.parseString(vars[value.__name], value.__format);
|
|
1044
1062
|
} catch(err) {
|
|
@@ -1406,11 +1424,11 @@ util.runStrictnessChecks = function (config) {
|
|
|
1406
1424
|
});
|
|
1407
1425
|
// development is special-cased because it's the default value
|
|
1408
1426
|
if (env && (env !== 'development') && !anyFilesMatchEnv) {
|
|
1409
|
-
_warnOrThrow("
|
|
1427
|
+
_warnOrThrow(NODE_ENV_VAR_NAME+" value of '"+env+"' did not match any deployment config file names.");
|
|
1410
1428
|
}
|
|
1411
1429
|
// Throw if NODE_ENV matches' default' or 'local'
|
|
1412
1430
|
if ((env === 'default') || (env === 'local')) {
|
|
1413
|
-
_warnOrThrow("
|
|
1431
|
+
_warnOrThrow(NODE_ENV_VAR_NAME+" value of '"+env+"' is ambiguous.");
|
|
1414
1432
|
}
|
|
1415
1433
|
});
|
|
1416
1434
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "config",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.3",
|
|
4
4
|
"main": "./lib/config.js",
|
|
5
5
|
"description": "Configuration control for production node deployments",
|
|
6
6
|
"author": "Loren West <open_source@lorenwest.com>",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
},
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"json5": "^1.
|
|
22
|
+
"json5": "^2.1.1"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/node": "^7.0.8",
|
package/parser.js
CHANGED
|
@@ -281,8 +281,33 @@ Parser.stripYamlComments = function(fileStr) {
|
|
|
281
281
|
return fileStr.replace(/^\s*#.*/mg,'').replace(/^\s*[\n|\r]+/mg,'');
|
|
282
282
|
};
|
|
283
283
|
|
|
284
|
-
|
|
284
|
+
/**
|
|
285
|
+
* Parses the environment variable to the boolean equivalent.
|
|
286
|
+
* Defaults to false
|
|
287
|
+
*
|
|
288
|
+
* @param {String} content - Environment variable value
|
|
289
|
+
* @return {boolean} - Boolean value fo the passed variable value
|
|
290
|
+
*/
|
|
291
|
+
Parser.booleanParser = function(filename, content) {
|
|
292
|
+
return content === 'true';
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Parses the environment variable to the number equivalent.
|
|
297
|
+
* Defaults to undefined
|
|
298
|
+
*
|
|
299
|
+
* @param {String} content - Environment variable value
|
|
300
|
+
* @return {Number} - Number value fo the passed variable value
|
|
301
|
+
*/
|
|
302
|
+
Parser.numberParser = function(filename, content) {
|
|
303
|
+
const numberValue = Number(content);
|
|
304
|
+
return Number.isNaN(numberValue) ? undefined : numberValue;
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
var order = ['js', 'cjs', 'ts', 'json', 'json5', 'hjson', 'toml', 'coffee', 'iced', 'yaml', 'yml', 'cson', 'properties', 'xml',
|
|
308
|
+
'boolean', 'number'];
|
|
285
309
|
var definitions = {
|
|
310
|
+
cjs: Parser.jsParser,
|
|
286
311
|
coffee: Parser.coffeeParser,
|
|
287
312
|
cson: Parser.csonParser,
|
|
288
313
|
hjson: Parser.hjsonParser,
|
|
@@ -296,6 +321,8 @@ var definitions = {
|
|
|
296
321
|
xml: Parser.xmlParser,
|
|
297
322
|
yaml: Parser.yamlParser,
|
|
298
323
|
yml: Parser.yamlParser,
|
|
324
|
+
boolean: Parser.booleanParser,
|
|
325
|
+
number: Parser.numberParser
|
|
299
326
|
};
|
|
300
327
|
|
|
301
328
|
Parser.getParser = function(name) {
|