Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for watching hidden files #210

Open
boxizen opened this issue Mar 24, 2023 · 7 comments
Open

Support for watching hidden files #210

boxizen opened this issue Mar 24, 2023 · 7 comments
Labels
enhancement New feature or request watch

Comments

@boxizen
Copy link
Contributor

boxizen commented Mar 24, 2023

Feature request

Allows monitoring changes starting with ., like .env or other hidden files.

Why?

Reading hidden files in ts files is a special requirement we encounter in business development.

For example, we will keep some secret data locally on the server by means of hidden files. When adjusting the content of hidden files, the result should also be real-time refresh, but tsx excludes hidden files from the monitoring range by default, which will not meet this requirement.

For the same case, please refer to #181

Alternatives

In order to meet such requirements, it is necessary to add the monitoring capability of dependent files other than js/ts first, like the capabilities provided by #208.

Then exclude rules that match the currently watched file from the default ignored rules. For example, if I watch .env file, **/.* should be removed from the ignored rules, as shown in the figure below.

Additional context

@jrnail23

This comment was marked as spam.

@iki
Copy link

iki commented Aug 27, 2024

@privatenumber should also work for includes like

  • .env* (common)
  • ./.env*
  • .etc/* (config jsons) - needs to remove the ignored dotdirs glob **/.*/**
  • .etc/.env* (config jsons) - needs to remove both the ignored dotdirs/dotfiles globs

One possible implementation is via regexp checking of included items:

  • if include matches ^(.*[/\])?\.[^/\]+$, remove ignored dotfiles glob
  • if include matches ^(.*[/\])?\..*[/\].+$, remove ignored dotdirs glob

Given that tsx only watches imported sources and explicitly included files, there's a question if ignoring dotfiles and dotdirs has a real use case at all

I can help implementing that

@privatenumber
Copy link
Owner

Nice, thanks.

I looked into implementation but I'm not far into it at all so feel free to tackle it if you have time.

Regarding implementation, I was planning to convert the ignore in chokidar to a function and test against any includes pattern with the same glob library (https://github.com/micromatch/picomatch) before moving forward with the excludes patterns.

@iki
Copy link

iki commented Aug 27, 2024

@privatenumber good, looked into it a bit.

Currently, chokidar watch ignored option supports anymatch Array|String|RegExp|Function matchers , but it's going to narrow down to RegExp|Function in v4.

Also, the chokidar ignored option is only useful to ignore parts of monitored directories. AFAIK, tsx watch only monitors files, so we may avoid using this option at all and filter the files when adding, which gives us both simpler implementation and simpler future migration to chokidar v4.

The evaluation rules for any added files would be:

  • Add globs specified by --include
    • As implemented now, no changes needed
  • For imported files, skip if they matche tsx internal ignore setting, add otherwise
    • Ignore setting can be used as is, list of globs excluding dotfiles, dotdirs, node modules, etc.
    • The settings won't be passed to chokidar watch, tsx will use it to evaluate imported files before adding

I can get to it later this week. WDYT?

@privatenumber
Copy link
Owner

@iki Great insight and that sounds good, thanks for looking into it!

Also, not too relevant right now, but FYI I'm considering migrating from chokidar to @parcel/watcher down the road. It's used by VSCode and seems to support more platforms. But as you point out, tsx only watches specific file paths, so maybe we can even just use fs.watch in the future.

@Prabhuomkar9

This comment was marked as spam.

@buti1021
Copy link

Would it be possible to add a note to the documentation that using --include with a hidden file does currently not work as long as this is not implented? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request watch
Projects
None yet
Development

No branches or pull requests

6 participants