config 1.30.0 → 2.0.2

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 CHANGED
@@ -1,3 +1,30 @@
1
+ 2.0.2 / 2018-08-28
2
+ ==================
3
+
4
+ * Added dot notation to setModuleDefaults - bertho-zero
5
+ * Updated copyright year - JemiloII
6
+
7
+ 2.0.1 / 2018-07-26
8
+ ==================
9
+
10
+ * Removed deprecated code - jpwilliams
11
+
12
+ 2.0.0 / 2018-07-26
13
+ ==================
14
+
15
+ Potential for backward incompatibility requiring a major version bump.
16
+
17
+ Safe to upgrade to major version 2 if you're using a recent NodeJS version
18
+ and you're not trying to mutate config arrays.
19
+
20
+ * Added array immutability - jacobemerick
21
+ * Removed Node V.4 support
22
+
23
+ 1.31.0 / 2018-05-22
24
+ ===================
25
+
26
+ * Load new coffeescript module instead of coffee-script - bastbijl
27
+
1
28
  1.30.0 / 2018-02-26
2
29
  ===================
3
30
 
package/README.md CHANGED
@@ -152,18 +152,18 @@ Contributors
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
154
  <td><img src=https://avatars3.githubusercontent.com/u/1443067?v=4><a href="https://github.com/IvanVergiliev">IvanVergiliev</a></td>
155
- </tr><tr><td><img src=https://avatars2.githubusercontent.com/u/1246875?v=4><a href="https://github.com/jaylynch">jaylynch</a></td>
155
+ </tr><tr><td><img src=https://avatars0.githubusercontent.com/u/1736957?v=4><a href="https://github.com/jpwilliams">jpwilliams</a></td>
156
+ <td><img src=https://avatars2.githubusercontent.com/u/1246875?v=4><a href="https://github.com/jaylynch">jaylynch</a></td>
156
157
  <td><img src=https://avatars1.githubusercontent.com/u/145742?v=4><a href="https://github.com/jberrisch">jberrisch</a></td>
157
158
  <td><img src=https://avatars1.githubusercontent.com/u/9355665?v=4><a href="https://github.com/kgoerlitz">kgoerlitz</a></td>
159
+ <td><img src=https://avatars3.githubusercontent.com/u/8650543?v=4><a href="https://github.com/leonardovillela">leonardovillela</a></td>
158
160
  <td><img src=https://avatars3.githubusercontent.com/u/1918551?v=4><a href="https://github.com/nitzan-shaked">nitzan-shaked</a></td>
159
- <td><img src=https://avatars3.githubusercontent.com/u/3058150?v=4><a href="https://github.com/robertrossmann">robertrossmann</a></td>
161
+ </tr><tr><td><img src=https://avatars3.githubusercontent.com/u/3058150?v=4><a href="https://github.com/robertrossmann">robertrossmann</a></td>
160
162
  <td><img src=https://avatars2.githubusercontent.com/u/498929?v=4><a href="https://github.com/roncli">roncli</a></td>
161
- </tr><tr><td><img src=https://avatars2.githubusercontent.com/u/1355559?v=4><a href="https://github.com/superoven">superoven</a></td>
163
+ <td><img src=https://avatars2.githubusercontent.com/u/1355559?v=4><a href="https://github.com/superoven">superoven</a></td>
162
164
  <td><img src=https://avatars2.githubusercontent.com/u/54934?v=4><a href="https://github.com/wmertens">wmertens</a></td>
163
165
  <td><img src=https://avatars3.githubusercontent.com/u/2842176?v=4><a href="https://github.com/XadillaX">XadillaX</a></td>
164
- <td><img src=https://avatars1.githubusercontent.com/u/4425455?v=4><a href="https://github.com/ncuillery">ncuillery</a></td>
165
- <td><img src=https://avatars0.githubusercontent.com/u/2015295?v=4><a href="https://github.com/patrickpilch">patrickpilch</a></td>
166
- <td><img src=https://avatars1.githubusercontent.com/u/618330?v=4><a href="https://github.com/adityabansod">adityabansod</a></td>
166
+ <td><img src=https://avatars2.githubusercontent.com/u/527814?v=4><a href="https://github.com/jacobemerick">jacobemerick</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-2015 Loren West
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
@@ -33,7 +33,8 @@ var DEFAULT_CLONE_DEPTH = 20,
33
33
  gitCryptTestRegex = /^.GITCRYPT/; // regular expression to test for gitcrypt files.
34
34
 
35
35
  // Define soft dependencies so transpilers don't include everything
36
- var COFFEE_DEP = "coffee-script",
36
+ var COFFEE_2_DEP = "coffeescript",
37
+ COFFEE_DEP = "coffee-script",
37
38
  ICED_DEP = "iced-coffee-script",
38
39
  JS_YAML_DEP = "js-yaml",
39
40
  YAML_DEP = "yaml",
@@ -229,141 +230,6 @@ Config.prototype.has = function(property) {
229
230
  return (getImpl(t, property) !== undefined);
230
231
  };
231
232
 
232
- /**
233
- * <p>Monitor a javascript property for runtime changes.</p>
234
- *
235
- * <p>
236
- * This method was built for an earlier version of node-config that allowed
237
- * configuration value mutations. Since version 1.0.0, node-config no longer
238
- * allows configuration mutations, and is no longer used in node-config.
239
- * </p>
240
- *
241
- * <p>
242
- * It is deprecated, and will be removed in the next semver incompatible release 2.0.0.
243
- * </p>
244
- *
245
- * @method watch
246
- * @deprecated
247
- * @param object {object} - The object to watch.
248
- * @param property {string} - The property name to watch. Watch all object properties if null.
249
- * @param handler {function(object, propertyName, priorValue, newValue)} - Handler called when a property change is detected.
250
- * The handler is run along with other handlers registered for notification.
251
- * If your handler changes the value of the property, that change is applied after all handlers have finished processing the current change.
252
- * Then all handlers (including this one) will be called again with the newly changed value.
253
- * @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.
254
- * @return object {object} - The original object is returned - for chaining.
255
- */
256
- util.watch = function(object, property, handler, depth) {
257
-
258
- // Initialize
259
- var t = this, o = object;
260
- var allProperties = property ? [property] : Object.keys(o);
261
-
262
- // Deprecation warning
263
- if (!deprecationWarnings.watch) {
264
- console.error('WARNING: config.' + fnName + '() is deprecated, and will not be supported in release 2.0.');
265
- console.error('WARNING: See https://github.com/lorenwest/node-config/wiki/Future-Compatibility#upcoming-incompatibilities');
266
- deprecationWarnings.watch = true;
267
- }
268
-
269
- // Depth detection
270
- depth = (depth === null ? DEFAULT_CLONE_DEPTH : depth);
271
- if (depth < 0) {
272
- return;
273
- }
274
-
275
- // Create hidden properties on the object
276
- if (!o.__watchers)
277
- util.makeHidden(o, '__watchers', {});
278
- if (!o.__propertyValues)
279
- util.makeHidden(o, '__propertyValues', {});
280
-
281
- // Attach watchers to all requested properties
282
- allProperties.forEach(function(prop){
283
-
284
- // Setup the property for watching (first time only)
285
- if (typeof(o.__propertyValues[prop]) === 'undefined') {
286
-
287
- // Don't error re-defining the property if immutable
288
- var descriptor = Object.getOwnPropertyDescriptor(o, prop);
289
- if (descriptor && descriptor.writable === false)
290
- return;
291
-
292
- // Copy the value to the hidden field, and add the property to watchers
293
- o.__propertyValues[prop] = [o[prop]];
294
- o.__watchers[prop] = [];
295
-
296
- // Attach the property watcher
297
- Object.defineProperty(o, prop, {
298
- enumerable : true,
299
-
300
- get : function(){
301
- // If more than 1 item is in the values array,
302
- // then we're currently processing watchers.
303
- if (o.__propertyValues[prop].length === 1)
304
- // Current value
305
- return o.__propertyValues[prop][0];
306
- else
307
- // [0] is prior value, [1] is new value being processed
308
- return o.__propertyValues[prop][1];
309
- },
310
-
311
- set : function(newValue) {
312
-
313
- // Return early if no change
314
- var origValue = o[prop];
315
- if (util.equalsDeep(origValue, newValue))
316
- return;
317
-
318
- // Remember the new value, and return if we're in another setter
319
- o.__propertyValues[prop].push(newValue);
320
- if (o.__propertyValues[prop].length > 2)
321
- return;
322
-
323
- // Call all watchers for each change requested
324
- var numIterations = 0;
325
- while (o.__propertyValues[prop].length > 1) {
326
-
327
- // Detect recursion
328
- if (++numIterations > 20) {
329
- o.__propertyValues[prop] = [origValue];
330
- throw new Error('Recursion detected while setting [' + prop + ']');
331
- }
332
-
333
- // Call each watcher for the current values
334
- var oldValue = o.__propertyValues[prop][0];
335
- newValue = o.__propertyValues[prop][1];
336
- o.__watchers[prop].forEach(function(watcher) {
337
- try {
338
- watcher(o, prop, oldValue, newValue);
339
- } catch (e) {
340
- // Log an error and continue with subsequent watchers
341
- console.error("Exception in object watcher for " + prop, e);
342
- }
343
- });
344
-
345
- // Done processing this value
346
- o.__propertyValues[prop].splice(0,1);
347
- }
348
- }
349
- });
350
-
351
- } // Done setting up the property for watching (first time)
352
-
353
- // Add the watcher to the property
354
- o.__watchers[prop].push(handler);
355
-
356
- // Recurs if this is an object...
357
- if (o[prop] && typeof(o[prop]) === 'object') {
358
- util.watch(o[prop], null, handler, depth - 1);
359
- }
360
-
361
- }); // Done processing each property
362
-
363
- // Return the original object - for chaining
364
- return o;
365
- };
366
-
367
233
  /**
368
234
  * <p>
369
235
  * Set default configurations for a node.js module.
@@ -410,17 +276,18 @@ util.setModuleDefaults = function (moduleName, defaultProperties) {
410
276
  parsed: {}
411
277
  });
412
278
  }
413
- configSources[0].parsed[moduleName] = {};
414
- util.extendDeep(configSources[0].parsed[moduleName], defaultProperties);
279
+ util.setPath(configSources[0].parsed, moduleName.split('.'), {});
280
+ util.extendDeep(getImpl(configSources[0].parsed, moduleName), defaultProperties);
415
281
 
416
282
  // Create a top level config for this module if it doesn't exist
417
- t[moduleName] = t[moduleName] || {};
283
+ util.setPath(t, moduleName.split('.'), getImpl(t, moduleName) || {});
418
284
 
419
285
  // Extend local configurations into the module config
420
- util.extendDeep(moduleConfig, t[moduleName]);
286
+ util.setPath(moduleConfig, moduleName.split('.'), getImpl(moduleConfig, moduleName) || {});
287
+ util.extendDeep(moduleConfig, getImpl(t, moduleName));
421
288
 
422
289
  // Merge the extended configs without replacing the original
423
- util.extendDeep(t[moduleName], moduleConfig);
290
+ util.extendDeep(getImpl(t, moduleName), moduleConfig);
424
291
 
425
292
  // reset the mutability check for "config.get" method.
426
293
  // we are not making t[moduleName] immutable immediately,
@@ -430,7 +297,7 @@ util.setModuleDefaults = function (moduleName, defaultProperties) {
430
297
  }
431
298
 
432
299
  // Attach handlers & watchers onto the module config object
433
- return util.attachProtoDeep(t[moduleName]);
300
+ return util.attachProtoDeep(getImpl(t, moduleName));
434
301
  };
435
302
 
436
303
  /**
@@ -554,6 +421,10 @@ util.makeImmutable = function(object, property, value) {
554
421
  writable: false,
555
422
  configurable: false
556
423
  });
424
+ } else if (Array.isArray(value)) {
425
+ Object.defineProperty(object, propertyName, {
426
+ value: Object.freeze(value)
427
+ });
557
428
  } else {
558
429
  Object.defineProperty(object, propertyName, {
559
430
  value: value,
@@ -661,6 +532,9 @@ util.loadFileConfigs = function(configDir) {
661
532
  // Override, NODE_ENV if NODE_CONFIG_ENV is specified.
662
533
  NODE_ENV = util.initParam('NODE_CONFIG_ENV', NODE_ENV);
663
534
 
535
+ // Split files name, for loading multiple files.
536
+ NODE_ENV = NODE_ENV.split(',');
537
+
664
538
  CONFIG_DIR = configDir || util.initParam('NODE_CONFIG_DIR', Path.join( process.cwd(), 'config') );
665
539
  if (CONFIG_DIR.indexOf('.') === 0) {
666
540
  CONFIG_DIR = Path.join(process.cwd() , CONFIG_DIR);
@@ -691,22 +565,26 @@ util.loadFileConfigs = function(configDir) {
691
565
  env.HOSTNAME = hostName;
692
566
 
693
567
  // Read each file in turn
694
- var baseNames = ['default', NODE_ENV];
568
+ var baseNames = ['default'].concat(NODE_ENV);
695
569
 
696
570
  // #236: Also add full hostname when they are different.
697
571
  if ( hostName ) {
698
572
  var firstDomain = hostName.split('.')[0];
699
573
 
700
- // Backward compatibility
701
- baseNames.push(firstDomain, firstDomain + '-' + NODE_ENV);
574
+ NODE_ENV.forEach(function(env) {
575
+ // Backward compatibility
576
+ baseNames.push(firstDomain, firstDomain + '-' + env);
702
577
 
703
- // Add full hostname when it is not the same
704
- if ( hostName != firstDomain ) {
705
- baseNames.push(hostName, hostName + '-' + NODE_ENV);
706
- }
578
+ // Add full hostname when it is not the same
579
+ if ( hostName != firstDomain ) {
580
+ baseNames.push(hostName, hostName + '-' + env);
581
+ }
582
+ });
707
583
  }
708
584
 
709
- baseNames.push('local', 'local-' + NODE_ENV);
585
+ NODE_ENV.forEach(function(env) {
586
+ baseNames.push('local', 'local-' + env);
587
+ });
710
588
 
711
589
  var extNames = ['js', 'ts', 'json', 'json5', 'hjson', 'toml', 'coffee', 'iced', 'yaml', 'yml', 'cson', 'properties', 'xml'];
712
590
  baseNames.forEach(function(baseName) {
@@ -919,7 +797,14 @@ util.parseFile = function(fullFilename) {
919
797
  // Coffee = require("coffee-script");
920
798
  //}
921
799
 
922
- Coffee = require(COFFEE_DEP);
800
+ try {
801
+ // Try to load coffeescript
802
+ Coffee = require(COFFEE_2_DEP);
803
+ }
804
+ catch (e) {
805
+ // If it doesn't exist, try to load it using the deprecated module name
806
+ Coffee = require(COFFEE_DEP);
807
+ }
923
808
 
924
809
  // coffee-script >= 1.7.0 requires explicit registration for require() to work
925
810
  if (Coffee.register) {
@@ -1711,15 +1596,20 @@ util.runStrictnessChecks = function (config) {
1711
1596
  return Path.basename(src.name);
1712
1597
  });
1713
1598
 
1714
-
1715
- // Throw an exception if there's no explicit config file for NODE_ENV
1716
- var anyFilesMatchEnv = sourceFilenames.some(function (filename) {
1717
- return filename.match(NODE_ENV);
1599
+ NODE_ENV.forEach(function(env) {
1600
+ // Throw an exception if there's no explicit config file for NODE_ENV
1601
+ var anyFilesMatchEnv = sourceFilenames.some(function (filename) {
1602
+ return filename.match(env);
1603
+ });
1604
+ // development is special-cased because it's the default value
1605
+ if (env && (env !== 'development') && !anyFilesMatchEnv) {
1606
+ _warnOrThrow("NODE_ENV value of '"+env+"' did not match any deployment config file names.");
1607
+ }
1608
+ // Throw if NODE_ENV matches' default' or 'local'
1609
+ if ((env === 'default') || (env === 'local')) {
1610
+ _warnOrThrow("NODE_ENV value of '"+env+"' is ambiguous.");
1611
+ }
1718
1612
  });
1719
- // development is special-cased because it's the default value
1720
- if (NODE_ENV && (NODE_ENV !== 'development') && !anyFilesMatchEnv) {
1721
- _warnOrThrow("NODE_ENV value of '"+NODE_ENV+"' did not match any deployment config file names.");
1722
- }
1723
1613
 
1724
1614
  // Throw an exception if there's no explict config file for NODE_APP_INSTANCE
1725
1615
  var anyFilesMatchInstance = sourceFilenames.some(function (filename) {
@@ -1729,11 +1619,6 @@ util.runStrictnessChecks = function (config) {
1729
1619
  _warnOrThrow("NODE_APP_INSTANCE value of '"+APP_INSTANCE+"' did not match any instance config file names.");
1730
1620
  }
1731
1621
 
1732
- // Throw if NODE_ENV matches' default' or 'local'
1733
- if ((NODE_ENV === 'default') || (NODE_ENV === 'local')) {
1734
- _warnOrThrow("NODE_ENV value of '"+NODE_ENV+"' is ambiguous.");
1735
- }
1736
-
1737
1622
  function _warnOrThrow (msg) {
1738
1623
  var beStrict = process.env.NODE_CONFIG_STRICT_MODE;
1739
1624
  var prefix = beStrict ? 'FATAL: ' : 'WARNING: ';
@@ -1749,35 +1634,6 @@ util.runStrictnessChecks = function (config) {
1749
1634
  }
1750
1635
  }
1751
1636
 
1752
- // Process pre-1.0 utility names
1753
- var utilWarnings = {};
1754
- ['watch', 'setModuleDefaults', 'makeHidden', 'makeImmutable', 'getConfigSources', '_loadFileConfigs',
1755
- '_parseFile', '_attachProtoDeep', '_cloneDeep', '_equalsDeep', '_diffDeep', '_extendDeep', '_stripYamlComments',
1756
- '_stripComments', '_isObject', '_initParam', '_getCmdLineArg'].forEach(function(oldName) {
1757
-
1758
- // Config.util names don't have underscores
1759
- var newName = oldName;
1760
- if (oldName.indexOf('_') === 0) {
1761
- newName = oldName.substr(1);
1762
- }
1763
-
1764
- // Build the wrapper with warning
1765
- Config.prototype[oldName] = function(){
1766
-
1767
- // Produce the warning
1768
- if (!utilWarnings[oldName]) {
1769
- console.error('WARNING: config.' + oldName + '() is deprecated. Use config.util.' + newName + '() instead.');
1770
- console.error('WARNING: See https://github.com/lorenwest/node-config/wiki/Future-Compatibility#upcoming-incompatibilities');
1771
- utilWarnings[oldName] = true;
1772
- }
1773
-
1774
- // Forward the call
1775
- return util[newName].apply(this, arguments);
1776
- }
1777
- });
1778
-
1779
-
1780
-
1781
1637
  // Instantiate and export the configuration
1782
1638
  var config = module.exports = new Config();
1783
1639
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "config",
3
- "version": "1.30.0",
3
+ "version": "2.0.2",
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,12 +19,11 @@
19
19
  },
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
- "json5": "0.4.0",
23
- "os-homedir": "1.0.2"
22
+ "json5": "^1.0.1"
24
23
  },
25
24
  "devDependencies": {
26
25
  "@types/node": "^7.0.8",
27
- "coffee-script": ">=1.7.0",
26
+ "coffeescript": "2.2.4",
28
27
  "cson": "^3.0.1",
29
28
  "hjson": "^1.2.0",
30
29
  "js-yaml": "^3.2.2",
@@ -42,7 +41,7 @@
42
41
  "url": "http://github.com/lorenwest/node-config.git"
43
42
  },
44
43
  "engines": {
45
- "node": ">= 4.0.0"
44
+ "node": ">= 6.0.0"
46
45
  },
47
46
  "scripts": {
48
47
  "test": "./node_modules/vows/bin/vows test/*.js --spec"
package/ISSUE_TEMPLATE.md DELETED
@@ -1,24 +0,0 @@
1
- **Note: for support questions, please use [StackOverflow](https://stackoverflow.com/questions/tagged/node-config) and tag your question with `node-config`**. *This repository's issues are reserved for feature requests and bug reports.*
2
-
3
- Before submitting a bug report, please search the issue tracker the wiki first. Many issues have already been discussed.
4
-
5
- The wiki is located at: https://github.com/lorenwest/node-config/wiki
6
-
7
- ### I'm submitting a ...
8
- - [ ] bug report
9
- - [ ] feature request
10
- - [ ] support request or question => Please do not submit support request or questions here, see note at the top of this template.
11
-
12
- ### What is the current behavior?
13
- *If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem*:
14
-
15
- ### What is the expected behavior?
16
-
17
- ### Please tell us about your environment:
18
-
19
- - node-config version: x.x.x
20
- - node-version: x.x.x
21
-
22
- ### Other information
23
-
24
- (e.g. are you using an environment besides Node.js?)