From c1d4e5cf83a7c83dac5159f119f88d1c354b4864 Mon Sep 17 00:00:00 2001 From: Teffen Ellis <592134+GirlBossRush@users.noreply.github.com> Date: Wed, 17 Sep 2025 17:08:34 +0200 Subject: [PATCH] web: Flush logs on SIGINT. (#16723) --- web/scripts/build-web.mjs | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/web/scripts/build-web.mjs b/web/scripts/build-web.mjs index 75dd52564c..430622b7ae 100644 --- a/web/scripts/build-web.mjs +++ b/web/scripts/build-web.mjs @@ -148,6 +148,8 @@ function doHelp() { } async function doWatch() { + const { promise, resolve, reject } = Promise.withResolvers(); + logger.info(`🤖 Watching entry points:\n\t${Object.keys(EntryPoint).join("\n\t")}`); const entryPoints = Object.values(EntryPoint); @@ -182,23 +184,31 @@ async function doWatch() { logger.info(`🔓 ${httpURL.href}`); logger.info(`🔒 ${httpsURL.href}`); - return /** @type {Promise} */ ( - new Promise((resolve) => { - process.on("SIGINT", () => { - resolve(); - }); - }) - ); + let disposing = false; + + const delegateShutdown = () => { + logger.flush(); + console.log(""); + + // We prevent multiple attempts to dispose the context + // because ESBuild will repeatedly restart its internal clean-up logic. + // However, sending a second SIGINT will still exit the process immediately. + if (disposing) return; + + disposing = true; + + return buildContext.dispose().then(resolve).catch(reject); + }; + + process.on("SIGINT", delegateShutdown); + + return promise; } async function doBuild() { - logger.info(`🚀 Building entry points:`); + logger.info(`🤖 Watching entry points:\n\t${Object.keys(EntryPoint).join("\n\t")}`); - const entryPoints = Object.entries(EntryPoint).map(([entrypointID, target]) => { - logger.info(entrypointID); - - return target; - }); + const entryPoints = Object.values(EntryPoint); const buildOptions = createESBuildOptions({ entryPoints,