From e78e088969afea534968db842ed869e568dc6d1c Mon Sep 17 00:00:00 2001 From: Walter Krivanek Date: Thu, 11 Jul 2024 16:27:48 +0200 Subject: [PATCH] Makes stopWatch() async and graceful. --- src/Eleventy.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Eleventy.js b/src/Eleventy.js index 969eee889..156b345e2 100644 --- a/src/Eleventy.js +++ b/src/Eleventy.js @@ -1151,7 +1151,7 @@ Arguments: this.watchManager.setBuildFinished(); } else { this.errorHandler.fatal(e, "Eleventy fatal watch error"); - this.stopWatch(); + await this.stopWatch(); } } }; @@ -1172,15 +1172,21 @@ Arguments: this.fileSystemSearch.delete(path); }); - process.on("SIGINT", () => this.stopWatch()); + process.on("SIGINT", async () => await this.stopWatch()); } - stopWatch() { + async stopWatch() { + // Prevent multiple invocations. + if (this?._isStopping) { + return; + } + this._isStopping = true; + debug("Cleaning up chokidar and server instances, if they exist."); - this.eleventyServe.close(); - this.watcher.close(); + await this.eleventyServe.close(); + await this.watcher.close(); - process.exit(); + process.exitCode = 0; } /**