diff --git a/index.js b/index.js index 6c1caa8..3c8646a 100644 --- a/index.js +++ b/index.js @@ -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; + } } }); diff --git a/test/test.js b/test/test.js index 708a333..ee29192 100644 --- a/test/test.js +++ b/test/test.js @@ -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();