Skip to content

Commit 49ba2ac

Browse files
committed
refactor: make invalidateModule function in DevEnvironment a method
1 parent 9479176 commit 49ba2ac

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
@@ -135,7 +135,7 @@ export class DevEnvironment extends BaseEnvironment {
135135
this.hot.on(
136136
'vite:invalidate',
137137
async ({ path, message, firstInvalidatedBy }) => {
138-
invalidateModule(this, {
138+
this.invalidateModule({
139139
path,
140140
message,
141141
firstInvalidatedBy,
@@ -232,6 +232,36 @@ export class DevEnvironment extends BaseEnvironment {
232232
}
233233
}
234234

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

@@ -273,39 +303,6 @@ export class DevEnvironment extends BaseEnvironment {
273303
}
274304
}
275305

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

311308
interface CrawlEndFinder {

0 commit comments

Comments
 (0)