diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ba0d33..41c689b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## v2.16.0 +* Add support for a .js config file (export config with `module.exports`) + ## v2.15.2 * Update several other packages as well diff --git a/src/config.js b/src/config.js index 4d7cd86..54ad5c9 100644 --- a/src/config.js +++ b/src/config.js @@ -9,7 +9,8 @@ const configFiles = [ 'config.json', 'config.json5', 'config.json.json', - 'config.json.txt' + 'config.json.txt', + 'config.js' ]; let foundConfigFile; @@ -28,8 +29,12 @@ if (! foundConfigFile) { // Parse the config using JSON5 try { - const raw = fs.readFileSync(__dirname + '/../' + foundConfigFile); - userConfig = json5.parse(raw); + if (foundConfigFile.endsWith('.js')) { + userConfig = require(`../${foundConfigFile}`); + } else { + const raw = fs.readFileSync(__dirname + '/../' + foundConfigFile); + userConfig = json5.parse(raw); + } } catch (e) { throw new Error(`Error reading config file! The error given was: ${e.message}`); }