Skip to content

Commit 2046ec4

Browse files
committed
refactor: make invalidateModule function in DevEnvironment a method
1 parent 2ec3177 commit 2046ec4

File tree

1 file changed

+31
-34
lines changed

1 file changed

+31
-34
lines changed

packages/vite/src/node/server/environment.ts

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export class DevEnvironment extends BaseEnvironment {
138138
this.hot.on(
139139
'vite:invalidate',
140140
async ({ path, message, firstInvalidatedBy }) => {
141-
invalidateModule(this, {
141+
this.invalidateModule({
142142
path,
143143
message,
144144
firstInvalidatedBy,
@@ -239,6 +239,36 @@ export class DevEnvironment extends BaseEnvironment {
239239
}
240240
}
241241

242+
private invalidateModule(m: {
243+
path: string
244+
message?: string
245+
firstInvalidatedBy: string
246+
}): void {
247+
const mod = this.moduleGraph.urlToModuleMap.get(m.path)
248+
if (
249+
mod &&
250+
mod.isSelfAccepting &&
251+
mod.lastHMRTimestamp > 0 &&
252+
!mod.lastHMRInvalidationReceived
253+
) {
254+
mod.lastHMRInvalidationReceived = true
255+
this.logger.info(
256+
colors.yellow(`hmr invalidate `) +
257+
colors.dim(m.path) +
258+
(m.message ? ` ${m.message}` : ''),
259+
{ timestamp: true },
260+
)
261+
const file = getShortName(mod.file!, this.config.root)
262+
updateModules(
263+
this,
264+
file,
265+
[...mod.importers],
266+
mod.lastHMRTimestamp,
267+
m.firstInvalidatedBy,
268+
)
269+
}
270+
}
271+
242272
async close(): Promise<void> {
243273
this._closing = true
244274

@@ -280,39 +310,6 @@ export class DevEnvironment extends BaseEnvironment {
280310
}
281311
}
282312

283-
function invalidateModule(
284-
environment: DevEnvironment,
285-
m: {
286-
path: string
287-
message?: string
288-
firstInvalidatedBy: string
289-
},
290-
) {
291-
const mod = environment.moduleGraph.urlToModuleMap.get(m.path)
292-
if (
293-
mod &&
294-
mod.isSelfAccepting &&
295-
mod.lastHMRTimestamp > 0 &&
296-
!mod.lastHMRInvalidationReceived
297-
) {
298-
mod.lastHMRInvalidationReceived = true
299-
environment.logger.info(
300-
colors.yellow(`hmr invalidate `) +
301-
colors.dim(m.path) +
302-
(m.message ? ` ${m.message}` : ''),
303-
{ timestamp: true },
304-
)
305-
const file = getShortName(mod.file!, environment.config.root)
306-
updateModules(
307-
environment,
308-
file,
309-
[...mod.importers],
310-
mod.lastHMRTimestamp,
311-
m.firstInvalidatedBy,
312-
)
313-
}
314-
}
315-
316313
const callCrawlEndIfIdleAfterMs = 50
317314

318315
interface CrawlEndFinder {

0 commit comments

Comments
 (0)