vite 5.0.4 → 5.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +22 -0
- package/client.d.ts +4 -1
- package/dist/client/client.mjs +198 -168
- package/dist/client/client.mjs.map +1 -1
- package/dist/node/chunks/{dep-GiiHpyM6.js → dep-IrrVD4is.js} +1 -1
- package/dist/node/chunks/{dep-4RECYSE1.js → dep-MF_y65BT.js} +211 -135
- package/dist/node/chunks/{dep-nbvvoiwS.js → dep-mpgFWQ-7.js} +1 -1
- package/dist/node/cli.js +5 -5
- package/dist/node/constants.js +1 -0
- package/dist/node/index.d.ts +2 -1
- package/dist/node/index.js +2 -2
- package/dist/node-cjs/publicUtils.cjs +2 -2
- package/package.json +6 -6
package/LICENSE.md
CHANGED
|
@@ -579,6 +579,28 @@ License: MIT
|
|
|
579
579
|
By: Rich Harris
|
|
580
580
|
Repository: rollup/plugins
|
|
581
581
|
|
|
582
|
+
> The MIT License (MIT)
|
|
583
|
+
>
|
|
584
|
+
> Copyright (c) 2019 RollupJS Plugin Contributors (https://github.com/rollup/plugins/graphs/contributors)
|
|
585
|
+
>
|
|
586
|
+
> Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
587
|
+
> of this software and associated documentation files (the "Software"), to deal
|
|
588
|
+
> in the Software without restriction, including without limitation the rights
|
|
589
|
+
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
590
|
+
> copies of the Software, and to permit persons to whom the Software is
|
|
591
|
+
> furnished to do so, subject to the following conditions:
|
|
592
|
+
>
|
|
593
|
+
> The above copyright notice and this permission notice shall be included in
|
|
594
|
+
> all copies or substantial portions of the Software.
|
|
595
|
+
>
|
|
596
|
+
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
597
|
+
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
598
|
+
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
599
|
+
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
600
|
+
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
601
|
+
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
602
|
+
> THE SOFTWARE.
|
|
603
|
+
|
|
582
604
|
---------------------------------------
|
|
583
605
|
|
|
584
606
|
## acorn
|
package/client.d.ts
CHANGED
|
@@ -128,11 +128,14 @@ declare module '*.aac' {
|
|
|
128
128
|
const src: string
|
|
129
129
|
export default src
|
|
130
130
|
}
|
|
131
|
-
|
|
132
131
|
declare module '*.opus' {
|
|
133
132
|
const src: string
|
|
134
133
|
export default src
|
|
135
134
|
}
|
|
135
|
+
declare module '*.mov' {
|
|
136
|
+
const src: string
|
|
137
|
+
export default src
|
|
138
|
+
}
|
|
136
139
|
|
|
137
140
|
// fonts
|
|
138
141
|
declare module '*.woff' {
|
package/dist/client/client.mjs
CHANGED
|
@@ -1,5 +1,187 @@
|
|
|
1
1
|
import '@vite/env';
|
|
2
2
|
|
|
3
|
+
class HMRContext {
|
|
4
|
+
constructor(ownerPath, hmrClient, connection) {
|
|
5
|
+
this.ownerPath = ownerPath;
|
|
6
|
+
this.hmrClient = hmrClient;
|
|
7
|
+
this.connection = connection;
|
|
8
|
+
if (!hmrClient.dataMap.has(ownerPath)) {
|
|
9
|
+
hmrClient.dataMap.set(ownerPath, {});
|
|
10
|
+
}
|
|
11
|
+
// when a file is hot updated, a new context is created
|
|
12
|
+
// clear its stale callbacks
|
|
13
|
+
const mod = hmrClient.hotModulesMap.get(ownerPath);
|
|
14
|
+
if (mod) {
|
|
15
|
+
mod.callbacks = [];
|
|
16
|
+
}
|
|
17
|
+
// clear stale custom event listeners
|
|
18
|
+
const staleListeners = hmrClient.ctxToListenersMap.get(ownerPath);
|
|
19
|
+
if (staleListeners) {
|
|
20
|
+
for (const [event, staleFns] of staleListeners) {
|
|
21
|
+
const listeners = hmrClient.customListenersMap.get(event);
|
|
22
|
+
if (listeners) {
|
|
23
|
+
hmrClient.customListenersMap.set(event, listeners.filter((l) => !staleFns.includes(l)));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
this.newListeners = new Map();
|
|
28
|
+
hmrClient.ctxToListenersMap.set(ownerPath, this.newListeners);
|
|
29
|
+
}
|
|
30
|
+
get data() {
|
|
31
|
+
return this.hmrClient.dataMap.get(this.ownerPath);
|
|
32
|
+
}
|
|
33
|
+
accept(deps, callback) {
|
|
34
|
+
if (typeof deps === 'function' || !deps) {
|
|
35
|
+
// self-accept: hot.accept(() => {})
|
|
36
|
+
this.acceptDeps([this.ownerPath], ([mod]) => deps === null || deps === void 0 ? void 0 : deps(mod));
|
|
37
|
+
}
|
|
38
|
+
else if (typeof deps === 'string') {
|
|
39
|
+
// explicit deps
|
|
40
|
+
this.acceptDeps([deps], ([mod]) => callback === null || callback === void 0 ? void 0 : callback(mod));
|
|
41
|
+
}
|
|
42
|
+
else if (Array.isArray(deps)) {
|
|
43
|
+
this.acceptDeps(deps, callback);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
throw new Error(`invalid hot.accept() usage.`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// export names (first arg) are irrelevant on the client side, they're
|
|
50
|
+
// extracted in the server for propagation
|
|
51
|
+
acceptExports(_, callback) {
|
|
52
|
+
this.acceptDeps([this.ownerPath], ([mod]) => callback === null || callback === void 0 ? void 0 : callback(mod));
|
|
53
|
+
}
|
|
54
|
+
dispose(cb) {
|
|
55
|
+
this.hmrClient.disposeMap.set(this.ownerPath, cb);
|
|
56
|
+
}
|
|
57
|
+
prune(cb) {
|
|
58
|
+
this.hmrClient.pruneMap.set(this.ownerPath, cb);
|
|
59
|
+
}
|
|
60
|
+
// Kept for backward compatibility (#11036)
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
62
|
+
decline() { }
|
|
63
|
+
invalidate(message) {
|
|
64
|
+
this.hmrClient.notifyListeners('vite:invalidate', {
|
|
65
|
+
path: this.ownerPath,
|
|
66
|
+
message,
|
|
67
|
+
});
|
|
68
|
+
this.send('vite:invalidate', { path: this.ownerPath, message });
|
|
69
|
+
this.hmrClient.logger.debug(`[vite] invalidate ${this.ownerPath}${message ? `: ${message}` : ''}`);
|
|
70
|
+
}
|
|
71
|
+
on(event, cb) {
|
|
72
|
+
const addToMap = (map) => {
|
|
73
|
+
const existing = map.get(event) || [];
|
|
74
|
+
existing.push(cb);
|
|
75
|
+
map.set(event, existing);
|
|
76
|
+
};
|
|
77
|
+
addToMap(this.hmrClient.customListenersMap);
|
|
78
|
+
addToMap(this.newListeners);
|
|
79
|
+
}
|
|
80
|
+
off(event, cb) {
|
|
81
|
+
const removeFromMap = (map) => {
|
|
82
|
+
const existing = map.get(event);
|
|
83
|
+
if (existing === undefined) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const pruned = existing.filter((l) => l !== cb);
|
|
87
|
+
if (pruned.length === 0) {
|
|
88
|
+
map.delete(event);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
map.set(event, pruned);
|
|
92
|
+
};
|
|
93
|
+
removeFromMap(this.hmrClient.customListenersMap);
|
|
94
|
+
removeFromMap(this.newListeners);
|
|
95
|
+
}
|
|
96
|
+
send(event, data) {
|
|
97
|
+
this.connection.addBuffer(JSON.stringify({ type: 'custom', event, data }));
|
|
98
|
+
this.connection.send();
|
|
99
|
+
}
|
|
100
|
+
acceptDeps(deps, callback = () => { }) {
|
|
101
|
+
const mod = this.hmrClient.hotModulesMap.get(this.ownerPath) || {
|
|
102
|
+
id: this.ownerPath,
|
|
103
|
+
callbacks: [],
|
|
104
|
+
};
|
|
105
|
+
mod.callbacks.push({
|
|
106
|
+
deps,
|
|
107
|
+
fn: callback,
|
|
108
|
+
});
|
|
109
|
+
this.hmrClient.hotModulesMap.set(this.ownerPath, mod);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
class HMRClient {
|
|
113
|
+
constructor(logger,
|
|
114
|
+
// this allows up to implement reloading via different methods depending on the environment
|
|
115
|
+
importUpdatedModule) {
|
|
116
|
+
this.logger = logger;
|
|
117
|
+
this.importUpdatedModule = importUpdatedModule;
|
|
118
|
+
this.hotModulesMap = new Map();
|
|
119
|
+
this.disposeMap = new Map();
|
|
120
|
+
this.pruneMap = new Map();
|
|
121
|
+
this.dataMap = new Map();
|
|
122
|
+
this.customListenersMap = new Map();
|
|
123
|
+
this.ctxToListenersMap = new Map();
|
|
124
|
+
}
|
|
125
|
+
async notifyListeners(event, data) {
|
|
126
|
+
const cbs = this.customListenersMap.get(event);
|
|
127
|
+
if (cbs) {
|
|
128
|
+
await Promise.allSettled(cbs.map((cb) => cb(data)));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// After an HMR update, some modules are no longer imported on the page
|
|
132
|
+
// but they may have left behind side effects that need to be cleaned up
|
|
133
|
+
// (.e.g style injections)
|
|
134
|
+
// TODO Trigger their dispose callbacks.
|
|
135
|
+
prunePaths(paths) {
|
|
136
|
+
paths.forEach((path) => {
|
|
137
|
+
const fn = this.pruneMap.get(path);
|
|
138
|
+
if (fn) {
|
|
139
|
+
fn(this.dataMap.get(path));
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
warnFailedUpdate(err, path) {
|
|
144
|
+
if (!err.message.includes('fetch')) {
|
|
145
|
+
this.logger.error(err);
|
|
146
|
+
}
|
|
147
|
+
this.logger.error(`[hmr] Failed to reload ${path}. ` +
|
|
148
|
+
`This could be due to syntax errors or importing non-existent ` +
|
|
149
|
+
`modules. (see errors above)`);
|
|
150
|
+
}
|
|
151
|
+
async fetchUpdate(update) {
|
|
152
|
+
const { path, acceptedPath } = update;
|
|
153
|
+
const mod = this.hotModulesMap.get(path);
|
|
154
|
+
if (!mod) {
|
|
155
|
+
// In a code-splitting project,
|
|
156
|
+
// it is common that the hot-updating module is not loaded yet.
|
|
157
|
+
// https://github.com/vitejs/vite/issues/721
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
let fetchedModule;
|
|
161
|
+
const isSelfUpdate = path === acceptedPath;
|
|
162
|
+
// determine the qualified callbacks before we re-import the modules
|
|
163
|
+
const qualifiedCallbacks = mod.callbacks.filter(({ deps }) => deps.includes(acceptedPath));
|
|
164
|
+
if (isSelfUpdate || qualifiedCallbacks.length > 0) {
|
|
165
|
+
const disposer = this.disposeMap.get(acceptedPath);
|
|
166
|
+
if (disposer)
|
|
167
|
+
await disposer(this.dataMap.get(acceptedPath));
|
|
168
|
+
try {
|
|
169
|
+
fetchedModule = await this.importUpdatedModule(update);
|
|
170
|
+
}
|
|
171
|
+
catch (e) {
|
|
172
|
+
this.warnFailedUpdate(e, acceptedPath);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return () => {
|
|
176
|
+
for (const { deps, fn } of qualifiedCallbacks) {
|
|
177
|
+
fn(deps.map((dep) => (dep === acceptedPath ? fetchedModule : undefined)));
|
|
178
|
+
}
|
|
179
|
+
const loggedPath = isSelfUpdate ? path : `${acceptedPath} via ${path}`;
|
|
180
|
+
this.logger.debug(`[vite] hot updated: ${loggedPath}`);
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
3
185
|
const hmrConfigName = __HMR_CONFIG_NAME__;
|
|
4
186
|
const base$1 = __BASE__ || '/';
|
|
5
187
|
// set :host styles to make playwright detect the element as visible
|
|
@@ -305,14 +487,6 @@ function setupWebSocket(protocol, hostAndPath, onCloseWithoutOpen) {
|
|
|
305
487
|
});
|
|
306
488
|
return socket;
|
|
307
489
|
}
|
|
308
|
-
function warnFailedFetch(err, path) {
|
|
309
|
-
if (!err.message.match('fetch')) {
|
|
310
|
-
console.error(err);
|
|
311
|
-
}
|
|
312
|
-
console.error(`[hmr] Failed to reload ${path}. ` +
|
|
313
|
-
`This could be due to syntax errors or importing non-existent ` +
|
|
314
|
-
`modules. (see errors above)`);
|
|
315
|
-
}
|
|
316
490
|
function cleanUrl(pathname) {
|
|
317
491
|
const url = new URL(pathname, location.toString());
|
|
318
492
|
url.searchParams.delete('direct');
|
|
@@ -333,6 +507,14 @@ const debounceReload = (time) => {
|
|
|
333
507
|
};
|
|
334
508
|
};
|
|
335
509
|
const pageReload = debounceReload(50);
|
|
510
|
+
const hmrClient = new HMRClient(console, async function importUpdatedModule({ acceptedPath, timestamp, explicitImportRequired, }) {
|
|
511
|
+
const [acceptedPathWithoutQuery, query] = acceptedPath.split(`?`);
|
|
512
|
+
return await import(
|
|
513
|
+
/* @vite-ignore */
|
|
514
|
+
base +
|
|
515
|
+
acceptedPathWithoutQuery.slice(1) +
|
|
516
|
+
`?${explicitImportRequired ? 'import&' : ''}t=${timestamp}${query ? `&${query}` : ''}`);
|
|
517
|
+
});
|
|
336
518
|
async function handleMessage(payload) {
|
|
337
519
|
switch (payload.type) {
|
|
338
520
|
case 'connected':
|
|
@@ -362,7 +544,7 @@ async function handleMessage(payload) {
|
|
|
362
544
|
}
|
|
363
545
|
await Promise.all(payload.updates.map(async (update) => {
|
|
364
546
|
if (update.type === 'js-update') {
|
|
365
|
-
return queueUpdate(fetchUpdate(update));
|
|
547
|
+
return queueUpdate(hmrClient.fetchUpdate(update));
|
|
366
548
|
}
|
|
367
549
|
// css-update
|
|
368
550
|
// this is only sent when a css file referenced with <link> is updated
|
|
@@ -421,16 +603,7 @@ async function handleMessage(payload) {
|
|
|
421
603
|
break;
|
|
422
604
|
case 'prune':
|
|
423
605
|
notifyListeners('vite:beforePrune', payload);
|
|
424
|
-
|
|
425
|
-
// but they may have left behind side effects that need to be cleaned up
|
|
426
|
-
// (.e.g style injections)
|
|
427
|
-
// TODO Trigger their dispose callbacks.
|
|
428
|
-
payload.paths.forEach((path) => {
|
|
429
|
-
const fn = pruneMap.get(path);
|
|
430
|
-
if (fn) {
|
|
431
|
-
fn(dataMap.get(path));
|
|
432
|
-
}
|
|
433
|
-
});
|
|
606
|
+
hmrClient.prunePaths(payload.paths);
|
|
434
607
|
break;
|
|
435
608
|
case 'error': {
|
|
436
609
|
notifyListeners('vite:error', payload);
|
|
@@ -450,10 +623,7 @@ async function handleMessage(payload) {
|
|
|
450
623
|
}
|
|
451
624
|
}
|
|
452
625
|
function notifyListeners(event, data) {
|
|
453
|
-
|
|
454
|
-
if (cbs) {
|
|
455
|
-
cbs.forEach((cb) => cb(data));
|
|
456
|
-
}
|
|
626
|
+
hmrClient.notifyListeners(event, data);
|
|
457
627
|
}
|
|
458
628
|
const enableOverlay = __HMR_ENABLE_OVERLAY__;
|
|
459
629
|
function createErrorOverlay(err) {
|
|
@@ -580,161 +750,21 @@ function removeStyle(id) {
|
|
|
580
750
|
sheetsMap.delete(id);
|
|
581
751
|
}
|
|
582
752
|
}
|
|
583
|
-
async function fetchUpdate({ path, acceptedPath, timestamp, explicitImportRequired, }) {
|
|
584
|
-
const mod = hotModulesMap.get(path);
|
|
585
|
-
if (!mod) {
|
|
586
|
-
// In a code-splitting project,
|
|
587
|
-
// it is common that the hot-updating module is not loaded yet.
|
|
588
|
-
// https://github.com/vitejs/vite/issues/721
|
|
589
|
-
return;
|
|
590
|
-
}
|
|
591
|
-
let fetchedModule;
|
|
592
|
-
const isSelfUpdate = path === acceptedPath;
|
|
593
|
-
// determine the qualified callbacks before we re-import the modules
|
|
594
|
-
const qualifiedCallbacks = mod.callbacks.filter(({ deps }) => deps.includes(acceptedPath));
|
|
595
|
-
if (isSelfUpdate || qualifiedCallbacks.length > 0) {
|
|
596
|
-
const disposer = disposeMap.get(acceptedPath);
|
|
597
|
-
if (disposer)
|
|
598
|
-
await disposer(dataMap.get(acceptedPath));
|
|
599
|
-
const [acceptedPathWithoutQuery, query] = acceptedPath.split(`?`);
|
|
600
|
-
try {
|
|
601
|
-
fetchedModule = await import(
|
|
602
|
-
/* @vite-ignore */
|
|
603
|
-
base +
|
|
604
|
-
acceptedPathWithoutQuery.slice(1) +
|
|
605
|
-
`?${explicitImportRequired ? 'import&' : ''}t=${timestamp}${query ? `&${query}` : ''}`);
|
|
606
|
-
}
|
|
607
|
-
catch (e) {
|
|
608
|
-
warnFailedFetch(e, acceptedPath);
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
return () => {
|
|
612
|
-
for (const { deps, fn } of qualifiedCallbacks) {
|
|
613
|
-
fn(deps.map((dep) => (dep === acceptedPath ? fetchedModule : undefined)));
|
|
614
|
-
}
|
|
615
|
-
const loggedPath = isSelfUpdate ? path : `${acceptedPath} via ${path}`;
|
|
616
|
-
console.debug(`[vite] hot updated: ${loggedPath}`);
|
|
617
|
-
};
|
|
618
|
-
}
|
|
619
753
|
function sendMessageBuffer() {
|
|
620
754
|
if (socket.readyState === 1) {
|
|
621
755
|
messageBuffer.forEach((msg) => socket.send(msg));
|
|
622
756
|
messageBuffer.length = 0;
|
|
623
757
|
}
|
|
624
758
|
}
|
|
625
|
-
const hotModulesMap = new Map();
|
|
626
|
-
const disposeMap = new Map();
|
|
627
|
-
const pruneMap = new Map();
|
|
628
|
-
const dataMap = new Map();
|
|
629
|
-
const customListenersMap = new Map();
|
|
630
|
-
const ctxToListenersMap = new Map();
|
|
631
759
|
function createHotContext(ownerPath) {
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
// when a file is hot updated, a new context is created
|
|
636
|
-
// clear its stale callbacks
|
|
637
|
-
const mod = hotModulesMap.get(ownerPath);
|
|
638
|
-
if (mod) {
|
|
639
|
-
mod.callbacks = [];
|
|
640
|
-
}
|
|
641
|
-
// clear stale custom event listeners
|
|
642
|
-
const staleListeners = ctxToListenersMap.get(ownerPath);
|
|
643
|
-
if (staleListeners) {
|
|
644
|
-
for (const [event, staleFns] of staleListeners) {
|
|
645
|
-
const listeners = customListenersMap.get(event);
|
|
646
|
-
if (listeners) {
|
|
647
|
-
customListenersMap.set(event, listeners.filter((l) => !staleFns.includes(l)));
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
const newListeners = new Map();
|
|
652
|
-
ctxToListenersMap.set(ownerPath, newListeners);
|
|
653
|
-
function acceptDeps(deps, callback = () => { }) {
|
|
654
|
-
const mod = hotModulesMap.get(ownerPath) || {
|
|
655
|
-
id: ownerPath,
|
|
656
|
-
callbacks: [],
|
|
657
|
-
};
|
|
658
|
-
mod.callbacks.push({
|
|
659
|
-
deps,
|
|
660
|
-
fn: callback,
|
|
661
|
-
});
|
|
662
|
-
hotModulesMap.set(ownerPath, mod);
|
|
663
|
-
}
|
|
664
|
-
const hot = {
|
|
665
|
-
get data() {
|
|
666
|
-
return dataMap.get(ownerPath);
|
|
667
|
-
},
|
|
668
|
-
accept(deps, callback) {
|
|
669
|
-
if (typeof deps === 'function' || !deps) {
|
|
670
|
-
// self-accept: hot.accept(() => {})
|
|
671
|
-
acceptDeps([ownerPath], ([mod]) => deps === null || deps === void 0 ? void 0 : deps(mod));
|
|
672
|
-
}
|
|
673
|
-
else if (typeof deps === 'string') {
|
|
674
|
-
// explicit deps
|
|
675
|
-
acceptDeps([deps], ([mod]) => callback === null || callback === void 0 ? void 0 : callback(mod));
|
|
676
|
-
}
|
|
677
|
-
else if (Array.isArray(deps)) {
|
|
678
|
-
acceptDeps(deps, callback);
|
|
679
|
-
}
|
|
680
|
-
else {
|
|
681
|
-
throw new Error(`invalid hot.accept() usage.`);
|
|
682
|
-
}
|
|
760
|
+
return new HMRContext(ownerPath, hmrClient, {
|
|
761
|
+
addBuffer(message) {
|
|
762
|
+
messageBuffer.push(message);
|
|
683
763
|
},
|
|
684
|
-
|
|
685
|
-
// extracted in the server for propagation
|
|
686
|
-
acceptExports(_, callback) {
|
|
687
|
-
acceptDeps([ownerPath], ([mod]) => callback === null || callback === void 0 ? void 0 : callback(mod));
|
|
688
|
-
},
|
|
689
|
-
dispose(cb) {
|
|
690
|
-
disposeMap.set(ownerPath, cb);
|
|
691
|
-
},
|
|
692
|
-
prune(cb) {
|
|
693
|
-
pruneMap.set(ownerPath, cb);
|
|
694
|
-
},
|
|
695
|
-
// Kept for backward compatibility (#11036)
|
|
696
|
-
// @ts-expect-error untyped
|
|
697
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
698
|
-
decline() { },
|
|
699
|
-
// tell the server to re-perform hmr propagation from this module as root
|
|
700
|
-
invalidate(message) {
|
|
701
|
-
notifyListeners('vite:invalidate', { path: ownerPath, message });
|
|
702
|
-
this.send('vite:invalidate', { path: ownerPath, message });
|
|
703
|
-
console.debug(`[vite] invalidate ${ownerPath}${message ? `: ${message}` : ''}`);
|
|
704
|
-
},
|
|
705
|
-
// custom events
|
|
706
|
-
on(event, cb) {
|
|
707
|
-
const addToMap = (map) => {
|
|
708
|
-
const existing = map.get(event) || [];
|
|
709
|
-
existing.push(cb);
|
|
710
|
-
map.set(event, existing);
|
|
711
|
-
};
|
|
712
|
-
addToMap(customListenersMap);
|
|
713
|
-
addToMap(newListeners);
|
|
714
|
-
},
|
|
715
|
-
// remove a custom event
|
|
716
|
-
off(event, cb) {
|
|
717
|
-
const removeFromMap = (map) => {
|
|
718
|
-
const existing = map.get(event);
|
|
719
|
-
if (existing === undefined) {
|
|
720
|
-
return;
|
|
721
|
-
}
|
|
722
|
-
const pruned = existing.filter((l) => l !== cb);
|
|
723
|
-
if (pruned.length === 0) {
|
|
724
|
-
map.delete(event);
|
|
725
|
-
return;
|
|
726
|
-
}
|
|
727
|
-
map.set(event, pruned);
|
|
728
|
-
};
|
|
729
|
-
removeFromMap(customListenersMap);
|
|
730
|
-
removeFromMap(newListeners);
|
|
731
|
-
},
|
|
732
|
-
send(event, data) {
|
|
733
|
-
messageBuffer.push(JSON.stringify({ type: 'custom', event, data }));
|
|
764
|
+
send() {
|
|
734
765
|
sendMessageBuffer();
|
|
735
766
|
},
|
|
736
|
-
};
|
|
737
|
-
return hot;
|
|
767
|
+
});
|
|
738
768
|
}
|
|
739
769
|
/**
|
|
740
770
|
* urls here are dynamic import() urls that couldn't be statically analyzed
|