Skip to content

Commit ce1c66c

Browse files
committed
refactor: make invalidateModule function in DevEnvironment a method
1 parent 68151ac commit ce1c66c

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
@@ -137,7 +137,7 @@ export class DevEnvironment extends BaseEnvironment {
137137
this.hot.on(
138138
'vite:invalidate',
139139
async ({ path, message, firstInvalidatedBy }) => {
140-
invalidateModule(this, {
140+
this.invalidateModule({
141141
path,
142142
message,
143143
firstInvalidatedBy,
@@ -235,6 +235,36 @@ export class DevEnvironment extends BaseEnvironment {
235235
}
236236
}
237237

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

@@ -276,39 +306,6 @@ export class DevEnvironment extends BaseEnvironment {
276306
}
277307
}
278308

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

314311
interface CrawlEndFinder {

0 commit comments

Comments
 (0)