Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

Commit bc76bee

Browse files
committed
Always resolve globs, fixes opts.cwd
1 parent 6cc9d40 commit bc76bee

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

index.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,22 @@ module.exports = function (globs, opts, cb) {
3838
opts = opts || {};
3939
cb = cb || function () {};
4040

41+
function resolveFilepath(filepath) {
42+
if (pathIsAbsolute(filepath)) {
43+
return filepath;
44+
}
45+
return path.resolve(opts.cwd || process.cwd(), filepath);
46+
}
47+
4148
function resolveGlob(glob) {
4249
var mod = '';
43-
var resolveFn = path.resolve;
4450

4551
if (glob[0] === '!') {
4652
mod = glob[0];
4753
glob = glob.slice(1);
4854
}
4955

50-
if (opts.cwd) {
51-
resolveFn = path.normalize;
52-
}
53-
54-
return mod + resolveFn(glob);
56+
return mod + resolveFilepath(glob);
5557
}
5658
globs = globs.map(resolveGlob);
5759

@@ -98,9 +100,7 @@ module.exports = function (globs, opts, cb) {
98100
};
99101

100102
function processEvent(event, filepath) {
101-
if (!pathIsAbsolute(filepath)) {
102-
filepath = path.resolve(opts.cwd || process.cwd(), filepath);
103-
}
103+
filepath = resolveFilepath(filepath);
104104

105105
var glob;
106106
var currentFilepath = filepath;

test/test-cwd.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('cwd', function () {
2121

2222
it('should respect opts.cwd', function (done) {
2323
w = watch('index.js', {cwd: fixtures('')}, function (file) {
24-
file.relative.should.eql(path.normalize('test/fixtures/index.js'));
24+
file.relative.should.eql(path.normalize('index.js'));
2525
done();
2626
}).on('ready', touch(fixtures('index.js')));
2727
});

0 commit comments

Comments
 (0)