-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Feature request - Allow watching files outside of the module graph #12197
Comments
I found a good workaround for this. Consider the code below: async function watch(
directory: string,
extension: string,
handler: (path: string) => void,
) {
const watcher = Deno.watchFs(directory);
for await (const event of watcher) {
event.paths.forEach((p) => p.endsWith(extension) && handler(p));
}
} Then at function main() {
// Touch this file if any json file in the project changes to trigger a rebuild.
watch(
".",
".json",
() => Deno.run({ cmd: ["touch", new URL("", import.meta.url).pathname] }),
);
...
} |
I think this is a really useful feature. We should add it. Would be tremendously useful for fresh: https://fresh.deno.dev. |
How do you propose we do this? Accept arguments to the |
@bartlomieju As mentioned in the issue, I would go with something like |
The thing is we don't really support globs in any of the CLI flags - it's up to your shell to expand them. I can see the value of this feature, but we need to be careful considering what can be delivered. |
@bartlomieju let's just start with individual files and folders in the arguments to --watch, and go from there. |
Sounds good to me, PRs are welcome |
For anyone interested in tackling this issue, here are some some pointers how to do it: In
In
Add a test to I'm going to mark this as a "good first issue", even though it's on the harder spectrum of "first issues". |
I'd like to have a go at this if that's ok! |
@jespertheend Please do! If you need some more guidance, please hop into the #dev channel on Discord: https://discord.gg/deno |
I am reading JSON files that then affect what Deno serves. The problem is that the operation is outside of Deno's module graph and the
watch
feature won't notice these type of changes.Based on #2401 (comment) I was thinking patterns are supported already but looking at the source (
deno/cli/flags.rs
Line 226 in 3c97dbf
Therefore I would propose adding support to
--watch=./**/*.ts,./**/*.tsx
kind of syntax (i.e.watch
would accept a string of globs) to allow watching arbitrary files even outside of Deno's module graph.Related to jurassiscripts/velociraptor#80.
The text was updated successfully, but these errors were encountered: