Skip to content

Commit

Permalink
Fix windows ignore when using anymatch@2
Browse files Browse the repository at this point in the history
Fixes #668

Chokidar@2 includes anymatch@2 which has a (potentially) breaking change
as described in the changelog: https://github.com/micromatch/anymatch#change-log

When the `cwd` is set Chokidar will join the ignore pattern to the cwd,
and if this isn't absolute, it causes `anymatch` to fail:

```js
// where cwd = c:\Users\remy\
anymatch('C:\\Users\\remy\\**\\node_modules\\**',
'C:\\Users\\remy\\node_modules\\project'); // === false
```

https://runkit.com/embed/rn05fobk294p

So this change adds the upath module (used by Chokidar during testing
and about 35K footprint) to normalize the path to bash-like slashes
which corrects the issue.
  • Loading branch information
remy committed Jan 12, 2018
1 parent 3409db8 commit 966c300
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions index.js
Expand Up @@ -9,7 +9,8 @@ var isGlob = require('is-glob');
var isAbsolute = require('path-is-absolute');
var inherits = require('inherits');
var braces = require('braces');
var normalizePath = require('normalize-path')
var normalizePath = require('normalize-path');
var upath = require('upath');

var NodeFsHandler = require('./lib/nodefs-handler');
var FsEventsHandler = require('./lib/fsevents-handler');
Expand Down Expand Up @@ -357,7 +358,7 @@ FSWatcher.prototype._isIgnored = function(path, stats) {
if (cwd && ignored) {
ignored = ignored.map(function (path) {
if (typeof path !== 'string') return path;
return isAbsolute(path) ? path : sysPath.join(cwd, path);
return upath.normalize(isAbsolute(path) ? path : sysPath.join(cwd, path));
});
}
var paths = arrify(ignored)
Expand Down
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -38,8 +38,7 @@
"mocha": "^3.0.0",
"rimraf": "^2.4.3",
"sinon": "^1.10.3",
"sinon-chai": "^2.6.0",
"upath": "1.0.0"
"sinon-chai": "^2.6.0"
},
"optionalDependencies": {
"fsevents": "^1.0.0"
Expand All @@ -54,6 +53,7 @@
"is-glob": "^4.0.0",
"normalize-path": "^2.1.1",
"path-is-absolute": "^1.0.0",
"readdirp": "^2.0.0"
"readdirp": "^2.0.0",
"upath": "1.0.0"
}
}

0 comments on commit 966c300

Please sign in to comment.