Skip to content

Commit fb964de

Browse files
committed
fix: Close vite HMR on shutdown message
1 parent 620092c commit fb964de

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Scope } from 'harperdb';
22
import { join } from 'node:path';
33
import * as vite from 'vite';
4+
import { parentPort } from 'node:worker_threads';
45

56
export const viteWrapper = {
67
createServer: vite.createServer,
@@ -20,4 +21,12 @@ export async function handleApplication(scope: Scope) {
2021
}
2122

2223
scope.on('close', () => viteInstance.close());
24+
25+
// TODO: Once `scope.close` is emitting properly, we won't need this. Hopefully.
26+
// To you who read this in 2 years and shake your head: I salute you, sir or madam.
27+
parentPort?.on('message', (msg) => {
28+
if (msg.type === 'shutdown') {
29+
viteInstance.close();
30+
}
31+
});
2332
}

0 commit comments

Comments
 (0)