@@ -152,20 +152,15 @@ async function onFileCreatedOrRemoved(file: string, isRemove: boolean, server: V
152152 // ```bash
153153 // rm someImportedFile.js && sleep 2 && git checkout someImportedFile.js
154154 // ```
155- ( isScriptFile ( file ) && getVikeConfigError ( ) && ! existsInViteModuleGraph ( file , moduleGraph ) )
155+ ( isScriptFile ( file ) && getVikeConfigError ( ) )
156156 ) {
157157 reloadVikeConfig ( )
158- return
159- }
160-
161- // Vike runtime code => let Vite handle it
162- if ( isAppFile ?. isRuntimeDependency ) {
163- assert ( existsInViteModuleGraph ( file , moduleGraph ) )
164- return
165158 }
166159}
167160
168161async function isAppDependency ( filePathAbsoluteFilesystem : string , moduleGraph : ModuleGraph ) {
162+ const isAppFile : Partial < { isConfigDependency : boolean ; isRuntimeDependency : boolean } > = { }
163+
169164 // =============================
170165 // { isConfigDependency: false }
171166 // =============================
@@ -178,7 +173,7 @@ async function isAppDependency(filePathAbsoluteFilesystem: string, moduleGraph:
178173 if ( vikeConfigObject ) {
179174 const { _vikeConfigDependencies : vikeConfigDependencies } = vikeConfigObject
180175 vikeConfigDependencies . forEach ( ( f ) => assertPosixPath ( f ) )
181- if ( vikeConfigDependencies . has ( filePathAbsoluteFilesystem ) ) return { isConfigDependency : true }
176+ isAppFile . isConfigDependency = vikeConfigDependencies . has ( filePathAbsoluteFilesystem )
182177 }
183178
184179 // =============================
@@ -188,21 +183,9 @@ async function isAppDependency(filePathAbsoluteFilesystem: string, moduleGraph:
188183 // - They're included in Vite's module graph.
189184 // - They never modify Vike's virtual files.
190185 // - Same for all `+data.js` transitive dependencies.
191- const importersTransitive = getImportersTransitive ( filePathAbsoluteFilesystem , moduleGraph )
192- const isPlusValueFileDependency = Array . from ( importersTransitive ) . some (
193- ( importer ) => importer . file && isPlusFile ( importer . file ) ,
194- )
195- if ( isPlusValueFileDependency ) return { isRuntimeDependency : true }
186+ isAppFile . isRuntimeDependency = existsInViteModuleGraph ( filePathAbsoluteFilesystem , moduleGraph )
196187
197- // File unrelated to the user's Vite/Vike app, for example:
198- // package.json
199- // .github/workflows/ci.yml
200- // migrations/migration-0123.ts
201- // ...
202- /* TO-DO/eventually: this assert should be true?
203- assert(!existsInViteModuleGraph(filePathAbsoluteFilesystem, moduleGraph))
204- //*/
205- return null
188+ return isAppFile
206189}
207190
208191function reloadConfig (
@@ -246,35 +229,3 @@ function getVikeVirtualFiles(server: ViteDevServer): ModuleNode[] {
246229function existsInViteModuleGraph ( file : string , moduleGraph : ModuleGraph ) : boolean {
247230 return ! ! moduleGraph . getModulesByFile ( file )
248231}
249-
250- // Get all ancestors in the module graph. Includes the module itself.
251- function getImportersTransitive ( file : string , moduleGraph : ModuleGraph ) : Set < ModuleNode > {
252- const importers = new Set < ModuleNode > ( )
253- const mods = moduleGraph . getModulesByFile ( file )
254- if ( ! mods ) return importers
255-
256- for ( const mod of mods ) {
257- getModuleImporters ( mod ) . forEach ( ( importer ) => {
258- if ( importer ) importers . add ( importer )
259- } )
260- }
261-
262- return importers
263- }
264- function getModuleImporters ( mod : ModuleNode , seen : Set < ModuleNode > = new Set ( ) ) : Set < ModuleNode > {
265- if ( seen . has ( mod ) ) return new Set ( )
266- seen . add ( mod )
267-
268- const importers = new Set < ModuleNode > ( )
269- if ( mod . id ) importers . add ( mod )
270-
271- // Traverse through the importers (modules that import this module)
272- for ( const importer of mod . importers ) {
273- if ( importer . id ) importers . add ( importer )
274- getModuleImporters ( importer , seen ) . forEach ( ( importerTransitive ) => {
275- if ( importerTransitive ) importers . add ( importerTransitive )
276- } )
277- }
278-
279- return importers
280- }
0 commit comments