dev:all stops both sides when the server's port is taken
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Jm2auWk6RP71CjaAb4FMoG
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
ab999c1c43
commit
43a5a2023b
+10
-2
@@ -1,5 +1,6 @@
|
|||||||
// The game server and the site together, for playing locally: one terminal,
|
// The game server and the site together, for playing locally: one terminal,
|
||||||
// each line marked with its side, and Ctrl-C (or either one stopping) stops both.
|
// each line marked with its side, and Ctrl-C (or either one stopping or
|
||||||
|
// failing to get its port) stops both.
|
||||||
import { spawn } from 'node:child_process';
|
import { spawn } from 'node:child_process';
|
||||||
|
|
||||||
const sides = [
|
const sides = [
|
||||||
@@ -13,7 +14,14 @@ const children = sides.map(([name, args]) => {
|
|||||||
stream.on('data', (chunk) => {
|
stream.on('data', (chunk) => {
|
||||||
const lines = (rest + chunk).split('\n');
|
const lines = (rest + chunk).split('\n');
|
||||||
rest = lines.pop();
|
rest = lines.pop();
|
||||||
for (const line of lines) console.log(`[${name}] ${line}`);
|
for (const line of lines) {
|
||||||
|
console.log(`[${name}] ${line}`);
|
||||||
|
// A watcher outlives the crash it watches, so a port already taken would leave one side running alone.
|
||||||
|
if (line.includes('EADDRINUSE')) {
|
||||||
|
console.log(`[${name}] its port is taken: is another copy already running?`);
|
||||||
|
stop(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
child.on('exit', (code) => stop(code ?? 0));
|
child.on('exit', (code) => stop(code ?? 0));
|
||||||
|
|||||||
Reference in New Issue
Block a user