Skip to content

Commit c7a2581

Browse files
Enhance VitestManager to support module invalidation for server, vite, and browser contexts
1 parent 0d0ec4c commit c7a2581

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

code/addons/vitest/src/node/vitest-manager.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,20 @@ export class VitestManager {
164164
}
165165

166166
private updateLastChanged(filepath: string) {
167-
this.vitest!.projects.forEach((project) => {
168-
const mods = project.vite.moduleGraph.getModulesByFile(filepath);
169-
mods?.forEach((mod) => project.vite.moduleGraph.invalidateModule(mod));
167+
// @ts-expect-error `server` only exists in Vitest 3
168+
this.vitest!.projects.forEach(({ browser, vite, server }) => {
169+
if (server) {
170+
const serverMods = server.moduleGraph.getModulesByFile(filepath);
171+
serverMods?.forEach((mod: any) => server.moduleGraph.invalidateModule(mod));
172+
}
173+
if (vite) {
174+
const serverMods = vite.moduleGraph.getModulesByFile(filepath);
175+
serverMods?.forEach((mod) => vite.moduleGraph.invalidateModule(mod));
176+
}
177+
if (browser) {
178+
const browserMods = browser.vite.moduleGraph.getModulesByFile(filepath);
179+
browserMods?.forEach((mod) => browser.vite.moduleGraph.invalidateModule(mod));
180+
}
170181
});
171182
}
172183

0 commit comments

Comments
 (0)