@@ -586,7 +586,7 @@ export class Vitest {
586586
587587 public getModuleProjects ( id : string ) {
588588 return this . projects . filter ( ( project ) => {
589- return project . getModuleById ( id )
589+ return project . getModulesByFilepath ( id ) . size
590590 // TODO: reevaluate || project.browser?.moduleGraph.getModulesByFile(id)?.size
591591 } )
592592 }
@@ -596,9 +596,13 @@ export class Vitest {
596596 const updateLastChanged = ( id : string ) => {
597597 const projects = this . getModuleProjects ( id )
598598 projects . forEach ( ( { server, browser } ) => {
599- const mod = server . moduleGraph . getModuleById ( id ) || browser ?. moduleGraph . getModuleById ( id )
600- if ( mod )
601- server . moduleGraph . invalidateModule ( mod )
599+ const serverMods = server . moduleGraph . getModulesByFile ( id )
600+ serverMods ?. forEach ( mod => server . moduleGraph . invalidateModule ( mod ) )
601+
602+ if ( browser ) {
603+ const browserMods = browser . moduleGraph . getModulesByFile ( id )
604+ browserMods ?. forEach ( mod => browser . moduleGraph . invalidateModule ( mod ) )
605+ }
602606 } )
603607 }
604608
@@ -675,22 +679,10 @@ export class Vitest {
675679 const files : string [ ] = [ ]
676680
677681 for ( const project of projects ) {
678- const { server, browser } = project
679- const mod = server . moduleGraph . getModuleById ( id ) || browser ?. moduleGraph . getModuleById ( id )
680- if ( ! mod ) {
681- // files with `?v=` query from the browser
682- const mods = browser ?. moduleGraph . getModulesByFile ( id )
683- if ( ! mods ?. size )
684- return [ ]
685- let rerun = false
686- mods . forEach ( ( m ) => {
687- if ( m . id && this . handleFileChanged ( m . id ) )
688- rerun = true
689- } )
690- if ( rerun )
691- files . push ( id )
682+ const { server } = project
683+ const mods = project . getModulesByFilepath ( id )
684+ if ( ! mods . size )
692685 continue
693- }
694686
695687 // remove queries from id
696688 id = normalizeRequestId ( id , server . config . base )
@@ -705,14 +697,18 @@ export class Vitest {
705697 }
706698
707699 let rerun = false
708- mod . importers . forEach ( ( i ) => {
709- if ( ! i . id )
710- return
711-
712- const heedsRerun = this . handleFileChanged ( i . id )
713- if ( heedsRerun )
714- rerun = true
715- } )
700+ for ( const mod of mods ) {
701+ if ( ! mod . id )
702+ continue
703+ mod . importers . forEach ( ( i ) => {
704+ if ( ! i . id )
705+ return
706+
707+ const heedsRerun = this . handleFileChanged ( i . id )
708+ if ( heedsRerun )
709+ rerun = true
710+ } )
711+ }
716712
717713 if ( rerun )
718714 files . push ( id )
0 commit comments