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

deno watch for web development #2401

Closed
MarkTiedemann opened this issue May 23, 2019 · 16 comments
Closed

deno watch for web development #2401

MarkTiedemann opened this issue May 23, 2019 · 16 comments
Labels
cli related to cli/ dir suggestion suggestions for new features (yet to be agreed)

Comments

@MarkTiedemann
Copy link
Contributor

MarkTiedemann commented May 23, 2019

Would love to have a better web development experience with Deno out of the box.

  • First, the server should restart whenever I make changes.
  • Second, the website should reload whenever I make changes.

For the server, I'd like to propose a deno watch subcommand or deno run --watch flag that automatically restarts the server in a controlled way, e.g.

deno watch *.ts --run main.ts --allow-net
# or
deno run --watch *.ts --allow-net main.ts

If we also had a Deno.watch API for watching directories or files, we could then implement a simple client refresh via server-sent events (example) or web sockets.

EDIT: It would be nice if the watch subcommand/flag would be able to notify the running code that it will/should be restarted - maybe something via signals (e.g. SIGUSR1), command line flags, some API, or a similar mechanism - so that the server could notify the client that it will be restarted and that the client needs to be reloaded.

@MarkTiedemann MarkTiedemann changed the title deno watch deno watch for web development May 23, 2019
@kitsonk
Copy link
Contributor

kitsonk commented May 23, 2019

Duplicate of #1826

@MarkTiedemann
Copy link
Contributor Author

MarkTiedemann commented May 23, 2019

Duplicate of #1826

I'd say it's related rather than a duplicate. #1826 is about the Deno.watch API, but does not mention a watch subcommand or --watch flag.

I also found #2251 which is related. It's about "automatically restarting the server". I think the solution to that would be the subcommand / flag.

@ry
Copy link
Member

ry commented May 23, 2019

Once #1826 is done, I would consider this. Tho it would need to be carefully specified - and I'm not sure if it can be accomplished in general.

@Caesar2011
Copy link
Contributor

Caesar2011 commented Apr 20, 2020

Now, when #1826 is done, we can consider this again. Based on another issue #4830 I implemented a small typescript script.

https://github.com/Caesar2011/rhinoder

This could at least be used for Deno.watch().

@eliassjogreen
Copy link
Contributor

I have made denon which serves the same purpose but with a bit more configurability.

@MarkTiedemann
Copy link
Contributor Author

Don't think that this should be part of Deno core anymore, closing.

@rudyhuynh
Copy link

@MarkTiedemann I think this should be part of Deno core. We already have unit test, code format, bundler, .etc. Watch for development must be major piece of Deno core as well.

@Caesar2011
Copy link
Contributor

Consider deno run --watch file.ts.

@bartlomieju bartlomieju reopened this May 24, 2020
@bartlomieju bartlomieju added cli related to cli/ dir suggestion suggestions for new features (yet to be agreed) labels May 24, 2020
@MarkTiedemann
Copy link
Contributor Author

First of all, I think Deno is fast enough that you don't really need a watcher. Just Ctrl+C, Up, Enter is probably fine for 90% of use cases. It has been working quite fine for me working with Deno on a daily basis for the past one and a half years. You should try it. :)

Then there's two arguments I made when originally opening this issue:

  1. The server should restart whenever I make changes.
  2. The website should reload whenever I make changes.

2, I think, is out of scope anyways. Deno should not have live-reload integration or some hacky server-sent events that trigger in-browser refresh, as I originally proposed. In retrospect, I think that is a dumb idea. If you really need something like that, write it yourself, put it on GitHub - but I don't think this should ever be in core.

1, I think, is doable and could potentially be in core some day. But then again, I don't think deno run --watch app.ts is any better than denon run app.ts, or using the usual general purpose filewatching tools that have long solved this problem (https://github.com/emcrisostomo/fswatch, https://github.com/facebook/watchman, etc.)

If someone wants to open another issue for this, feel free. This one I'd like to keep closed.

@jtwebman
Copy link

jtwebman commented May 25, 2020

@MarkTiedemann Closing the whole issue because 2 isn't a good idea but 1 would be a big win. It is very common when working on an API application to restart deno. The sad part is right now I use Node.js nodemon to do it.

npx nodemon --exec "deno run --allow-net=0.0.0.0" server.js

But will gladly open another issue to be more clear with what is needed and the win for having it in the core. --watch in the run command will allow for you to only watch the files that are loaded with the command vs restarting if anything changes.

@notfilippo
Copy link

Also, there is denosaurs/denon

@rwieruch
Copy link
Contributor

I was surprised seeing that there is no watch mode for development purposes in Deno (correct me if I am wrong). After going through Deno's philosophy, IMO it shouldn't be the case that I already have to fallback to nodemon or a third-party (?) like denon for this. This is a core developer experience issue for me.

@pedropaulosuzuki
Copy link

Just in case someone is wondering, #7382 got merged successfully 22 days ago

@tbsvttr
Copy link

tbsvttr commented Dec 14, 2020

deno bundle --unstable --watch ./src/app.ts ./build/app.bundle.ts works for me with deno 1.6.0.

@asbjornu
Copy link

Seems like --watch supports globbing and multiple paths separated by comma as well. This works for me, at least:

deno run --watch=./**/*.ts,./**/*.tsx server.ts

@bebraw
Copy link

bebraw commented Sep 23, 2021

@asbjornu Through research at jurassiscripts/velociraptor#80 we found out watch supports only a boolean flag right now. I opened #12197 with a small proposal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli related to cli/ dir suggestion suggestions for new features (yet to be agreed)
Projects
None yet
Development

No branches or pull requests