|
| 1 | +import type { |
| 2 | + DevRuntime as DevRuntimeType, |
| 3 | + Messenger, |
| 4 | +} from 'rolldown/experimental/runtime-types' |
1 | 5 | import type { ErrorPayload, HotPayload } from '#types/hmrPayload' |
2 | 6 | import type { ViteHotContext } from '#types/hot' |
3 | 7 | import { HMRClient, HMRContext } from '../shared/hmr' |
@@ -617,33 +621,36 @@ export function injectQuery(url: string, queryToInject: string): string { |
617 | 621 |
|
618 | 622 | export { ErrorOverlay } |
619 | 623 |
|
620 | | -// TODO: proper types |
621 | | -declare let DevRuntime: { new (socket: any): any } | undefined |
| 624 | +declare const DevRuntime: typeof DevRuntimeType |
622 | 625 |
|
623 | 626 | if (isFullBundleMode && typeof DevRuntime !== 'undefined') { |
624 | 627 | class ViteDevRuntime extends DevRuntime { |
625 | | - createModuleHotContext(moduleId: string) { |
| 628 | + override createModuleHotContext(moduleId: string) { |
626 | 629 | const ctx = createHotContext(moduleId) |
627 | 630 | // @ts-expect-error TODO: support CSS properly |
628 | 631 | ctx._internal = { updateStyle, removeStyle } |
629 | 632 | return ctx |
630 | 633 | } |
631 | 634 |
|
632 | | - applyUpdates(_boundaries: string[]): void { |
| 635 | + override applyUpdates(_boundaries: [string, string][]): void { |
633 | 636 | // noop, handled in the HMR client |
634 | 637 | } |
635 | 638 | } |
636 | 639 |
|
637 | | - // TODO: make this more performant |
638 | | - const wrappedSocket = { |
639 | | - readyState: WebSocket.OPEN, |
640 | | - send(data: string) { |
641 | | - const d = JSON.parse(data) |
642 | | - transport.send({ |
643 | | - type: 'custom', |
644 | | - event: 'vite:module-loaded', |
645 | | - data: { modules: d.modules }, |
646 | | - }) |
| 640 | + const wrappedSocket: Messenger = { |
| 641 | + send(message) { |
| 642 | + switch (message.type) { |
| 643 | + case 'hmr:module-registered': { |
| 644 | + transport.send({ |
| 645 | + type: 'custom', |
| 646 | + event: 'vite:module-loaded', |
| 647 | + data: { modules: message.modules }, |
| 648 | + }) |
| 649 | + break |
| 650 | + } |
| 651 | + default: |
| 652 | + throw new Error(`Unknown message type: ${JSON.stringify(message)}`) |
| 653 | + } |
647 | 654 | }, |
648 | 655 | } |
649 | 656 | ;(globalThis as any).__rolldown_runtime__ ??= new ViteDevRuntime( |
|
0 commit comments