From 2582d960be9ac914653c38606669f3d4d74c102b Mon Sep 17 00:00:00 2001 From: Remy Sharp Date: Wed, 3 Jan 2018 17:09:57 +0000 Subject: [PATCH] fix: clarify which config files are actually used Fixes #1204 --- lib/config/load.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/config/load.js b/lib/config/load.js index d950bb7a..b3a88be9 100644 --- a/lib/config/load.js +++ b/lib/config/load.js @@ -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 () { @@ -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); @@ -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') { @@ -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);