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

Method invalidateModule

packages/vite/src/node/server/bundledDev.ts:225–277  ·  view source on GitHub ↗
(
    m: {
      path: string
      message?: string
      firstInvalidatedBy: string
    },
    client: NormalizedHotChannelClient,
  )

Source from the content-addressed store, hash-verified

223 }
224
225 async invalidateModule(
226 m: {
227 path: string
228 message?: string
229 firstInvalidatedBy: string
230 },
231 client: NormalizedHotChannelClient,
232 ): Promise<void> {
233 const invalidateCalledModules = this.invalidateCalledModules.get(client)
234 if (invalidateCalledModules?.has(m.path)) {
235 debug?.(
236 `INVALIDATE: invalidate received from ${m.path}, but ignored because it was already invalidated`,
237 )
238 return
239 }
240
241 debug?.(`INVALIDATE: invalidate received from ${m.path}, re-triggering HMR`)
242 if (!invalidateCalledModules) {
243 this.invalidateCalledModules.set(client, new Set([]))
244 }
245 this.invalidateCalledModules.get(client)!.add(m.path)
246
247 let update: BindingClientHmrUpdate['update'] | undefined
248 try {
249 const _update = await this.devEngine.invalidate(
250 m.path,
251 m.firstInvalidatedBy,
252 )
253 update = _update.find(
254 (u) => this.clients.get(u.clientId) === client,
255 )?.update
256 } catch (e) {
257 client.send({
258 type: 'error',
259 err: prepareError(e as Error),
260 })
261 return
262 }
263 if (!update) return
264
265 if (update.type === 'Patch') {
266 this.environment.logger.info(
267 colors.yellow(`hmr invalidate `) +
268 colors.dim(m.path) +
269 (m.message ? ` ${m.message}` : ''),
270 { timestamp: true },
271 )
272 }
273
274 this.handleHmrOutput(client, [m.path], update, {
275 firstInvalidatedBy: m.firstInvalidatedBy,
276 })
277 }
278
279 async triggerBundleRegenerationIfStale(): Promise<boolean> {
280 const bundleState = await this.devEngine.getBundleState()

Callers 5

server-hmr.spec.tsFile · 0.45
updateModulesFunction · 0.45
devHtmlHookFunction · 0.45

Calls 9

handleHmrOutputMethod · 0.95
prepareErrorFunction · 0.90
hasMethod · 0.80
addMethod · 0.80
invalidateMethod · 0.65
sendMethod · 0.65
infoMethod · 0.65
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected