From 605929053ca00c377372b0b1c660835ee81de185 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 20 Feb 2018 11:11:02 -0500 Subject: [PATCH] ensure old server is killed before listening for port on new server --- src/cli/dev.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/cli/dev.ts b/src/cli/dev.ts index 3f32e70..92857da 100644 --- a/src/cli/dev.ts +++ b/src/cli/dev.ts @@ -137,14 +137,21 @@ export default async function dev(src: string, dir: string) { fs.writeFileSync(path.join(dir, 'server_info.json'), JSON.stringify(server_info, null, ' ')); deferreds.client.promise.then(() => { - if (proc) proc.kill(); + function restart() { + wait_for_port(3000, deferreds.server.fulfil); // TODO control port + } + + if (proc) { + proc.kill(); + proc.on('exit', restart); + } else { + restart(); + } proc = child_process.fork(`${dir}/server.js`, [], { cwd: process.cwd(), env: Object.assign({}, process.env) }); - - wait_for_port(3000, deferreds.server.fulfil); // TODO control port }); } });