--watch flag doesn't restart on file creation
How can I trigger Deno to restart when a new file is added? The
deno run --watch ...
command only seems to trigger when a file is modified or deleted but not when a new file is created.
My workaround currently is to use Deno.watchFs(".")
to detect file creation and then modify an existing file which triggers the process to restart. This isn't ideal and it would be great if --watch
would also restart on file creation.2 Replies
My use case is for a dev mode for a Hono server. I have a simple script which enables file-based routing by generating a
routes.ts
file which imports all files within the routes/
directory. I can then import that routes.ts
file in my main.ts
and preserve the types where doing dynamic imports wouldn't. The code generation script is run on start / restart, just before main.ts
.I wasn't able to find the answer to your question in the official Deno documentation. However, based on your message, it seems like you're using the
--watch
flag correctly. The --watch
flag should indeed restart the Deno process when files change, but if it's not reacting to new files being created, this might be an oversight or a limitation in the current implementation.
Your current workaround using Deno.watchFs(".")
to detect file creation and then modifying an existing file to trigger a restart is a creative solution, but I understand that it's not ideal.
Please note that this advice is not based on the Deno documentation, and I would advise you to double-check the accuracy of this advice. It might also be helpful to check the latest updates in the Deno release notes or to reach out to the Deno community for more insights on this behavior.