gaze
gaze copied to clipboard
Using an absolute path added events do not fire
I can add these tests as a PR if you want. But first I wanted to make sure that my thought process on this was correct. These tests are simply copies of current tests. Or are such patterns not supported?
addedByAbsolutePath: function(test) {
test.expect(1);
gaze(process.cwd() + '/**/*', function(err, watcher) {
setTimeout(function() {
test.ok(false, 'Ended without adding a file.');
watcher.close();
}, 1000);
this.on('added', function(filepath) {
var expected = path.relative(process.cwd(), filepath);
test.equal(path.join('sub', 'tmp.js'), expected);
watcher.close();
});
this.on('changed', function() { test.ok(false, 'changed event should not have emitted.'); });
this.on('deleted', function() { test.ok(false, 'deleted event should not have emitted.'); });
fs.writeFileSync(path.resolve(__dirname, 'fixtures', 'sub', 'tmp.js'), 'var tmp = true;');
watcher.on('end', test.done);
});
},
dontAddUnmatchedFilesByAbsolutePath: function(test) {
// TODO: Code smell
test.expect(2);
gaze(process.cwd() + '/**/*.js', function(err, watcher) {
setTimeout(function() {
test.ok(true, 'Ended without adding a file.');
watcher.close();
}, 1000);
this.on('added', function(filepath) {
test.equal(path.relative(process.cwd(), filepath), path.join('sub', 'tmp.js'));
});
fs.writeFileSync(path.resolve(__dirname, 'fixtures', 'sub', 'tmp'), 'Dont add me!');
fs.writeFileSync(path.resolve(__dirname, 'fixtures', 'sub', 'tmp.js'), 'add me!');
watcher.on('end', test.done);
});
},
process.cwd() + '/**/*'
doesn't work very well as the patterns should have a base on which to operate from. A better strategy is this:
gaze('**/*', { cwd: process.cwd() }, function() {});
// Although process.cwd() is already the default if cwd isnt supplied here
What I'm finding when using gaze
/random/path$./my/program /path/to/some/files/**/*js
will not alert on new files being added however
/path/to/some/files$/random/path/my/program **/*js
will alert on new files being added
N.B. to the left of $
is pwd
, to the right of $
is cmd line.
I see how to execute my program so that it will work given what I want to do, but I don't understand why one will successfully see additions but the other will not. Both successfully see changes and deletes.
Oh, one last thing, my program is effectively calling gaze(process.argv[1])
Oh, and node v0.10.26 and gaze v0.5.1 (sorry, I forgot...)
/random/path$./my/program /path/to/some/files/**/*js
uses absolute paths. The patterns need a base to operate properly.
/path/to/some/files$/random/path/my/program **/*js
uses relative paths. The patterns are operating from the cwd: '/path/to/some/files'
.
I think I understand. How do I pass a base for the pattern to operate properly? Or is cwd
the only way?
cwd
is the only way. Your program can determine what the cwd is though.
For the pattern /path/to/some/files/**/*js
, the cwd could be /path/to/some/
and pattern files/**/*js
. Or it could be /path/to/some/files/
and **/*js
. It's up to your program.
Ok. I see it here. The npm and README documentation needs to be updated. If I get time I'll give you a PR.
But... When I test this I see that
cwd = /path/to/some/
and pattern = files/**/*js
does not fire the add event
but
cwd = /path/to/some/files/
and pattern = **/*.js
does
again, I can work around it but is the expectation that the first one will not fire add events? or do you want a test for that case?
Both should fire added
events. A test showing the unexpected behavior would be great.
+1 also having this issue. It worked in previous versions and is now broken in 0.6
+1 I have the same issue when using paths generated by the temp
package (temporary directories in /var/folders/...
), nothing works for me on any of the aforementioned combinations, been trying stuff for over an hour now
:+1:
This is the code I was using:
gaze = new Gaze absolutePattern
gaze.on "all", (event) ->
# No "added" event is ever triggered.
The absolutePattern
is defined by a third party, so a call to require("path").relative()
is needed.
{ relative } = require "path"
gaze = new Gaze relative process.cwd(), absolutePattern
+1, I tried to replace chokidar because it didn't build on Atom/Electron because fsevents. I just wanted to watch an absolute file name, but that doesn't seem possible. So I tried to break it down and use cwd, but that seems broken on empty folders too. I did an outside test:
https://gist.github.com/hedefalk/adccbaeb10c7285686d19e9263fda6c5
I'm gonna try something else :)