config 2.0.0 → 3.0.1
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 +8 -8
- package/lib/config.js +12 -170
- package/package.json +1 -1
package/History.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
3.0.1 / 2018-12-16
|
|
2
|
+
==================
|
|
3
|
+
|
|
4
|
+
* Fixed bug where dot notation extended own key @exogen
|
|
5
|
+
|
|
6
|
+
3.0.0 / 2018-11-20
|
|
7
|
+
==================
|
|
8
|
+
|
|
9
|
+
* Ensure config array items and objects are sealed @fgheorghe
|
|
10
|
+
- This required a major version bump in case someone
|
|
11
|
+
- relied on the ability to mutate non-sealed data.
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
2.0.2 / 2018-08-28
|
|
15
|
+
==================
|
|
16
|
+
|
|
17
|
+
* Added dot notation to setModuleDefaults - bertho-zero
|
|
18
|
+
* Updated copyright year - JemiloII
|
|
19
|
+
|
|
20
|
+
2.0.1 / 2018-07-26
|
|
21
|
+
==================
|
|
22
|
+
|
|
23
|
+
* Removed deprecated code - jpwilliams
|
|
24
|
+
|
|
1
25
|
2.0.0 / 2018-07-26
|
|
2
26
|
==================
|
|
3
27
|
|
package/README.md
CHANGED
|
@@ -151,19 +151,19 @@ Contributors
|
|
|
151
151
|
<td><img src=https://avatars2.githubusercontent.com/u/2529835?v=4><a href="https://github.com/simon-scherzinger">simon-scherzinger</a></td>
|
|
152
152
|
<td><img src=https://avatars1.githubusercontent.com/u/175627?v=4><a href="https://github.com/axelhzf">axelhzf</a></td>
|
|
153
153
|
<td><img src=https://avatars3.githubusercontent.com/u/7782055?v=4><a href="https://github.com/benkroeger">benkroeger</a></td>
|
|
154
|
-
<td><img src=https://avatars3.githubusercontent.com/u/
|
|
155
|
-
</tr><tr><td><img src=https://
|
|
154
|
+
<td><img src=https://avatars3.githubusercontent.com/u/1872824?v=4><a href="https://github.com/fgheorghe">fgheorghe</a></td>
|
|
155
|
+
</tr><tr><td><img src=https://avatars3.githubusercontent.com/u/1443067?v=4><a href="https://github.com/IvanVergiliev">IvanVergiliev</a></td>
|
|
156
|
+
<td><img src=https://avatars0.githubusercontent.com/u/1736957?v=4><a href="https://github.com/jpwilliams">jpwilliams</a></td>
|
|
157
|
+
<td><img src=https://avatars2.githubusercontent.com/u/1246875?v=4><a href="https://github.com/jaylynch">jaylynch</a></td>
|
|
156
158
|
<td><img src=https://avatars1.githubusercontent.com/u/145742?v=4><a href="https://github.com/jberrisch">jberrisch</a></td>
|
|
157
159
|
<td><img src=https://avatars1.githubusercontent.com/u/9355665?v=4><a href="https://github.com/kgoerlitz">kgoerlitz</a></td>
|
|
158
|
-
<td><img src=https://
|
|
160
|
+
<td><img src=https://avatars0.githubusercontent.com/u/8525267?v=4><a href="https://github.com/bertho-zero">bertho-zero</a></td>
|
|
161
|
+
</tr><tr><td><img src=https://avatars3.githubusercontent.com/u/8650543?v=4><a href="https://github.com/leonardovillela">leonardovillela</a></td>
|
|
159
162
|
<td><img src=https://avatars3.githubusercontent.com/u/1918551?v=4><a href="https://github.com/nitzan-shaked">nitzan-shaked</a></td>
|
|
160
163
|
<td><img src=https://avatars3.githubusercontent.com/u/3058150?v=4><a href="https://github.com/robertrossmann">robertrossmann</a></td>
|
|
161
|
-
|
|
164
|
+
<td><img src=https://avatars2.githubusercontent.com/u/498929?v=4><a href="https://github.com/roncli">roncli</a></td>
|
|
162
165
|
<td><img src=https://avatars2.githubusercontent.com/u/1355559?v=4><a href="https://github.com/superoven">superoven</a></td>
|
|
163
166
|
<td><img src=https://avatars2.githubusercontent.com/u/54934?v=4><a href="https://github.com/wmertens">wmertens</a></td>
|
|
164
|
-
<td><img src=https://avatars3.githubusercontent.com/u/2842176?v=4><a href="https://github.com/XadillaX">XadillaX</a></td>
|
|
165
|
-
<td><img src=https://avatars2.githubusercontent.com/u/527814?v=4><a href="https://github.com/jacobemerick">jacobemerick</a></td>
|
|
166
|
-
<td><img src=https://avatars1.githubusercontent.com/u/4425455?v=4><a href="https://github.com/ncuillery">ncuillery</a></td>
|
|
167
167
|
</tr></table>
|
|
168
168
|
|
|
169
169
|
License
|
|
@@ -171,6 +171,6 @@ License
|
|
|
171
171
|
|
|
172
172
|
May be freely distributed under the [MIT license](https://raw.githubusercontent.com/lorenwest/node-config/master/LICENSE).
|
|
173
173
|
|
|
174
|
-
Copyright (c) 2010-
|
|
174
|
+
Copyright (c) 2010-2018 Loren West
|
|
175
175
|
[and other contributors](https://github.com/lorenwest/node-config/graphs/contributors)
|
|
176
176
|
|
package/lib/config.js
CHANGED
|
@@ -230,141 +230,6 @@ Config.prototype.has = function(property) {
|
|
|
230
230
|
return (getImpl(t, property) !== undefined);
|
|
231
231
|
};
|
|
232
232
|
|
|
233
|
-
/**
|
|
234
|
-
* <p>Monitor a javascript property for runtime changes.</p>
|
|
235
|
-
*
|
|
236
|
-
* <p>
|
|
237
|
-
* This method was built for an earlier version of node-config that allowed
|
|
238
|
-
* configuration value mutations. Since version 1.0.0, node-config no longer
|
|
239
|
-
* allows configuration mutations, and is no longer used in node-config.
|
|
240
|
-
* </p>
|
|
241
|
-
*
|
|
242
|
-
* <p>
|
|
243
|
-
* It is deprecated, and will be removed in the next semver incompatible release 2.0.0.
|
|
244
|
-
* </p>
|
|
245
|
-
*
|
|
246
|
-
* @method watch
|
|
247
|
-
* @deprecated
|
|
248
|
-
* @param object {object} - The object to watch.
|
|
249
|
-
* @param property {string} - The property name to watch. Watch all object properties if null.
|
|
250
|
-
* @param handler {function(object, propertyName, priorValue, newValue)} - Handler called when a property change is detected.
|
|
251
|
-
* The handler is run along with other handlers registered for notification.
|
|
252
|
-
* If your handler changes the value of the property, that change is applied after all handlers have finished processing the current change.
|
|
253
|
-
* Then all handlers (including this one) will be called again with the newly changed value.
|
|
254
|
-
* @param depth {integer} (optional) - If watching all object properties or if the specified property is an object, this specifies the depth of the object graph to watch for changes. Default 6.
|
|
255
|
-
* @return object {object} - The original object is returned - for chaining.
|
|
256
|
-
*/
|
|
257
|
-
util.watch = function(object, property, handler, depth) {
|
|
258
|
-
|
|
259
|
-
// Initialize
|
|
260
|
-
var t = this, o = object;
|
|
261
|
-
var allProperties = property ? [property] : Object.keys(o);
|
|
262
|
-
|
|
263
|
-
// Deprecation warning
|
|
264
|
-
if (!deprecationWarnings.watch) {
|
|
265
|
-
console.error('WARNING: config.' + fnName + '() is deprecated, and will not be supported in release 2.0.');
|
|
266
|
-
console.error('WARNING: See https://github.com/lorenwest/node-config/wiki/Future-Compatibility#upcoming-incompatibilities');
|
|
267
|
-
deprecationWarnings.watch = true;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
// Depth detection
|
|
271
|
-
depth = (depth === null ? DEFAULT_CLONE_DEPTH : depth);
|
|
272
|
-
if (depth < 0) {
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
// Create hidden properties on the object
|
|
277
|
-
if (!o.__watchers)
|
|
278
|
-
util.makeHidden(o, '__watchers', {});
|
|
279
|
-
if (!o.__propertyValues)
|
|
280
|
-
util.makeHidden(o, '__propertyValues', {});
|
|
281
|
-
|
|
282
|
-
// Attach watchers to all requested properties
|
|
283
|
-
allProperties.forEach(function(prop){
|
|
284
|
-
|
|
285
|
-
// Setup the property for watching (first time only)
|
|
286
|
-
if (typeof(o.__propertyValues[prop]) === 'undefined') {
|
|
287
|
-
|
|
288
|
-
// Don't error re-defining the property if immutable
|
|
289
|
-
var descriptor = Object.getOwnPropertyDescriptor(o, prop);
|
|
290
|
-
if (descriptor && descriptor.writable === false)
|
|
291
|
-
return;
|
|
292
|
-
|
|
293
|
-
// Copy the value to the hidden field, and add the property to watchers
|
|
294
|
-
o.__propertyValues[prop] = [o[prop]];
|
|
295
|
-
o.__watchers[prop] = [];
|
|
296
|
-
|
|
297
|
-
// Attach the property watcher
|
|
298
|
-
Object.defineProperty(o, prop, {
|
|
299
|
-
enumerable : true,
|
|
300
|
-
|
|
301
|
-
get : function(){
|
|
302
|
-
// If more than 1 item is in the values array,
|
|
303
|
-
// then we're currently processing watchers.
|
|
304
|
-
if (o.__propertyValues[prop].length === 1)
|
|
305
|
-
// Current value
|
|
306
|
-
return o.__propertyValues[prop][0];
|
|
307
|
-
else
|
|
308
|
-
// [0] is prior value, [1] is new value being processed
|
|
309
|
-
return o.__propertyValues[prop][1];
|
|
310
|
-
},
|
|
311
|
-
|
|
312
|
-
set : function(newValue) {
|
|
313
|
-
|
|
314
|
-
// Return early if no change
|
|
315
|
-
var origValue = o[prop];
|
|
316
|
-
if (util.equalsDeep(origValue, newValue))
|
|
317
|
-
return;
|
|
318
|
-
|
|
319
|
-
// Remember the new value, and return if we're in another setter
|
|
320
|
-
o.__propertyValues[prop].push(newValue);
|
|
321
|
-
if (o.__propertyValues[prop].length > 2)
|
|
322
|
-
return;
|
|
323
|
-
|
|
324
|
-
// Call all watchers for each change requested
|
|
325
|
-
var numIterations = 0;
|
|
326
|
-
while (o.__propertyValues[prop].length > 1) {
|
|
327
|
-
|
|
328
|
-
// Detect recursion
|
|
329
|
-
if (++numIterations > 20) {
|
|
330
|
-
o.__propertyValues[prop] = [origValue];
|
|
331
|
-
throw new Error('Recursion detected while setting [' + prop + ']');
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
// Call each watcher for the current values
|
|
335
|
-
var oldValue = o.__propertyValues[prop][0];
|
|
336
|
-
newValue = o.__propertyValues[prop][1];
|
|
337
|
-
o.__watchers[prop].forEach(function(watcher) {
|
|
338
|
-
try {
|
|
339
|
-
watcher(o, prop, oldValue, newValue);
|
|
340
|
-
} catch (e) {
|
|
341
|
-
// Log an error and continue with subsequent watchers
|
|
342
|
-
console.error("Exception in object watcher for " + prop, e);
|
|
343
|
-
}
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
// Done processing this value
|
|
347
|
-
o.__propertyValues[prop].splice(0,1);
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
} // Done setting up the property for watching (first time)
|
|
353
|
-
|
|
354
|
-
// Add the watcher to the property
|
|
355
|
-
o.__watchers[prop].push(handler);
|
|
356
|
-
|
|
357
|
-
// Recurs if this is an object...
|
|
358
|
-
if (o[prop] && typeof(o[prop]) === 'object') {
|
|
359
|
-
util.watch(o[prop], null, handler, depth - 1);
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
}); // Done processing each property
|
|
363
|
-
|
|
364
|
-
// Return the original object - for chaining
|
|
365
|
-
return o;
|
|
366
|
-
};
|
|
367
|
-
|
|
368
233
|
/**
|
|
369
234
|
* <p>
|
|
370
235
|
* Set default configurations for a node.js module.
|
|
@@ -411,17 +276,17 @@ util.setModuleDefaults = function (moduleName, defaultProperties) {
|
|
|
411
276
|
parsed: {}
|
|
412
277
|
});
|
|
413
278
|
}
|
|
414
|
-
configSources[0].parsed
|
|
415
|
-
util.extendDeep(configSources[0].parsed
|
|
279
|
+
util.setPath(configSources[0].parsed, moduleName.split('.'), {});
|
|
280
|
+
util.extendDeep(getImpl(configSources[0].parsed, moduleName), defaultProperties);
|
|
416
281
|
|
|
417
282
|
// Create a top level config for this module if it doesn't exist
|
|
418
|
-
t
|
|
283
|
+
util.setPath(t, moduleName.split('.'), getImpl(t, moduleName) || {});
|
|
419
284
|
|
|
420
285
|
// Extend local configurations into the module config
|
|
421
|
-
util.extendDeep(moduleConfig, t
|
|
286
|
+
util.extendDeep(moduleConfig, getImpl(t, moduleName));
|
|
422
287
|
|
|
423
288
|
// Merge the extended configs without replacing the original
|
|
424
|
-
util.extendDeep(t
|
|
289
|
+
util.extendDeep(getImpl(t, moduleName), moduleConfig);
|
|
425
290
|
|
|
426
291
|
// reset the mutability check for "config.get" method.
|
|
427
292
|
// we are not making t[moduleName] immutable immediately,
|
|
@@ -431,7 +296,7 @@ util.setModuleDefaults = function (moduleName, defaultProperties) {
|
|
|
431
296
|
}
|
|
432
297
|
|
|
433
298
|
// Attach handlers & watchers onto the module config object
|
|
434
|
-
return util.attachProtoDeep(t
|
|
299
|
+
return util.attachProtoDeep(getImpl(t, moduleName));
|
|
435
300
|
};
|
|
436
301
|
|
|
437
302
|
/**
|
|
@@ -556,6 +421,9 @@ util.makeImmutable = function(object, property, value) {
|
|
|
556
421
|
configurable: false
|
|
557
422
|
});
|
|
558
423
|
} else if (Array.isArray(value)) {
|
|
424
|
+
// Ensure object items of this array are also immutable.
|
|
425
|
+
value.forEach((item, index) => { if (util.isObject(item) || Array.isArray(item)) util.makeImmutable(item) })
|
|
426
|
+
|
|
559
427
|
Object.defineProperty(object, propertyName, {
|
|
560
428
|
value: Object.freeze(value)
|
|
561
429
|
});
|
|
@@ -566,6 +434,9 @@ util.makeImmutable = function(object, property, value) {
|
|
|
566
434
|
configurable: false
|
|
567
435
|
});
|
|
568
436
|
|
|
437
|
+
// Ensure new properties can not be added.
|
|
438
|
+
Object.preventExtensions(object)
|
|
439
|
+
|
|
569
440
|
// Call recursively if an object.
|
|
570
441
|
if (util.isObject(value)) {
|
|
571
442
|
util.makeImmutable(value);
|
|
@@ -1768,35 +1639,6 @@ util.runStrictnessChecks = function (config) {
|
|
|
1768
1639
|
}
|
|
1769
1640
|
}
|
|
1770
1641
|
|
|
1771
|
-
// Process pre-1.0 utility names
|
|
1772
|
-
var utilWarnings = {};
|
|
1773
|
-
['watch', 'setModuleDefaults', 'makeHidden', 'makeImmutable', 'getConfigSources', '_loadFileConfigs',
|
|
1774
|
-
'_parseFile', '_attachProtoDeep', '_cloneDeep', '_equalsDeep', '_diffDeep', '_extendDeep', '_stripYamlComments',
|
|
1775
|
-
'_stripComments', '_isObject', '_initParam', '_getCmdLineArg'].forEach(function(oldName) {
|
|
1776
|
-
|
|
1777
|
-
// Config.util names don't have underscores
|
|
1778
|
-
var newName = oldName;
|
|
1779
|
-
if (oldName.indexOf('_') === 0) {
|
|
1780
|
-
newName = oldName.substr(1);
|
|
1781
|
-
}
|
|
1782
|
-
|
|
1783
|
-
// Build the wrapper with warning
|
|
1784
|
-
Config.prototype[oldName] = function(){
|
|
1785
|
-
|
|
1786
|
-
// Produce the warning
|
|
1787
|
-
if (!utilWarnings[oldName]) {
|
|
1788
|
-
console.error('WARNING: config.' + oldName + '() is deprecated. Use config.util.' + newName + '() instead.');
|
|
1789
|
-
console.error('WARNING: See https://github.com/lorenwest/node-config/wiki/Future-Compatibility#upcoming-incompatibilities');
|
|
1790
|
-
utilWarnings[oldName] = true;
|
|
1791
|
-
}
|
|
1792
|
-
|
|
1793
|
-
// Forward the call
|
|
1794
|
-
return util[newName].apply(this, arguments);
|
|
1795
|
-
}
|
|
1796
|
-
});
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
1642
|
// Instantiate and export the configuration
|
|
1801
1643
|
var config = module.exports = new Config();
|
|
1802
1644
|
|