Skip to content

Commit

Permalink
fix(PELIAS_CONFIG): properly suport relative paths
Browse files Browse the repository at this point in the history
Usage of `path.resolve` was removed in #89.

Without `path.resolve`, relative paths are evaluated as relative to the
location of the `pelias-config` module, not the current working
directory, as is likely intended.
  • Loading branch information
orangejulius committed Jun 5, 2018
1 parent 652de2d commit 353fbbd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function getConfig(deep) {
// load config from ENV
let custom_config;
if( process.env.hasOwnProperty('PELIAS_CONFIG') ){
custom_config = require( process.env.PELIAS_CONFIG );
custom_config = require( path.resolve(process.env.PELIAS_CONFIG) );
} else if ( fs.existsSync (localpath) ) {
custom_config = require( localpath );
}
Expand Down
13 changes: 13 additions & 0 deletions test/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,19 @@ module.exports.generate.paths = function(test) {
delete process.env.PELIAS_CONFIG;
});

test('relative paths supported from any location', function (t) {
process.chdir('./config');
// set the relative PELIAS_CONFIG env var
process.env.PELIAS_CONFIG = './env.json';

var c = config.generate();
t.deepEqual(c, expected, 'loaded relative file path');
t.end();

// unset the PELIAS_CONFIG env var
delete process.env.PELIAS_CONFIG;
});

test('invalid paths in ENV var throws exception', function (t) {

// set the relative PELIAS_CONFIG env var
Expand Down

0 comments on commit 353fbbd

Please sign in to comment.