Open VividVisions opened 2 weeks ago
Happy to merge this but any API breaking changes in Eleventy core and we might be able to sneak it in to 3.0 if it happens very soon (like, probably this week)
Created a PR. Please let me know if I should change anything. I'll provide a PR for the changes in Eleventy tomorrow.
Currently, the web server, the update (WebSocket) server and the Chokidar watcher are closed by calling their respective
close()
functions, disregarding their callbacks/returned Promises. Furthermoreprocess.exit();
is called immediately after, preventing a graceful shutdown altogether.I'd suggest to make the
close()
methods ofEleventyDevServer
andCli
asynchronous and to changeprocess.exit();
toprocess.exitCode = 0;
in case of aSIGINT
signal. This would make the shutdown process clean and graceful.I'd happily provide a PR!
Note: These changes would also necessitate small adjustments in Eleventy itself, i.e. making
stopWatch()
ofEleventy
asynchronous and exchangingprocess.exit();
there as well.Background:
We've built a custom server which wraps around `EleventyDevServer` and needs a bit of cleanup during shutdown. Due to the current shutdown process, we couldn't use the `close` event of `http.Server` which either doesn't even get emitted or isn't waited for. We had to implement ugly workarounds/hacks to make this work. ;)