MCPcopy
hub / github.com/vitejs/vite / updateModules

Function updateModules

packages/vite/src/node/server/hmr.ts:673–785  ·  view source on GitHub ↗
(
  environment: DevEnvironment,
  file: string,
  modules: EnvironmentModuleNode[],
  timestamp: number,
  firstInvalidatedBy?: string,
)

Source from the content-addressed store, hash-verified

671type HasDeadEnd = string | boolean
672
673export function updateModules(
674 environment: DevEnvironment,
675 file: string,
676 modules: EnvironmentModuleNode[],
677 timestamp: number,
678 firstInvalidatedBy?: string,
679): void {
680 const { hot } = environment
681 const updates: Update[] = []
682 const invalidatedModules = new Set<EnvironmentModuleNode>()
683 const traversedModules = new Set<EnvironmentModuleNode>()
684 // Modules could be empty if a root module is invalidated via import.meta.hot.invalidate()
685 let needFullReload: HasDeadEnd = modules.length === 0
686
687 for (const mod of modules) {
688 const boundaries: PropagationBoundary[] = []
689 const hasDeadEnd = propagateUpdate(mod, traversedModules, boundaries)
690
691 environment.moduleGraph.invalidateModule(
692 mod,
693 invalidatedModules,
694 timestamp,
695 true,
696 )
697
698 if (needFullReload) {
699 continue
700 }
701
702 if (hasDeadEnd) {
703 needFullReload = hasDeadEnd
704 continue
705 }
706
707 // If import.meta.hot.invalidate was called already on that module for the same update,
708 // it means any importer of that module can't hot update. We should fallback to full reload.
709 if (
710 firstInvalidatedBy &&
711 boundaries.some(
712 ({ acceptedVia }) =>
713 normalizeHmrUrl(acceptedVia.url) === firstInvalidatedBy,
714 )
715 ) {
716 needFullReload = 'circular import invalidate'
717 continue
718 }
719
720 updates.push(
721 ...boundaries.map(
722 ({ boundary, acceptedVia, isWithinCircularImport }) => ({
723 type: `${boundary.type}-update` as const,
724 timestamp,
725 path: normalizeHmrUrl(boundary.url),
726 acceptedPath: normalizeHmrUrl(acceptedVia.url),
727 explicitImportRequired:
728 boundary.type === 'js'
729 ? isExplicitImportRequired(acceptedVia.url)
730 : false,

Callers 4

reloadModuleFunction · 0.90
reloadModuleMethod · 0.90
invalidateModuleMethod · 0.90
hmrFunction · 0.85

Calls 8

isExplicitImportRequiredFunction · 0.90
propagateUpdateFunction · 0.85
normalizeHmrUrlFunction · 0.85
infoMethod · 0.65
sendMethod · 0.65
resolveMethod · 0.65
invalidateModuleMethod · 0.45

Tested by

no test coverage detected