Skip to content

Commit

Permalink
fix: ignore ./<path> on cwd (#1787)
Browse files Browse the repository at this point in the history
Fixes: #1784

This fixes the watch/ignore rules where the config is ignoring
the relative local path of ./ - this fix was in place for the
positive (watch) test but not patched for the negative (ignore).
  • Loading branch information
remy committed Oct 19, 2020
1 parent 7e00a30 commit 03c4ed3
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/monitor/match.js
Expand Up @@ -157,6 +157,12 @@ function match(files, monitor, ext) {
if (s.indexOf('!' + cwd) === 0) {
return s;
}

// if it starts with a period, then let's get the relative path
if (s.indexOf('!.') === 0) {
return '!' + path.resolve(cwd, s.substring(1));
}

return '!**' + (prefix !== path.sep ? path.sep : '') + s.slice(1);
}

Expand Down Expand Up @@ -195,12 +201,13 @@ function match(files, monitor, ext) {
for (var i = 0; i < rules.length; i++) {
if (rules[i].slice(0, 1) === '!') {
if (!minimatch(file, rules[i], minimatchOpts)) {
debug('ignored', file, 'rule:', rules[i]);
ignored++;
matched = true;
break;
}
} else {
debug('match', file, minimatch(file, rules[i], minimatchOpts));
debug('matched', file, 'rule:', rules[i]);
if (minimatch(file, rules[i], minimatchOpts)) {
watched++;

Expand Down
44 changes: 44 additions & 0 deletions test/monitor/match.test.js
Expand Up @@ -22,6 +22,50 @@ describe('match', function() {
'!*.coffee',
];

it('should resolve ./ in positive match', () => {
const cwd = process.cwd();
const res = match(
[cwd + '/app.nodemon'],
[
'./*.nodemon',
'!**/dir/*.nodemon',
],
'js,mjs,json,nodemon'
);

assert.equal(res.result.length, 1, JSON.stringify(res));
});

it('should resolve ./ in positive match (miss test)', () => {
const cwd = process.cwd();
const res = match(
[cwd + '/dir/app.nodemon'],
[
'./*.nodemon',
'!**/dir/*.nodemon',
],
'js,mjs,json,nodemon'
);

assert.equal(res.result.length, 0, JSON.stringify(res));
assert.equal(res.ignored, 1, JSON.stringify(res));
});

it('should resolve ./ in negative match (hit test)', () => {
const cwd = process.cwd();
const res = match(
[cwd + '/app.nodemon'],
[
'!./*.nodemon',
'**/dir/*.nodemon',
],
'js,mjs,json,nodemon'
);

assert.equal(res.result.length, 0, JSON.stringify(res));
assert.equal(res.ignored, 1, JSON.stringify(res));
});

it('should handle lots of **s!', () => {
const res = match(
['test/fixtures/app.js'],
Expand Down

0 comments on commit 03c4ed3

Please sign in to comment.