Skip to content

Commit

Permalink
Properly handle case of config files with the same filename in differ…
Browse files Browse the repository at this point in the history
…ent directories.

Refs #3846
  • Loading branch information
sgress454 committed Oct 10, 2016
1 parent ba85568 commit 8e3774b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lib/hooks/moduleloader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ module.exports = function(sails) {
excludeDirs: /(locales|env)$/,
filter : new RegExp('(.+)\\.(' + sails.config.moduleloader.configExt.join('|') + ')$'),
flatten : true,
keepDirectoryPath: true,
identity : false
}, cb);
},
Expand All @@ -272,6 +273,7 @@ module.exports = function(sails) {
filter : new RegExp('(.+)\\.(' + sails.config.moduleloader.configExt.join('|') + ')$'),
optional : true,
flatten : true,
keepDirectoryPath: true,
identity : false
}, cb);
}],
Expand All @@ -287,6 +289,7 @@ module.exports = function(sails) {
filter : new RegExp('^' + env + '\\.(' + sails.config.moduleloader.configExt.join('|') + ')$'),
optional : true,
flatten : true,
keepDirectoryPath: true,
identity : false
}, cb);
}]
Expand Down
10 changes: 7 additions & 3 deletions test/integration/hook.userconfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ describe('hooks :: ', function() {
appHelper.teardown();
async.series([
function(cb) {fs.outputFile(path.resolve(__dirname,'../../testApp/config/abc.js'), 'module.exports = {"foo":"goo"};', cb);},
function(cb) {fs.outputFile(path.resolve(__dirname,'../../testApp/config/foo/bar.js'), 'module.exports = {"foo":"bar", "abc":123};', cb);},
function(cb) {fs.outputFile(path.resolve(__dirname,'../../testApp/config/foo/bar.js'), 'module.exports = {"foo":"bar", "abc":123, "betty": "boop"};', cb);},
function(cb) {fs.outputFile(path.resolve(__dirname,'../../testApp/config/lara/bar.js'), 'module.exports = {"horse":"neigh", "pig": "oink", "betty": "spaghetti"};', cb);},
function(cb) {fs.outputFile(path.resolve(__dirname,'../../testApp/config/env/development.js'), 'module.exports = {"cat":"meow"};', cb);},
function(cb) {fs.outputFile(path.resolve(__dirname,'../../testApp/config/env/development/config.js'), 'module.exports = {"owl":"hoot"};', cb);},
function(cb) {fs.outputFile(path.resolve(__dirname,'../../testApp/config/env/test-development.js'), 'module.exports = {"duck":"quack"};', cb);},
Expand All @@ -44,6 +45,9 @@ describe('hooks :: ', function() {
if (err) { return callback(err); }
assert.equal(sails.config.foo, 'bar');
assert.equal(sails.config.abc, 123);
assert.equal(sails.config.horse, 'neigh');
assert.equal(sails.config.pig, 'oink');
assert.equal(sails.config.betty, 'spaghetti');
assert.equal(typeof(sails.config.bar), 'undefined');
return done();
});
Expand All @@ -61,7 +65,7 @@ describe('hooks :: ', function() {
var sails;
before(function(done) {
sails = Sails();
sails.load({hooks:{grunt:false}, dontFlattenConfig: true}, done);
sails.load({hooks:{grunt:false}}, done);
});

it('should load config from config/env/development.js', function() {
Expand Down Expand Up @@ -91,7 +95,7 @@ describe('hooks :: ', function() {
var sails;
before(function(done) {
sails = Sails();
sails.load({hooks:{grunt:false}, dontFlattenConfig: true, environment: 'test-development'}, done);
sails.load({hooks:{grunt:false}, environment: 'test-development'}, done);
});

it('should load config from config/env/test-development.js', function() {
Expand Down

0 comments on commit 8e3774b

Please sign in to comment.