watchdeno

What syntax deno --watch supports for file globs?


I am running

deno run -A --watch=./**/*.html,./**/*.js src/build.js

but changes to the globbed files are never triggering the build. Only changes from dependency graph of build.js are causing the build to happen. I tried using the quotes around the globs, or using only one or another without commas without success.

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

but I don’t seem to find what syntax the <FILES> should be.

I am using Deno 1.32.1 on macOS.


Solution

  • Deno expects the values in list arguments to use a comma as the separator, but lists produced by globbing use a space by default.

    You can use shell features to modify the separator character in the list... or just use Deno. Here's an example using brace expansion that should work for your case:

    deno run --watch=$(deno eval -p 'Deno.args.join(",")' ./**/*.{html,js}) src/build.js
    

    Explanation of the watch argument:

    $(                                                   ) # Run the command in a subshell
      deno eval -p                                         # Evaluate JavaScript from the command line
                   'Deno.args.join(",")'                   # The code to evaluate (join input arguments on a comma)
                                         ./**/*.{html,js}  # The expanded glob list
    

    So, for example, if you have a filesystem structure of html and js files like this:

    % ls -1 ./**/*.{html,js}
    ./files/a.html
    ./files/a.js
    ./files/nested/b.html
    ./files/nested/b.js
    ./src/build.js
    

    then the subshell command would produce a comma-separated list argument like this:

    % deno eval -p 'Deno.args.join(",")' ./**/*.{html,js}
    ./files/a.html,./files/nested/b.html,./files/a.js,./files/nested/b.js,./src/build.js