chore(dev): improve bulk change handling #2234

Merged
Sainan merged 4 commits from dev-debounce into main 2025-06-21 11:33:59 -07:00
Showing only changes of commit 4c0d804828 - Show all commits

View File

@ -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();