fix(dev-server): normalize hot reload module paths

This commit is contained in:
2026-08-09 13:32:00 +05:30
parent d85be6c456
commit a90d3683d3
2 changed files with 4 additions and 2 deletions
+2
View File
@@ -259,6 +259,7 @@ async function rewriteArtifactImportsAsync(
} }
export async function loadModule(file: string): Promise<Record<string, unknown>> { export async function loadModule(file: string): Promise<Record<string, unknown>> {
file = resolve(file);
let mod = moduleCache.get(file); let mod = moduleCache.get(file);
if (!mod) { if (!mod) {
mod = (async () => { mod = (async () => {
@@ -631,6 +632,7 @@ export function serveWrnBrowserArtifact(pathname: string): Response | null {
/** Forget one module and force its next dynamic import to bypass Bun's import cache. */ /** Forget one module and force its next dynamic import to bypass Bun's import cache. */
export function invalidateModule(file: string): void { export function invalidateModule(file: string): void {
file = resolve(file);
moduleCache.delete(file); moduleCache.delete(file);
moduleVersions.set(file, (moduleVersions.get(file) ?? 0) + 1); moduleVersions.set(file, (moduleVersions.get(file) ?? 0) + 1);
} }
+2 -2
View File
@@ -83,7 +83,7 @@ test("invalidateModule loads changed server modules without restarting the proce
} }
}); });
test("invalidateModule recompiles changed WRN files in-process", async () => { test("invalidateModule recompiles changed WRN files with watcher-normalized separators", async () => {
const root = mkdtempSync(join(tmpdir(), "wrnexus-hmr-")); const root = mkdtempSync(join(tmpdir(), "wrnexus-hmr-"));
const file = join(root, "page.wrn"); const file = join(root, "page.wrn");
setCompileCacheDir(join(root, ".wrnexus")); setCompileCacheDir(join(root, ".wrnexus"));
@@ -94,7 +94,7 @@ test("invalidateModule recompiles changed WRN files in-process", async () => {
expect(String(first({}))).toContain("First"); expect(String(first({}))).toContain("First");
writeFileSync(file, "page Home { view { <h1>Second</h1> } }\n"); writeFileSync(file, "page Home { view { <h1>Second</h1> } }\n");
invalidateModule(file); invalidateModule(file.replace(/\\/g, "/"));
const second = (await loadModule(file)).default as (ctx: unknown) => unknown; const second = (await loadModule(file)).default as (ctx: unknown) => unknown;
expect(String(second({}))).toContain("Second"); expect(String(second({}))).toContain("Second");
} finally { } finally {