Skip to content

Commit 15b0b88

Browse files
committed
feat: merge ignore rules with defaults
And allow the user to override the defaults from their config
1 parent 7250919 commit 15b0b88

File tree

3 files changed

+75
-24
lines changed

3 files changed

+75
-24
lines changed

lib/config/load.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var debug = require('debug')('nodemon');
12
var fs = require('fs');
23
var path = require('path');
34
var exists = fs.exists || path.exists;
@@ -28,6 +29,22 @@ function load(settings, options, config, callback) {
2829
// and thus command line arguments get priority
2930
options = utils.merge(settings, options);
3031

32+
// legacy support
33+
if (!Array.isArray(options.ignore)) {
34+
options.ignore = [options.ignore];
35+
}
36+
37+
// blend the user ignore and the default ignore together
38+
if (options.ignoreRoot && options.ignore) {
39+
if (!Array.isArray(options.ignoreRoot)) {
40+
options.ignoreRoot = [options.ignoreRoot];
41+
}
42+
options.ignore = options.ignoreRoot.concat(options.ignore);
43+
} else {
44+
options.ignore = defaults.ignore.concat(options.ignore);
45+
}
46+
47+
3148
// add in any missing defaults
3249
options = utils.merge(options, defaults);
3350

@@ -119,6 +136,8 @@ function normaliseRules(options, ready) {
119136
options.watch = rules.rules.watch;
120137
options.ignore = rules.rules.ignore;
121138

139+
debug('final rules', options);
140+
122141
ready(options);
123142
}
124143

lib/monitor/watch.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module.exports = watch;
22

3-
var debug = require('debug')('nodemon');
3+
var debug = require('debug')('nodemon:watch');
4+
var debugRoot = require('debug')('nodemon');
45
var Promise = require('es6-promise').Promise; // jshint ignore:line
56
var chokidar = require('chokidar');
67
var undefsafe = require('undefsafe');
@@ -28,7 +29,8 @@ function watch() {
2829

2930
var dirs = [].slice.call(config.dirs);
3031

31-
debug('start watch on: %s', dirs.join(', '));
32+
debugRoot('start watch on: %s', dirs.join(', '));
33+
debugRoot('ignore dirs regex(%s)', config.options.ignore.re);
3234

3335
var promises = [];
3436

test/config/load.test.js

Lines changed: 52 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
'use strict';
2-
/*global describe:true, it: true, afterEach: true, beforeEach: true, after:true */
3-
var load = require('../../lib/config/load'),
4-
cli = require('../../lib/cli/'),
5-
path = require('path'),
6-
testUtils = require('../utils'),
7-
utils = require('../../lib/utils'),
8-
rules = require('../../lib/rules'),
9-
exec = require('../../lib/config/exec'),
10-
nodemon = require('../../lib/nodemon'),
11-
command = require('../../lib/config/command'),
12-
assert = require('assert');
2+
/*global describe, it, afterEach, beforeEach, after */
3+
var load = require('../../lib/config/load');
4+
var defaults = require('../../lib/config/defaults');
5+
var cli = require('../../lib/cli/');
6+
var path = require('path');
7+
var testUtils = require('../utils');
8+
var utils = require('../../lib/utils');
9+
var rules = require('../../lib/rules');
10+
var exec = require('../../lib/config/exec');
11+
var nodemon = require('../../lib/nodemon');
12+
var command = require('../../lib/config/command');
13+
var assert = require('assert');
1314

1415
function asCLI(cmd) {
15-
return ('node nodemon ' + (cmd|| '')).trim();
16+
return ('node nodemon ' + (cmd || '')).trim();
1617
}
1718

1819
function commandToString(command) {
@@ -125,7 +126,7 @@ describe('config load', function () {
125126
options = {};
126127
load(settings, options, config, function (config) {
127128
removeRegExp(config);
128-
assert.deepEqual(config.ignore, ['one'], 'ignore is "one": ' + config.ignore);
129+
assert(config.ignore.indexOf('one') !== -1, '"one" is ignored: ' + config.ignore);
129130
assert.deepEqual(config.watch, ['one'], 'watch is "one": ' + config.watch);
130131
done();
131132
});
@@ -164,20 +165,49 @@ describe('config load', function () {
164165
process.chdir(path.resolve(pwd, 'test/fixtures/legacy'));
165166
utils.home = path.resolve(pwd, 'test/fixtures/legacy');
166167

167-
var settings = { 'script': './index.js',
168-
'verbose': true,
169-
'ignore': ['*/artic/templates/*' ],
170-
'ext' : 'js coffee json',
171-
'watch': [ '*.coffee' ],
172-
'execMap': {'js': 'node --harmony', 'coffee': 'node --harmony', }
173-
},
174-
config = {},
175-
options = {};
168+
var settings = {
169+
script: './index.js',
170+
verbose: true,
171+
ignore: ['*/artic/templates/*' ],
172+
ext: 'js coffee json',
173+
watch: [ '*.coffee' ],
174+
execMap: {js: 'node --harmony', coffee: 'node --harmony', },
175+
};
176+
var config = {};
177+
var options = {};
176178

177179
load(settings, options, config, function (config) {
178180
var cmd = commandToString(command(config));
179181
assert(cmd === 'node --harmony ./index.js', 'cmd is: ' + cmd);
180182
done();
181183
});
182184
});
185+
186+
it('should merge ignore rules', function (done) {
187+
load({
188+
ignore: ['*/artic/templates/*', 'views/*' ],
189+
}, {}, {}, function (config) {
190+
assert.equal(config.ignore.length, defaults.ignore.length + 2);
191+
done();
192+
});
193+
});
194+
195+
it('should merge ignore rules even when strings', function (done) {
196+
load({
197+
ignore: 'public',
198+
}, {}, {}, function (config) {
199+
assert.equal(config.ignore.length, defaults.ignore.length + 1);
200+
done();
201+
});
202+
});
203+
204+
it('should allow user to override root ignore rules', function (done) {
205+
load({
206+
ignore: 'public',
207+
ignoreRoot: [],
208+
}, {}, {}, function (config) {
209+
assert.equal(config.ignore.length, 1);
210+
done();
211+
});
212+
});
183213
});

0 commit comments

Comments
 (0)