From 4c0d804828f18ac39a077bd719830b53d4270a21 Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Sat, 21 Jun 2025 20:20:45 +0200 Subject: [PATCH] No need to debounce, simply ignore orphaned build process "exit" events --- scripts/dev.js | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/scripts/dev.js b/scripts/dev.js index 80e505d8..10d6ac36 100644 --- a/scripts/dev.js +++ b/scripts/dev.js @@ -13,7 +13,7 @@ args.push("--dev"); args.push("--secret"); args.push(secret); -let buildproc, runproc, timeout; +let buildproc, runproc; function run(changedFile) { if (changedFile) { console.log(`Change to ${changedFile} detected`); @@ -28,19 +28,20 @@ function run(changedFile) { runproc = undefined; } - clearTimeout(timeout); - timeout = setTimeout(function () { - buildproc = spawn("npm", ["run", "build:dev"], { stdio: "inherit", shell: true }); - buildproc.on("exit", code => { - buildproc = undefined; - if (code === 0) { - runproc = spawn("npm", ["run", "start", "--", ...args], { stdio: "inherit", shell: true }); - runproc.on("exit", () => { - runproc = undefined; - }); - } - }); - }, 20); + const thisbuildproc = spawn("npm", ["run", "build:dev"], { stdio: "inherit", shell: true }); + buildproc = thisbuildproc; + buildproc.on("exit", code => { + if (buildproc !== thisbuildproc) { + return; + } + buildproc = undefined; + if (code === 0) { + runproc = spawn("npm", ["run", "start", "--", ...args], { stdio: "inherit", shell: true }); + runproc.on("exit", () => { + runproc = undefined; + }); + } + }); } run();