Skip to content

Commit 8cb5150

Browse files
authored
Merge pull request #92 from pelias/path.resolve
fix(PELIAS_CONFIG): properly suport relative paths
2 parents 652de2d + 353fbbd commit 8cb5150

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function getConfig(deep) {
4141
// load config from ENV
4242
let custom_config;
4343
if( process.env.hasOwnProperty('PELIAS_CONFIG') ){
44-
custom_config = require( process.env.PELIAS_CONFIG );
44+
custom_config = require( path.resolve(process.env.PELIAS_CONFIG) );
4545
} else if ( fs.existsSync (localpath) ) {
4646
custom_config = require( localpath );
4747
}

test/generate.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,19 @@ module.exports.generate.paths = function(test) {
185185
delete process.env.PELIAS_CONFIG;
186186
});
187187

188+
test('relative paths supported from any location', function (t) {
189+
process.chdir('./config');
190+
// set the relative PELIAS_CONFIG env var
191+
process.env.PELIAS_CONFIG = './env.json';
192+
193+
var c = config.generate();
194+
t.deepEqual(c, expected, 'loaded relative file path');
195+
t.end();
196+
197+
// unset the PELIAS_CONFIG env var
198+
delete process.env.PELIAS_CONFIG;
199+
});
200+
188201
test('invalid paths in ENV var throws exception', function (t) {
189202

190203
// set the relative PELIAS_CONFIG env var

0 commit comments

Comments
 (0)