gaze icon indicating copy to clipboard operation
gaze copied to clipboard

Using an absolute path added events do not fire

Open seebees opened this issue 10 years ago • 11 comments

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);
    });
  },

seebees avatar Mar 21 '14 18:03 seebees

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

shama avatar Mar 21 '14 18:03 shama

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...)

seebees avatar Mar 21 '14 19:03 seebees

/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'.

shama avatar Mar 21 '14 19:03 shama

I think I understand. How do I pass a base for the pattern to operate properly? Or is cwd the only way?

seebees avatar Mar 21 '14 21:03 seebees

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.

shama avatar Mar 21 '14 21:03 shama

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?

seebees avatar Mar 21 '14 21:03 seebees

Both should fire added events. A test showing the unexpected behavior would be great.

shama avatar Mar 21 '14 22:03 shama

+1 also having this issue. It worked in previous versions and is now broken in 0.6

yocontra avatar Apr 13 '14 19:04 yocontra

+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

thanpolas avatar Nov 18 '14 11:11 thanpolas

:+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

aleclarson avatar Jul 17 '15 00:07 aleclarson

+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 :)

hedefalk avatar Mar 31 '16 08:03 hedefalk