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

--watch behaves strangely #24213

Closed
bkerin opened this issue Jun 14, 2024 · 3 comments
Closed

--watch behaves strangely #24213

bkerin opened this issue Jun 14, 2024 · 3 comments
Labels
working as designed this is working as intended

Comments

@bkerin
Copy link

bkerin commented Jun 14, 2024

Version: Deno 1.44.2

I have two files deno_tsx_test.tsx and worker.perl. I like the restarted so thought I'd try to use it when worker.perl changes as well but the behavior is pretty strange:

with:

deno run --check -A --unstable-ffi deno_tsx_test.tsx

I get the expected behavior (no reloading).

with:

deno run --check -A --unstable-ffi --watch='worker.perl' deno_tsx_test.tsx

I get a reload when either worker.perl or deno_tsx_test.tsx change (why does explicitly mentioning worker.perl trigger reloading on deno_tsx_test.tsx?).

with:

deno run --check -A --unstable-ffi --watch='worker.perl deno_tsx_test.tsx' deno_tsx_test.tsx

or

deno run --check -A --unstable-ffi --watch='worker.perl nonexistant_file' deno_tsx_test.tsx

I don't get any errors or warning but reloading only happens on deno_tsx_test.tsx (so it seems that the presence of --watch triggers reloading on the run script regardless of the option value, and I've guessed badly on the argument value for the --watch option).

If --watch takes an argument it shouldn't magically affect watching of the script file itself, and if it gets a pattern or argument string it doesn't understand (and I think if their are not existing matching files) it should error. And the details of the option argument should be documented, and it's name changed to reflect the fact that it can be a pattern. And I think multiples --watch options should be allowed also.

@lucacasonato
Copy link
Member

When specifying --watch, the script program will restart if any of the files in the module graph (so the entrypoint, or any file imports from it or any of it's dependencies) change.

You can pass additional files or folder to --watch as paths relative to your cwd. When passing multiple paths, separate them with ,. This is also explained in the help text.

      --watch[=<FILES>...]
          Watch for file changes and restart process automatically.
          Local files from entry point module graph are watched by default.
          Additional paths might be watched by passing them as arguments to this flag.

Finally, you can exclude files from being watched, by specifying a --watch-exclude flag:

      --watch-exclude[=<FILES>...]
          Exclude provided files/patterns from watch mode

The behaviour where non existant paths are not an error is expected and desired - we want to allow you to watch a directory or folder that does not exist yet, that may only be created by the script itself during execution.

@lucacasonato lucacasonato added the working as designed this is working as intended label Jun 17, 2024
@bkerin
Copy link
Author

bkerin commented Jun 18, 2024

You're right the default is specified. I'd phrase it differently though since it's a little unusual to have an option with an argument also have a global effect. The use of commas isn't documented as far as I can tell though, and neither is the pattern format referred to. Maybe it could be rewritten like this:

 --watch={=<FILE_PATTERNS>...]
    Watch for file changes and restart process automatically.
    When this option appears local files from entry point module graph are watched by default.  If an argument is provided to this
    option it give a comma-separated list of ???-style file patterns that will also be watched.

I still don't know what file patterns are supported. It doesn't seem be be shell-style globs (e.g. *.perl).

@bkerin
Copy link
Author

bkerin commented Jun 28, 2024

Sorry to revisit this but globs would be convenient, are they supported somehow? If so I'll write a doc patch if you can give me a quick answer :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
working as designed this is working as intended
Projects
None yet
Development

No branches or pull requests

2 participants