rhysd / Shiba

Rich markdown live preview app with linter
772 stars 57 forks source link

Shiba cannot see changes inside hidden folders #10

Closed ghost closed 9 years ago

ghost commented 9 years ago

Given a Markdown document inside a .folder Shiba cannot see any changes occuring to the document. Only on manual refresh can Shiba see the changes.

For example: writing a temporary Markdown document to ~/.cache/AppName/output.md this file can be opened and manually refreshed inside Shiba but no changes made to that file will be automatically loaded by Shiba's watcher.

However, change that path to a non-hidden/non-dot folder ~/cache/AppName/output.md and Shiba works beautifully, as normal.

Thanks!!

ghost commented 9 years ago

Ok this is because Shiba tells chokidar to ignore dotfiles on watcher.ts#L70

It would be cool to be able to toggle this in config.yml so users could set whether or not to watch dotfiles.

Thanks!!

rhysd commented 9 years ago

Yeah, I added 'ignore_file_pattern' config to config.yml.

3896b3835396379be64a9a623fbeb750c45ec428

We can't know which file users want to ignore. (They also may want to ignore node_modules) It should be controlled by users.

rhysd commented 9 years ago

I renamed it to 'ignore_path_pattern' because it matches to path (including directory), not file.

ghost commented 9 years ago

Wow this is great, thanks so much!! :tropical_drink:

ghost commented 9 years ago

After testing, this is not working. I tried the following lines in my config.yml file and none worked:

ignore_path_pattern: '.git'
ignore_path_pattern: '/\.git/'
ignore_path_pattern: '[/\.git/]'

Am I entering the regex incorrectly? (I'm guessing so. I'm terrible with regex)

rhysd commented 9 years ago

ignore_path_pattern: '/\.git/'

Sorry for confusing. It is a bit complicated. The string is passed to JavaScript's RegExp's constructor. So, I think '/\\.git/' is correct. I don't know spec of YAML so much...

Also, note that if I use double quotes instead of single quotes, Shiba tells me on commandline: No configuration file is found

Let me confirm a point. You mean that above 'No configuration file is found' error does not occur when using single quotes? Please be sure to put config.yml in ~/.config/Shiba (I think already Shiba directory is created).

ghost commented 9 years ago

You mean that above 'No configuration file is found' error does not occur when using single quotes?

Please ignore that. I made a mistake with regex which was causing the parser to consider the surrounding quotes as part of the regex, this was obviously problematic and caused the config file to fail loading.

ghost commented 9 years ago

Testing with: ignore_path_pattern: '/\\.git/' does not work. :cry:

rhysd commented 9 years ago

OK, I'll check it!

ghost commented 9 years ago

Shouldn't you pass the string directly to chokidar instead of creating a new RegExp object? (pardon my poor knowledge of javascript)

rhysd commented 9 years ago

When the value of ignored is string, chokidar seems to assume it as the path (See here). So I think we must make an instance of RegExp.

rhysd commented 9 years ago

In my environment, below configuration works. (README.md is watched, .foo.md is watched and .git/foo.md is not watched)

ignore_path_pattern: "/\\.git/"

Could you be sure that Shiba's version is v0.4.4?

ghost commented 9 years ago

Oooops. I am on 0.4.2. That's odd, because I updated Shiba right after I saw you create tag v0.4.4 however I wonder if npmjs.org is not serving 0.4.4?? Yep, just checked and it's on 0.4.2. npm is being lazy today. :zzz:

ghost commented 9 years ago

Hmm, travis builds have been erroring for a while now? https://travis-ci.org/rhysd/Shiba/builds

... probably not related.

rhysd commented 9 years ago

Ah, that's right. But I have received an error as below on npm publish. npm package already should be updated to 0.4.4...

npm ERR! publish Failed PUT 403
npm ERR! Darwin 13.4.0
npm ERR! argv "node" "/usr/local/bin/npm" "publish"
npm ERR! node v0.12.4
npm ERR! npm  v2.10.1
npm ERR! code E403

npm ERR! "You cannot publish over the previously published version 0.4.4." : shiba
npm ERR! 
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/rhayasd/Dev/github.com/rhysd/Shiba/npm-publish/npm-debug.log

Hmm, travis builds have been erroring for a while now?

I think it's not related to this issue. It failed to open window in Travis environment.

Anyway, I think we should wait a little. Thank you for your cooperation!

ghost commented 9 years ago

Ah ok. I will try some patience! :hourglass: Thanks for your help.

ghost commented 9 years ago

aaaand now it's 0.4.4. I'll update and test again.

ghost commented 9 years ago

Ok! 0.4.4 respects my setting of ignore_path_pattern: "/\\.git/" however I noted these 2 problems when Shiba watches a dot-folder, or any child of a dot-folder:

  1. Shiba stops showing updates to watched document after 2nd or 3rd document change, Watcher cannot see the changes after that point.
  2. Shiba cannot see changes to files in same directory, Watcher cannot see file adds or any changes in other files.

So for now, for my app I've moved my output to /tmp/AppName/output1.md, /tmp/AppName/output2.md, /tmp/AppName/output3.md, etc. and Shiba has no trouble with watching all the documents in /tmp/AppName and seeing the changes as they are made... it works great!! :smiley:

rhysd commented 9 years ago

Sorry for late response. I'll check it.

rhysd commented 9 years ago

I tried.

current dir --- .foo
                  |
                  |- animals.md
                  |
                  |- animals2.md

I prepared .foo directory, animals.md and animals2.md. And I wrote below to config.yml

ignore_path_pattern: '/\\.git/'

I started Shiba and drag&drop animals.md to the window. And then I edited animals.md. As the result, I confirmed that Shiba works well. Could you tell me your detailed sequence?

ghost commented 9 years ago

Hopefully this explains my problem further:

When editing a document inside a hidden folder, Shiba stops updating the document after the 2nd or 3rd update. Normally if you edit the document in Vim, upon saving the document Shiba will see the file change and update the document. However, after the 2nd or 3rd save in VIm, Shiba stops updating the document. This only occurs for files which have a dot folder somewhere in the path.

Also, when editing a document that has a dot folder somewhere in the path, Shiba cannot see any file events so if you start editing a document within that folder Shiba is unable to see it, and will not switch to the most recently changed file.

Neither of these problems occur when there is no dot-folder in the file path.

rhysd commented 9 years ago

Ah, sorry, I thought I wrote comment to this issue but I didn't...

Thank you for your detailed explanation. I tried in above .foo directly but I could not reproduce...

  1. I opened Shiba and loaded animals.md by clicking paw icon in main window.
  2. I loaded animals2.md by folder button.
  3. I edited animals2.md
  4. Shiba updated preview correctly
ghost commented 9 years ago

Using the currently available build from npm (0.4.4), this is what happens:

  1. folder .foo and animals.md inside .foo
  2. open animals.md with shiba and with vim
  3. edit in vim, upon :w no update in shiba, requires manual refresh, shiba cannot see changes
  4. close shiba and vim
  5. rename folder to foo and leave animals.md inside
  6. reopen animals.md with shiba and vim
  7. edit in vim, upon :w shiba can now see changes and automatically updates
ghost commented 9 years ago

Oops didn't mean to close, pushed wrong button.

rhysd commented 9 years ago

Thank you for the detailed sequence. I'll try it.

rhysd commented 9 years ago

@xHN35RQ

I tried your sequence but 3. still works well. I took a screenshot.

ss

It may be a Linux-specific fsevent problem. I'll check it with Ubuntu PC (I can't use Linux PC until next Thursday..)

ghost commented 9 years ago

Thanks @rhysd!

rhysd commented 9 years ago

I tried below sequence with shiba v0.5.1 and Ubuntu 12.04. But it seems to work well...

Directory

current dir --- .foo
                  |
                  |- animals.md

Config

ignore_path_pattern: '/\\.git/'

Sequence

  1. cd .foo
  2. vim animals.md
  3. shiba animals.md
  4. Edit animals.md with Vim opened at 2..
  5. Check preview

At 5., the preview was updated correctly.

ghost commented 9 years ago

I can confirm this worked! I did not have ignore_path_pattern: '/\\.git/' in my config.yml. I added that line, and now it works perfectly.

So without ignore_path_pattern: '/\\.git/' in config.yml Shiba cannot see changes in dot-folders.

Thanks once again for your help! :cake:

rhysd commented 9 years ago

:tada:

Thank you for the confirmation.

ghost commented 9 years ago

In https://github.com/rhysd/Shiba/issues/10#issuecomment-142900717 you did the same as https://github.com/rhysd/Shiba/issues/10#issuecomment-133308065

So did I misunderstand something? Is Shiba default behavior to ignore hidden files?

Edit: ok it does ignore by default: https://github.com/rhysd/Shiba/commit/3896b3835396379be64a9a623fbeb750c45ec428

Odd, because I've tried before to use ignore_path_pattern: '/\\.git/' with no success.

rhysd commented 9 years ago

Yes, Shiba ignores dotfiles by default. This is a standard way when using chokidar.

Sometimes dotfiles directory has many files (e.g. .git of large repository). Watching such a directory seems to pay cost. I think ignoring dotfiles helps to avoid the cost.

ghost commented 9 years ago

Well, thank you again for your help, and I'm sorry for causing all this extra work for you. I forgot to read the documentation after you updated on August 15.

rhysd commented 9 years ago

No problem. You kindly reported many issues and they improved Shiba so much :smile: