Skip to content

Commit 03c4ed3

Browse files
authored
fix: ignore ./<path> on cwd (#1787)
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).
1 parent 7e00a30 commit 03c4ed3

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

lib/monitor/match.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ function match(files, monitor, ext) {
157157
if (s.indexOf('!' + cwd) === 0) {
158158
return s;
159159
}
160+
161+
// if it starts with a period, then let's get the relative path
162+
if (s.indexOf('!.') === 0) {
163+
return '!' + path.resolve(cwd, s.substring(1));
164+
}
165+
160166
return '!**' + (prefix !== path.sep ? path.sep : '') + s.slice(1);
161167
}
162168

@@ -195,12 +201,13 @@ function match(files, monitor, ext) {
195201
for (var i = 0; i < rules.length; i++) {
196202
if (rules[i].slice(0, 1) === '!') {
197203
if (!minimatch(file, rules[i], minimatchOpts)) {
204+
debug('ignored', file, 'rule:', rules[i]);
198205
ignored++;
199206
matched = true;
200207
break;
201208
}
202209
} else {
203-
debug('match', file, minimatch(file, rules[i], minimatchOpts));
210+
debug('matched', file, 'rule:', rules[i]);
204211
if (minimatch(file, rules[i], minimatchOpts)) {
205212
watched++;
206213

test/monitor/match.test.js

+44
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,50 @@ describe('match', function() {
2222
'!*.coffee',
2323
];
2424

25+
it('should resolve ./ in positive match', () => {
26+
const cwd = process.cwd();
27+
const res = match(
28+
[cwd + '/app.nodemon'],
29+
[
30+
'./*.nodemon',
31+
'!**/dir/*.nodemon',
32+
],
33+
'js,mjs,json,nodemon'
34+
);
35+
36+
assert.equal(res.result.length, 1, JSON.stringify(res));
37+
});
38+
39+
it('should resolve ./ in positive match (miss test)', () => {
40+
const cwd = process.cwd();
41+
const res = match(
42+
[cwd + '/dir/app.nodemon'],
43+
[
44+
'./*.nodemon',
45+
'!**/dir/*.nodemon',
46+
],
47+
'js,mjs,json,nodemon'
48+
);
49+
50+
assert.equal(res.result.length, 0, JSON.stringify(res));
51+
assert.equal(res.ignored, 1, JSON.stringify(res));
52+
});
53+
54+
it('should resolve ./ in negative match (hit test)', () => {
55+
const cwd = process.cwd();
56+
const res = match(
57+
[cwd + '/app.nodemon'],
58+
[
59+
'!./*.nodemon',
60+
'**/dir/*.nodemon',
61+
],
62+
'js,mjs,json,nodemon'
63+
);
64+
65+
assert.equal(res.result.length, 0, JSON.stringify(res));
66+
assert.equal(res.ignored, 1, JSON.stringify(res));
67+
});
68+
2569
it('should handle lots of **s!', () => {
2670
const res = match(
2771
['test/fixtures/app.js'],

0 commit comments

Comments
 (0)