Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ignore ./<path> on cwd #1787

Merged
merged 1 commit into from Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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