Skip to content

Commit 94ab392

Browse files
authored
fix: invalidate modules in all module graphs when the file is changed (#8352)
1 parent a4df683 commit 94ab392

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

packages/vitest/src/node/core.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,13 +1024,15 @@ export class Vitest {
10241024
*/
10251025
public invalidateFile(filepath: string): void {
10261026
this.projects.forEach(({ vite, browser }) => {
1027-
const serverMods = vite.moduleGraph.getModulesByFile(filepath)
1028-
serverMods?.forEach(mod => vite.moduleGraph.invalidateModule(mod))
1029-
1030-
if (browser) {
1031-
const browserMods = browser.vite.moduleGraph.getModulesByFile(filepath)
1032-
browserMods?.forEach(mod => browser.vite.moduleGraph.invalidateModule(mod))
1033-
}
1027+
const environments = [
1028+
...Object.values(vite.environments),
1029+
...Object.values(browser?.vite.environments || {}),
1030+
]
1031+
1032+
environments.forEach(({ moduleGraph }) => {
1033+
const modules = moduleGraph.getModulesByFile(filepath)
1034+
modules?.forEach(module => moduleGraph.invalidateModule(module))
1035+
})
10341036
})
10351037
}
10361038

0 commit comments

Comments
 (0)