diff --git a/lib/config/index.js b/lib/config/index.js index 25f9cccef..cb2e5d6c4 100644 --- a/lib/config/index.js +++ b/lib/config/index.js @@ -81,7 +81,12 @@ function getDefaultConfig() { function requireModule(file) { try { - return require(file); + if(file.indexOf('./') === 0 || file.indexOf('/') !== 0) { + return require(process.cwd() + '/' + file); + } else { + return require(file); + } + } catch (e) { if (e.code === 'MODULE_NOT_FOUND') { throw new GeminiError('Config file does not exist: ' + file); diff --git a/test/functional/config.test.js b/test/functional/config.test.js index 2e3632222..6a77ca060 100644 --- a/test/functional/config.test.js +++ b/test/functional/config.test.js @@ -51,6 +51,16 @@ describe('config', function() { return new Config(configPath('notExists.js')); }, GeminiError); }); + + it('should read relative to current working directory', function() { + assert.deepPropertyVal( + new Config(configPath('validConfig.js').replace(process.cwd() + '/', '')), + 'system.projectRoot', '/it/works'); + + assert.deepPropertyVal( + new Config(configPath('validConfig.js').replace(process.cwd() + '/', './')), + 'system.projectRoot', '/it/works'); + }); }); describe('.json', function() { @@ -64,6 +74,16 @@ describe('config', function() { return new Config(configPath('notExists.json')); }, GeminiError); }); + + it('should read relative to current working directory', function() { + assert.deepPropertyVal( + new Config(configPath('validConfig.json').replace(process.cwd() + '/', '')), + 'system.projectRoot', '/it/works'); + + assert.deepPropertyVal( + new Config(configPath('validConfig.json').replace(process.cwd() + '/', './')), + 'system.projectRoot', '/it/works'); + }); }); }); });