Skip to content

Commit

Permalink
Merge pull request #28 from Munawwar/ignoreMissingFiles
Browse files Browse the repository at this point in the history
Makes load() ignore any missing config files.
  • Loading branch information
kof authored Jan 7, 2017
2 parents 573078a + 4e819fd commit 6e8e069
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
18 changes: 10 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,16 @@ exports.load = function load(path, options) {
if (Array.isArray(path)) {
conf = {};
path.forEach(function(path) {
var data = load(path, options),
filename;

if (options.merge) {
exports.extend(true, conf, data);
} else {
filename = Path.basename(path, options.ext);
conf[filename] = data;
if (fs.existsSync(path)) {
var data = load(path, options),
filename;

if (options.merge) {
exports.extend(true, conf, data);
} else {
filename = Path.basename(path, options.ext);
conf[filename] = data;
}
}
});

Expand Down
10 changes: 10 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ a.deepEqual(cjson.load([fixtures + '/conf1.json', fixtures + '/conf6.json'], tru

a.deepEqual(cjson.load(fixtures), data, 'load all and merge them');

a.deepEqual(
cjson.load([
fixtures + '/conf1.json',
'missing-conf.json',
fixtures + '/conf6.json'
], true),
data2,
'load a missing config file among an array of config files and merge them'
);

a.deepEqual(cjson.load(fixtures, {ext: '.cjson'}), {conf9: {a: 1}}, 'use custom ext');

var str = require('fs').readFileSync(fixtures + '/conf2.json').toString();
Expand Down

0 comments on commit 6e8e069

Please sign in to comment.