@ -2,6 +2,7 @@ import { isMatch } from 'micromatch'
import path , { dirname , resolve } from 'node:path'
import { glob } from 'tinyglobby'
import {
type EnvironmentModuleNode ,
type Plugin ,
type ViteDevServer ,
loadConfigFromFile ,
@ -122,44 +123,27 @@ export const staticDataPlugin: Plugin = {
}
} ,
transform ( _code , id ) {
if ( server && loaderMatch . test ( id ) && '_importGlobMap' in server ) {
// register this module as a glob importer
const { watch } = idToLoaderModulesMap [ id ] !
if ( watch ) {
; ( server as any ) . _importGlobMap . set (
id ,
[ Array . isArray ( watch ) ? watch : [ watch ] ] . map ( ( globs ) = > {
const affirmed : string [ ] = [ ]
const negated : string [ ] = [ ]
for ( const glob of globs ) {
; ( glob [ 0 ] === '!' ? negated : affirmed ) . push ( glob )
}
return { affirmed , negated }
} )
)
}
}
return null
} ,
hotUpdate ( ctx ) {
if ( ctx . type === 'update' ) return
handleHotUpdate ( ctx ) {
const file = ctx . file
const module s : EnvironmentModuleNode [ ] = [ ]
// dependency of data loader changed
// (note the dep array includes the loader file itself)
if ( file in depToLoaderModuleIdMap ) {
const id = depToLoaderModuleIdMap [ file ] !
delete idToLoaderModulesMap [ id ]
ctx . module s.push ( server . module Graph.getModuleById ( id ) ! )
module s.push ( this . environment . module Graph.getModuleById ( id ) ! )
}
for ( const id in idToLoaderModulesMap ) {
const { watch } = idToLoaderModulesMap [ id ] !
if ( watch && isMatch ( file , watch ) ) {
ctx . module s.push ( server . module Graph.getModuleById ( id ) ! )
module s.push ( this . environment . module Graph.getModuleById ( id ) ! )
}
}
return module s.length > 0 ? [ . . . ctx . module s , . . . module s ] : undefined
}
}