Skip to content

Commit

Permalink
feat: merge ignore rules with defaults
Browse files Browse the repository at this point in the history
And allow the user to override the defaults from their config
  • Loading branch information
remy committed Sep 12, 2015
1 parent 7250919 commit 15b0b88
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 24 deletions.
19 changes: 19 additions & 0 deletions 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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -119,6 +136,8 @@ function normaliseRules(options, ready) {
options.watch = rules.rules.watch;
options.ignore = rules.rules.ignore;

debug('final rules', options);

ready(options);
}

Expand Down
6 changes: 4 additions & 2 deletions 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');
Expand Down Expand Up @@ -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 = [];

Expand Down
74 changes: 52 additions & 22 deletions 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) {
Expand Down Expand Up @@ -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();
});
Expand Down Expand Up @@ -164,20 +165,49 @@ 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));
assert(cmd === 'node --harmony ./index.js', 'cmd is: ' + cmd);
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();
});
});
});

0 comments on commit 15b0b88

Please sign in to comment.