Socket
Socket
Sign inDemoInstall

config

Package Overview
Dependencies
Maintainers
0
Versions
118
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

config - npm Package Compare versions

Comparing version 0.2.5 to 0.2.7

config/base.json

60

lib/config.js

@@ -10,2 +10,4 @@ /*******************************************************************************

var ext = require('./extensions');
var File = require('fs');
var Yaml = require('yaml');

@@ -15,2 +17,5 @@ // Saved configurations key=moduleName, value=configObj

// Saved configuration files. key=filename, value=configObj
var savedConfigFiles = {};
/*******************************************************************************

@@ -45,11 +50,52 @@ * config() - Build a module configuration object

if (argName == arg && ++pos < process.argv.length) {
// If the filename starts with "./", then make it relative to
// the process CWD vs. this modules file location
var confFile = process.argv[pos];
if (confFile.indexOf('./') == 0) {
confFile = process.cwd() + confFile.substr(1);
// If the filename is relative, make it relative to the process cwd
var configFile = process.argv[pos];
if (configFile.indexOf('./') == 0 || configFile.indexOf('../') == 0) {
configFile = process.cwd() + '/' + configFile;
}
// This will fail if it can't load the file
_.extendDeep(mixedConfig, require(confFile)[modName]);
// Get the configuration object from the file
var configObject = savedConfigFiles[configFile];
if (!configObject) {
// Determine the file type
var fileParts = configFile.split('.');
lastPart = fileParts[fileParts.length - 1].toLowerCase();
var isYAML = (lastPart == 'yaml');
var isJSON = (lastPart == 'json');
var isJS = (!isYAML && !isJSON);
// Load and parse the file into a javascript object
try {
if (isYAML) {
var text = File.readFileSync(configFile).toString();
// Yaml library doesn't like strings that have newlines but don't end in
// a newline: https://github.com/visionmedia/js-yaml/issues/issue/13
text += '\n';
configObject = Yaml.eval(text);
}
else if (isJSON) {
var text = File.readFileSync(configFile).toString();
configObject = JSON.parse(text);
}
else {
configObject = require(configFile);
}
// Remember the object so the file doesn't have to be parsed
// again for the next module.
savedConfigFiles[configFile] = configObject;
}
catch (e)
{
console.log("\nError parsing config file: " + configFile);
console.log(e.message);
process.exit(1);
}
}
// Mixin the module from the configuration file object
_.extendDeep(mixedConfig, configObject[modName]);
}

@@ -56,0 +102,0 @@ });

9

package.json
{
"name": "config",
"version": "0.2.5",
"version": "0.2.7",
"main": "./lib/config.js",

@@ -10,5 +10,6 @@ "description": "Runtime configuration for node.js deployment",

"dependencies": {
"underscore" : ">=1.1.3",
"vows" : ">=0.5.2",
"eyes" : ">=0.1.6"
"underscore" : "1.1.4",
"vows" : "0.5.3",
"eyes" : "0.1.6",
"yaml" : "0.1.1"
},

@@ -15,0 +16,0 @@ "engines": {"node": ">=0.2.4"},

@@ -65,3 +65,3 @@ /*******************************************************************************

'Alpha configuration was mixed in': function() {
process.argv = ['arg1', '-config', '../config/alpha.js'];
process.argv = ['arg1', '-config', './config/alpha.js'];
var conf = config('Customers', defaultParms);

@@ -76,4 +76,4 @@ var shouldBe = _.extendDeep({}, defaultParms, {

'Multiple configurations can be mixed in': function() {
process.argv = ['-config', '../config/base.js', 'arg1',
'-config', '../config/alpha.js', 'arg2'];
process.argv = ['-config', './config/base.js', 'arg1',
'-config', './config/alpha.js', 'arg2'];
var conf = config('Customers', defaultParms);

@@ -100,3 +100,3 @@ var shouldBe = _.extendDeep({}, defaultParms, {

'Command line configurations override file configurations': function() {
process.argv = ['-config', '../config/base.js', 'arg1',
process.argv = ['-config', './config/base.js', 'arg1',
'-Customers.dbName', 'cmdLineName'];

@@ -112,3 +112,3 @@ var conf = config('Customers', defaultParms);

'Configurations can be programmatically extended': function() {
process.argv = ['arg1', '-config', '../config/production'];
process.argv = ['arg1', '-config', './config/production'];
var conf = config('Customers', defaultParms);

@@ -125,3 +125,3 @@ var shouldBe = _.extendDeep({}, defaultParms, {

'Configurations can be programmatically extended': function() {
process.argv = ['arg1', '-config', '../config/production'];
process.argv = ['arg1', '-config', './config/production'];
var conf = config('Customers', defaultParms);

@@ -172,11 +172,26 @@ var shouldBe = _.extendDeep({}, defaultParms, {

/*
'Configuration can be retrieved later': function() {
assert.deepEqual(config('test'), module.shouldBe);
'JSON configuration files can be loaded': function() {
process.argv = ['-config', './config/base.json', 'arg1',
'-config', './config/alpha.js', 'arg2'];
var conf = config('Customers', defaultParms);
var shouldBe = _.extendDeep({}, defaultParms, {
dbName:'base_customers',
dbHost:"alpha",
dbPort:5999
});
assert.deepEqual(conf, shouldBe);
},
'All configurations can be retrieved': function() {
assert.isObject(config());
'YAML configuration files can be loaded': function() {
process.argv = ['-config', './config/base.yaml', 'arg1',
'-config', './config/alpha.js', 'arg2'];
var conf = config('Customers', defaultParms);
var shouldBe = _.extendDeep({}, defaultParms, {
dbName:'base_customers',
dbHost:"alpha",
dbPort:5999
});
assert.deepEqual(conf, shouldBe);
},
*/
'Resetting command line args': function(orig) {

@@ -183,0 +198,0 @@ process.argv = orig.argv;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc