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

hmr? (hot module reloading) #62

Open
jacoobes opened this issue Jul 21, 2022 · 35 comments
Open

hmr? (hot module reloading) #62

jacoobes opened this issue Jul 21, 2022 · 35 comments

Comments

@jacoobes
Copy link
Member

Most clis enable users with a watch command

  • rollup
  • eleventy
  • typescript
  • nodemon
  • vite
    Letting sern deal with this would be very convenient for users.
    We could also just include it in the future with global plugins, once compatibility branch rolls around
@Murtatrxx
Copy link
Member

I'm not sure @EvolutionX-10 is here

@Murtatrxx
Copy link
Member

He's taking his long break I think

@Murtatrxx
Copy link
Member

Can we do it without him?

@jacoobes
Copy link
Member Author

need his permission as he's author.

@Murtatrxx
Copy link
Member

🤔 weren't you the owner?

@EvolutionX-10
Copy link
Member

Most clis enable users with a watch command

  • rollup
  • eleventy
  • typescript
  • nodemon
  • vite
    Letting sern deal with this would be very convenient for users.
    We could also just include it in the future with global plugins, once compatibility branch rolls around

sern watch ?
what things will it do 🤔

@jacoobes
Copy link
Member Author

On users re typing into their editor, on saves, update their code and changes should be instant when testing

@EvolutionX-10
Copy link
Member

Would it mean a restart? or No restarts?

@jacoobes
Copy link
Member Author

jacoobes commented Jul 21, 2022 via email

@jacoobes
Copy link
Member Author

jacoobes commented Jul 21, 2022 via email

@EvolutionX-10
Copy link
Member

Yep I've used hmr as well in a discord bot before, I loved it
However it doesn't work good with TS if we want no restarts since TS compiling to JS is done as a whole project not a single file itself

@jacoobes
Copy link
Member Author

Yep, true, could tell typescript users to use the tsc watch command however and then hmr on distribution

@EvolutionX-10
Copy link
Member

Also check #63
had in my mind from a long time and finally completed it, if you got more improvements, you can commit there and notify me

@EvolutionX-10
Copy link
Member

If you want you can create a branch and work on it, else I'll work on it by next week
My account will be enabled soon btw, exam's this week

@EvolutionX-10
Copy link
Member

git fetch origin
git checkout feat/hmr

@jacoobes
Copy link
Member Author

POG, looking forward to return
Hmr experimenting should be good

@vKxni

This comment was marked as off-topic.

@jacoobes
Copy link
Member Author

jacoobes commented Jul 24, 2022 via email

@jacoobes
Copy link
Member Author

Will be working on this. Experimental at the moment! A dev i saw ( Chooksie ) has a really good explanation on this, so I will research into it.

image

@jacoobes
Copy link
Member Author

Well just discovered hmr and nodemon near the same thing. nodemon is more for server side stuff while hmr is frontend.
https://stackoverflow.com/questions/46086297/nodemon-and-or-hot-reloading-with-a-node-react-web-app. I suppose we can just do some chokidar based system? @leonardobagi recommended this can be done in the framework and not in the cli

@leonardobagi
Copy link

I suppose we can just do some chokidar based system? @leonardobagi recommended this can be done in the framework and not in the cli

This feature could either be directly implemented in the Sern.init command via an option, or made via plugin. I do think that making built-in in Sern can be lighter, faster (since there's no need for external packages) and more customizable; it could also be easier to implement, because controlling command files via plugin can generate conflicts with the main code. The only drawback, though, is that we couldn't watch for an X file rather than the entire folder, but that is not such a big deal

@leonardobagi
Copy link

A sern watch cli command wouldn't be that good imo, since the init thing of the cli only generates the code

@jacoobes
Copy link
Member Author

jacoobes commented Jul 25, 2022

A sern watch cli command wouldn't be that good imo, since the init thing of the cli only generates the code
Understandable.
I was thinking these ways to implement a module watcher

  • through cli
  • through plugins
  • through global plugins ( experimental (and top secret!!!! jk) )
  • built in

one part of Sern i want to keep is to keep customization and to not add any extra features that users may not want.
So with this reasoning, I would say global plugins or built in is the best option. Like you said here :

I suppose we can just do some chokidar based system? @leonardobagi recommended this can be done in the framework and not in the cli

This feature could either be directly implemented in the Sern.init command via an option, or made via plugin. I do think that making built-in in Sern can be lighter, faster (since there's no need for external packages) and more customizable; it could also be easier to implement, because controlling command files via plugin can generate conflicts with the main code. The only drawback, though, is that we couldn't watch for an X file rather than the entire folder, but that is not such a big deal

Individual command watchers is just inefficient and id rather have a whole directory being watched.
So that brings us down to two options

  • through global plugins
  • built in
    Now the question boils down to is adding an hmr system ( in return adding more to the depedencies list most likely ) built into the framework wise? Or would it best be handled via the user, to opt into it through plugins.

@leonardobagi
Copy link

Now that you mentioned global plug-ins thing (which is probably what I wanted to do), it's better to apply that option.

It's very likely some users will prefer nodemon over this watcher, since, sometimes, the user needs to hot reload other files outside the commands directory (a utils folder e.g).

In addition, making it a plugin will reduce unnecessary and unwanted dependencies. (Because chokidar would be required, and some users will just not use the feature, increasing final bundle size)

@leonardobagi
Copy link

I also think that promoting plug-ins with that hmr one will make them look for more utilities plug-ins, create their own and contribute to existing ones. It's a nice way to a promote such an unique feature in handlers.

@leonardobagi
Copy link

It's very likely some users will prefer nodemon over this watcher, since, sometimes, the user needs to hot reload other files outside the commands directory (a utils folder e.g).

Our main point is to avoid multiple bot relogins and restarts, and only dynamically reload the commands, making everything faster and using less bandwidth. We can even make a dev slash command /reload, if it fits here.

@SrIzan10
Copy link
Member

reviving this, I want a convenient way of developing my bot without using ts-node or nodemon!

@leonardobagi
Copy link

It seems like the plug-ins API can't get us the commands yet, so we'll have to wait for that to happen

@SrIzan10
Copy link
Member

yea some guy at the discord just asked for that

@leonardobagi
Copy link

Yea I did

@SrIzan10
Copy link
Member

oh wait its you?

@SrIzan10
Copy link
Member

oh yeah you are 💀

@leonardobagi
Copy link

Lmfao

@jacoobes
Copy link
Member Author

@leonardobagi has been working on an experimental FileWatcher that may work

@leonardobagi
Copy link

leonardobagi commented Jan 19, 2023

That class starts the whole hmr thing, the only thing remaining is syncing the commands on discord. This could be easily done via a CommandsSyncer class I made for the sern-community bot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants