()
| 365 | } |
| 366 | |
| 367 | async function importLatestModule(): Promise<unknown> { |
| 368 | const activeSessionRoot = getSessionRoot(); |
| 369 | revision++; |
| 370 | const revisionDir = join(activeSessionRoot, `rev-${String(revision)}`); |
| 371 | await cp(moduleRoot, revisionDir, { recursive: true, filter: copyFilter }); |
| 372 | if (hostNodeModulesPath) { |
| 373 | const snapshotNodeModules = join(revisionDir, "node_modules"); |
| 374 | try { |
| 375 | symlinkSync(hostNodeModulesPath, snapshotNodeModules, "junction"); |
| 376 | } catch { |
| 377 | // Best-effort: if symlink creation fails, reload may still work for relative imports. |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | const relEntry = relative(moduleRoot, entryPath); |
| 382 | const snapshotEntry = join(revisionDir, relEntry); |
| 383 | const moduleUrl = `${pathToFileURL(snapshotEntry).href}?rezi_hsr_rev=${String(revision)}`; |
| 384 | const moduleNs = await import(moduleUrl); |
| 385 | |
| 386 | const staleRevision = revision - PRESERVED_SNAPSHOT_REVISIONS; |
| 387 | if (staleRevision > 0) { |
| 388 | const staleDir = join(activeSessionRoot, `rev-${String(staleRevision)}`); |
| 389 | rmSync(staleDir, { recursive: true, force: true }); |
| 390 | } |
| 391 | |
| 392 | return moduleNs; |
| 393 | } |
| 394 | |
| 395 | function queueReload(phase: "manual" | "watch"): Promise<boolean> { |
| 396 | const changedPath = pendingChangePath; |
no test coverage detected