Skip to content

Commit

Permalink
fix: clarify which config files are actually used
Browse files Browse the repository at this point in the history
Fixes #1204
  • Loading branch information
remy committed Jan 3, 2018
1 parent 17d4b53 commit c3ac4c8
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/config/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ function load(settings, options, config, callback) {
// if we didn't pick up a nodemon.json file & there's no cli ignores
// then try loading an old style .nodemonignore file
if (config.loaded.length === 0) {
// TODO decide whether this is just confusing...
var legacy = loadLegacyIgnore.bind(null, options, ready);
var legacy = loadLegacyIgnore.bind(null, options, config, ready);

// first try .nodemonignore, if that doesn't exist, try nodemon-ignore
return legacy('.nodemonignore', function () {
Expand All @@ -118,11 +117,12 @@ function load(settings, options, config, callback) {
* @param {String} filename ignore file (.nodemonignore or nodemon-ignore)
* @param {Function} fail (optional) failure callback
*/
function loadLegacyIgnore(options, success, filename, fail) {
function loadLegacyIgnore(options, config, success, filename, fail) {
var ignoreFile = path.join(process.cwd(), filename);

exists(ignoreFile, function (exists) {
if (exists) {
config.loaded.push(ignoreFile);
return parse(ignoreFile, function (error, rules) {
options.ignore = rules.raw;
success(options);
Expand Down Expand Up @@ -172,6 +172,12 @@ function loadFile(options, config, dir, ready) {
}

var filename = options.configFile || path.join(dir, 'nodemon.json');

if (config.loaded.indexOf(filename) !== -1) {
// don't bother re-parsing the same config file
return callback({});
}

fs.readFile(filename, 'utf8', function (err, data) {
if (err) {
if (err.code === 'ENOENT') {
Expand All @@ -188,7 +194,9 @@ function loadFile(options, config, dir, ready) {

try {
settings = JSON.parse(data.toString('utf8').replace(/^\uFEFF/, ''));
config.loaded.push(filename);
if (!filename.endsWith('package.json') || settings.nodemonConfig) {
config.loaded.push(filename);
}
} catch (e) {
console.error(e);
utils.log.fail('Failed to parse config ' + filename);
Expand Down

0 comments on commit c3ac4c8

Please sign in to comment.