mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-18 13:35:08 +00:00
Merge pull request #129 from sveltejs/robustify-hmr
ensure old server is killed before listening for port on new server
This commit is contained in:
@@ -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, ' '));
|
fs.writeFileSync(path.join(dir, 'server_info.json'), JSON.stringify(server_info, null, ' '));
|
||||||
|
|
||||||
deferreds.client.promise.then(() => {
|
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`, [], {
|
proc = child_process.fork(`${dir}/server.js`, [], {
|
||||||
cwd: process.cwd(),
|
cwd: process.cwd(),
|
||||||
env: Object.assign({}, process.env)
|
env: Object.assign({}, process.env)
|
||||||
});
|
});
|
||||||
|
|
||||||
wait_for_port(3000, deferreds.server.fulfil); // TODO control port
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user