Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit edba45b

Browse files
authored
Merge pull request #129 from sveltejs/robustify-hmr
ensure old server is killed before listening for port on new server
2 parents 2752c73 + 6059290 commit edba45b

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/cli/dev.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,21 @@ export default async function dev(src: string, dir: string) {
137137
fs.writeFileSync(path.join(dir, 'server_info.json'), JSON.stringify(server_info, null, ' '));
138138

139139
deferreds.client.promise.then(() => {
140-
if (proc) proc.kill();
140+
function restart() {
141+
wait_for_port(3000, deferreds.server.fulfil); // TODO control port
142+
}
143+
144+
if (proc) {
145+
proc.kill();
146+
proc.on('exit', restart);
147+
} else {
148+
restart();
149+
}
141150

142151
proc = child_process.fork(`${dir}/server.js`, [], {
143152
cwd: process.cwd(),
144153
env: Object.assign({}, process.env)
145154
});
146-
147-
wait_for_port(3000, deferreds.server.fulfil); // TODO control port
148155
});
149156
}
150157
});

0 commit comments

Comments
 (0)