diff --git a/lib/config/load.js b/lib/config/load.js index 15b11226..053ccc6a 100644 --- a/lib/config/load.js +++ b/lib/config/load.js @@ -1,3 +1,4 @@ +var debug = require('debug')('nodemon'); var fs = require('fs'); var path = require('path'); var exists = fs.exists || path.exists; @@ -28,6 +29,22 @@ function load(settings, options, config, callback) { // and thus command line arguments get priority options = utils.merge(settings, options); + // legacy support + if (!Array.isArray(options.ignore)) { + options.ignore = [options.ignore]; + } + + // blend the user ignore and the default ignore together + if (options.ignoreRoot && options.ignore) { + if (!Array.isArray(options.ignoreRoot)) { + options.ignoreRoot = [options.ignoreRoot]; + } + options.ignore = options.ignoreRoot.concat(options.ignore); + } else { + options.ignore = defaults.ignore.concat(options.ignore); + } + + // add in any missing defaults options = utils.merge(options, defaults); @@ -119,6 +136,8 @@ function normaliseRules(options, ready) { options.watch = rules.rules.watch; options.ignore = rules.rules.ignore; + debug('final rules', options); + ready(options); } diff --git a/lib/monitor/watch.js b/lib/monitor/watch.js index b962fc94..4699cd09 100644 --- a/lib/monitor/watch.js +++ b/lib/monitor/watch.js @@ -1,6 +1,7 @@ module.exports = watch; -var debug = require('debug')('nodemon'); +var debug = require('debug')('nodemon:watch'); +var debugRoot = require('debug')('nodemon'); var Promise = require('es6-promise').Promise; // jshint ignore:line var chokidar = require('chokidar'); var undefsafe = require('undefsafe'); @@ -28,7 +29,8 @@ function watch() { var dirs = [].slice.call(config.dirs); - debug('start watch on: %s', dirs.join(', ')); + debugRoot('start watch on: %s', dirs.join(', ')); + debugRoot('ignore dirs regex(%s)', config.options.ignore.re); var promises = []; diff --git a/test/config/load.test.js b/test/config/load.test.js index 366dc97c..25c85c77 100644 --- a/test/config/load.test.js +++ b/test/config/load.test.js @@ -1,18 +1,19 @@ 'use strict'; -/*global describe:true, it: true, afterEach: true, beforeEach: true, after:true */ -var load = require('../../lib/config/load'), - cli = require('../../lib/cli/'), - path = require('path'), - testUtils = require('../utils'), - utils = require('../../lib/utils'), - rules = require('../../lib/rules'), - exec = require('../../lib/config/exec'), - nodemon = require('../../lib/nodemon'), - command = require('../../lib/config/command'), - assert = require('assert'); +/*global describe, it, afterEach, beforeEach, after */ +var load = require('../../lib/config/load'); +var defaults = require('../../lib/config/defaults'); +var cli = require('../../lib/cli/'); +var path = require('path'); +var testUtils = require('../utils'); +var utils = require('../../lib/utils'); +var rules = require('../../lib/rules'); +var exec = require('../../lib/config/exec'); +var nodemon = require('../../lib/nodemon'); +var command = require('../../lib/config/command'); +var assert = require('assert'); function asCLI(cmd) { - return ('node nodemon ' + (cmd|| '')).trim(); + return ('node nodemon ' + (cmd || '')).trim(); } function commandToString(command) { @@ -125,7 +126,7 @@ describe('config load', function () { options = {}; load(settings, options, config, function (config) { removeRegExp(config); - assert.deepEqual(config.ignore, ['one'], 'ignore is "one": ' + config.ignore); + assert(config.ignore.indexOf('one') !== -1, '"one" is ignored: ' + config.ignore); assert.deepEqual(config.watch, ['one'], 'watch is "one": ' + config.watch); done(); }); @@ -164,15 +165,16 @@ describe('config load', function () { process.chdir(path.resolve(pwd, 'test/fixtures/legacy')); utils.home = path.resolve(pwd, 'test/fixtures/legacy'); - var settings = { 'script': './index.js', - 'verbose': true, - 'ignore': ['*/artic/templates/*' ], - 'ext' : 'js coffee json', - 'watch': [ '*.coffee' ], - 'execMap': {'js': 'node --harmony', 'coffee': 'node --harmony', } - }, - config = {}, - options = {}; + var settings = { + script: './index.js', + verbose: true, + ignore: ['*/artic/templates/*' ], + ext: 'js coffee json', + watch: [ '*.coffee' ], + execMap: {js: 'node --harmony', coffee: 'node --harmony', }, + }; + var config = {}; + var options = {}; load(settings, options, config, function (config) { var cmd = commandToString(command(config)); @@ -180,4 +182,32 @@ describe('config load', function () { done(); }); }); + + it('should merge ignore rules', function (done) { + load({ + ignore: ['*/artic/templates/*', 'views/*' ], + }, {}, {}, function (config) { + assert.equal(config.ignore.length, defaults.ignore.length + 2); + done(); + }); + }); + + it('should merge ignore rules even when strings', function (done) { + load({ + ignore: 'public', + }, {}, {}, function (config) { + assert.equal(config.ignore.length, defaults.ignore.length + 1); + done(); + }); + }); + + it('should allow user to override root ignore rules', function (done) { + load({ + ignore: 'public', + ignoreRoot: [], + }, {}, {}, function (config) { + assert.equal(config.ignore.length, 1); + done(); + }); + }); }); \ No newline at end of file