@vxrn/vite-native-client 1.14.4 → 1.14.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/dist/cjs/client.cjs +236 -140
- package/dist/cjs/client.native.js +283 -184
- package/dist/cjs/client.native.js.map +1 -1
- package/dist/cjs/customEvent.cjs +7 -5
- package/dist/cjs/customEvent.native.js +7 -5
- package/dist/cjs/customEvent.native.js.map +1 -1
- package/dist/cjs/hmrPayload.cjs +7 -5
- package/dist/cjs/hmrPayload.native.js +7 -5
- package/dist/cjs/hmrPayload.native.js.map +1 -1
- package/dist/cjs/hot.cjs +7 -5
- package/dist/cjs/hot.native.js +7 -5
- package/dist/cjs/hot.native.js.map +1 -1
- package/dist/cjs/index.cjs +7 -5
- package/dist/cjs/index.native.js +7 -5
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/esm/client.mjs +227 -133
- package/dist/esm/client.mjs.map +1 -1
- package/dist/esm/client.native.js +272 -175
- package/dist/esm/client.native.js.map +1 -1
- package/package.json +2 -2
package/dist/cjs/client.cjs
CHANGED
|
@@ -2,13 +2,15 @@ var __create = Object.create;
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf
|
|
6
|
-
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __copyProps = (to, from, except, desc) => {
|
|
8
|
-
if (from && typeof from
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
10
|
+
get: () => from[key],
|
|
11
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
12
|
+
});
|
|
13
|
+
}
|
|
12
14
|
return to;
|
|
13
15
|
};
|
|
14
16
|
var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__getProtoOf(mod2)) : {}, __copyProps(
|
|
@@ -18,83 +20,98 @@ var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__
|
|
|
18
20
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
19
21
|
isNodeMode || !mod2 || !mod2.__esModule ? __defProp(target, "default", {
|
|
20
22
|
value: mod2,
|
|
21
|
-
enumerable:
|
|
23
|
+
enumerable: true
|
|
22
24
|
}) : target, mod2));
|
|
23
25
|
var import_getDevServer = __toESM(require("react-native/Libraries/Core/Devtools/getDevServer"));
|
|
24
26
|
const importMetaUrl = {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
hostname: "127.0.0.1",
|
|
28
|
+
protocol: "http",
|
|
29
|
+
port: 5173
|
|
30
|
+
};
|
|
31
|
+
const serverHost = __SERVER_HOST__;
|
|
32
|
+
const socketProtocol = __HMR_PROTOCOL__ || (importMetaUrl.protocol === "https:" ? "wss" : "ws");
|
|
33
|
+
const hmrPort = __HMR_PORT__ || 5173;
|
|
32
34
|
let rnDevServerHost;
|
|
33
35
|
try {
|
|
34
36
|
const {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
host
|
|
37
|
+
url: devServerUrl
|
|
38
|
+
} = (0, import_getDevServer.default)();
|
|
39
|
+
const [, host] = devServerUrl.match(/:\/\/([^/]+)/) || [];
|
|
40
|
+
if (host) rnDevServerHost = host;
|
|
39
41
|
} catch (e) {
|
|
40
42
|
console.warn(`[vite-native-client] failed to get react-native dev server url: ${e}`);
|
|
41
43
|
}
|
|
42
|
-
const hmrHost = rnDevServerHost || `${__HMR_HOSTNAME__ || importMetaUrl.hostname}:${hmrPort || importMetaUrl.port}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
const hmrHost = rnDevServerHost || `${__HMR_HOSTNAME__ || importMetaUrl.hostname}:${hmrPort || importMetaUrl.port}`;
|
|
45
|
+
const socketHost = `${hmrHost}${__HMR_BASE__}`;
|
|
46
|
+
const directSocketHost = __HMR_DIRECT_TARGET__;
|
|
47
|
+
const base = __BASE__ || "/";
|
|
48
|
+
const messageBuffer = [];
|
|
47
49
|
let socket;
|
|
48
50
|
try {
|
|
49
51
|
let fallback;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
if (!hmrPort) {
|
|
53
|
+
fallback = () => {
|
|
54
|
+
socket = setupWebSocket(socketProtocol, directSocketHost, () => {
|
|
55
|
+
console.error(`[vite] failed to connect to websocket.
|
|
53
56
|
your current setup:
|
|
54
57
|
(browser) ${JSON.stringify(importMetaUrl)} <--[HTTP]--> ${serverHost} (server)
|
|
55
58
|
(browser) ${socketHost} <--[WebSocket (failing)]--> ${directSocketHost} (server)
|
|
56
59
|
Check out your Vite / network configuration and https://vitejs.dev/config/server-options.html#server-hmr .`);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
});
|
|
61
|
+
socket.addEventListener("open", () => {
|
|
62
|
+
console.info("[vite] Direct websocket connection fallback. Check out https://vitejs.dev/config/server-options.html#server-hmr to remove the previous connection error.");
|
|
63
|
+
}, {
|
|
64
|
+
once: true
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
socket = setupWebSocket(socketProtocol, socketHost, fallback);
|
|
63
69
|
} catch (error) {
|
|
64
70
|
console.error(`[vite] failed to connect to websocket (${error}). `);
|
|
65
71
|
}
|
|
66
72
|
function setupWebSocket(protocol, hostAndPath, onCloseWithoutOpen) {
|
|
67
73
|
let endpoint = `${protocol}://${hostAndPath}`;
|
|
68
|
-
typeof globalThis.__VITE_WS_TOKEN__
|
|
74
|
+
if (typeof globalThis.__VITE_WS_TOKEN__ === "string") {
|
|
75
|
+
endpoint += `?token=${globalThis.__VITE_WS_TOKEN__}`;
|
|
76
|
+
}
|
|
69
77
|
const socket2 = new WebSocket(endpoint, "vite-hmr");
|
|
70
|
-
let isOpened =
|
|
71
|
-
|
|
72
|
-
isOpened =
|
|
78
|
+
let isOpened = false;
|
|
79
|
+
socket2.addEventListener("open", () => {
|
|
80
|
+
isOpened = true;
|
|
81
|
+
notifyListeners("vite:ws:connect", {
|
|
73
82
|
webSocket: socket2
|
|
74
83
|
});
|
|
75
84
|
}, {
|
|
76
|
-
once:
|
|
77
|
-
})
|
|
85
|
+
once: true
|
|
86
|
+
});
|
|
87
|
+
socket2.addEventListener("message", ({
|
|
78
88
|
data
|
|
79
89
|
}) => {
|
|
80
|
-
process.env.DEBUG
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
90
|
+
if (process.env.DEBUG) {
|
|
91
|
+
console.info(" \u2776 hmr ", data);
|
|
92
|
+
}
|
|
93
|
+
handleMessage(JSON.parse(data));
|
|
94
|
+
});
|
|
95
|
+
socket2.addEventListener("error", err => {
|
|
96
|
+
console.info("err" + err["message"] + err["stack"]);
|
|
97
|
+
});
|
|
98
|
+
socket2.addEventListener("close", ({
|
|
84
99
|
wasClean
|
|
85
100
|
}) => {
|
|
86
|
-
if (
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
notifyListeners("vite:ws:disconnect", {
|
|
92
|
-
webSocket: socket2
|
|
93
|
-
}), console.info("[vite] server connection lost. polling for restart..."), waitForSuccessfulPing(protocol, hostAndPath).then(() => {
|
|
94
|
-
console.info("should reload");
|
|
95
|
-
});
|
|
101
|
+
if (wasClean) return;
|
|
102
|
+
if (!isOpened && onCloseWithoutOpen) {
|
|
103
|
+
onCloseWithoutOpen();
|
|
104
|
+
return;
|
|
96
105
|
}
|
|
97
|
-
|
|
106
|
+
notifyListeners("vite:ws:disconnect", {
|
|
107
|
+
webSocket: socket2
|
|
108
|
+
});
|
|
109
|
+
console.info(`[vite] server connection lost. polling for restart...`);
|
|
110
|
+
waitForSuccessfulPing(protocol, hostAndPath).then(() => {
|
|
111
|
+
console.info("should reload");
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
return socket2;
|
|
98
115
|
}
|
|
99
116
|
function warnFailedFetch(err, path2) {
|
|
100
117
|
try {
|
|
@@ -105,31 +122,45 @@ ${err.stack}`);
|
|
|
105
122
|
}
|
|
106
123
|
console.error(`[hmr] Failed to reload ${path2}. This could be due to syntax errors or importing non-existent modules. (see errors above)`);
|
|
107
124
|
}
|
|
108
|
-
let isFirstUpdate =
|
|
125
|
+
let isFirstUpdate = true;
|
|
109
126
|
const debounceReload = time => {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
127
|
+
let timer;
|
|
128
|
+
return () => {
|
|
129
|
+
if (timer) {
|
|
130
|
+
clearTimeout(timer);
|
|
131
|
+
timer = null;
|
|
132
|
+
}
|
|
133
|
+
timer = setTimeout(() => {
|
|
134
|
+
globalThis.__vxrnReloadApp();
|
|
135
|
+
}, time);
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
const pageReload = debounceReload(50);
|
|
118
139
|
async function handleMessage(payload) {
|
|
119
140
|
switch (payload.type) {
|
|
120
141
|
case "connected":
|
|
121
|
-
console.info(
|
|
122
|
-
|
|
142
|
+
console.info(`[vite] connected.`);
|
|
143
|
+
sendMessageBuffer();
|
|
144
|
+
setInterval(() => {
|
|
145
|
+
if (socket.readyState === socket.OPEN) {
|
|
146
|
+
socket.send('{"type":"ping"}');
|
|
147
|
+
}
|
|
123
148
|
}, __HMR_TIMEOUT__);
|
|
124
149
|
break;
|
|
125
150
|
case "update":
|
|
126
|
-
|
|
151
|
+
notifyListeners("vite:beforeUpdate", payload);
|
|
152
|
+
if (isFirstUpdate && hasErrorOverlay()) {
|
|
127
153
|
globalThis.__vxrnReloadApp();
|
|
128
154
|
return;
|
|
129
155
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
156
|
+
clearErrorOverlay();
|
|
157
|
+
isFirstUpdate = false;
|
|
158
|
+
await Promise.all(payload.updates.map(update => {
|
|
159
|
+
if (update.type === "js-update") {
|
|
160
|
+
return queueUpdate(fetchUpdate(update));
|
|
161
|
+
}
|
|
162
|
+
}));
|
|
163
|
+
notifyListeners("vite:afterUpdate", payload);
|
|
133
164
|
break;
|
|
134
165
|
case "custom":
|
|
135
166
|
{
|
|
@@ -137,70 +168,101 @@ async function handleMessage(payload) {
|
|
|
137
168
|
break;
|
|
138
169
|
}
|
|
139
170
|
case "full-reload":
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
171
|
+
notifyListeners("vite:beforeFullReload", payload);
|
|
172
|
+
if (payload.path && payload.path.endsWith(".html")) {
|
|
173
|
+
const pagePath = decodeURI(location.pathname);
|
|
174
|
+
const payloadPath = base + payload.path.slice(1);
|
|
175
|
+
if (pagePath === payloadPath || payload.path === "/index.html" || pagePath.endsWith("/") && pagePath + "index.html" === payloadPath) {
|
|
176
|
+
pageReload();
|
|
177
|
+
}
|
|
144
178
|
return;
|
|
145
179
|
}
|
|
146
180
|
pageReload();
|
|
147
181
|
break;
|
|
148
182
|
case "prune":
|
|
149
|
-
notifyListeners("vite:beforePrune", payload)
|
|
183
|
+
notifyListeners("vite:beforePrune", payload);
|
|
184
|
+
payload.paths.forEach(path2 => {
|
|
150
185
|
const fn = pruneMap.get(path2);
|
|
151
|
-
|
|
186
|
+
if (fn) {
|
|
187
|
+
fn(dataMap.get(path2));
|
|
188
|
+
}
|
|
152
189
|
});
|
|
153
190
|
break;
|
|
154
191
|
case "error":
|
|
155
192
|
{
|
|
156
193
|
notifyListeners("vite:error", payload);
|
|
157
194
|
const err = payload.err;
|
|
158
|
-
|
|
195
|
+
if (enableOverlay) {
|
|
196
|
+
createErrorOverlay(err);
|
|
197
|
+
} else {
|
|
198
|
+
console.error(`[vite] Internal Server Error
|
|
159
199
|
${err.message}
|
|
160
200
|
${err.stack}`);
|
|
201
|
+
}
|
|
161
202
|
break;
|
|
162
203
|
}
|
|
163
204
|
default:
|
|
164
|
-
|
|
205
|
+
{
|
|
206
|
+
const check = payload;
|
|
207
|
+
return check;
|
|
208
|
+
}
|
|
165
209
|
}
|
|
166
210
|
}
|
|
167
211
|
function notifyListeners(event, data) {
|
|
168
212
|
const cbs = customListenersMap.get(event);
|
|
169
|
-
|
|
213
|
+
if (cbs) {
|
|
214
|
+
cbs.forEach(cb => cb(data));
|
|
215
|
+
}
|
|
170
216
|
}
|
|
171
217
|
const enableOverlay = __HMR_ENABLE_OVERLAY__;
|
|
172
218
|
function createErrorOverlay(err) {
|
|
173
|
-
|
|
219
|
+
if (!enableOverlay) return;
|
|
220
|
+
clearErrorOverlay();
|
|
221
|
+
console.error("create error", err);
|
|
174
222
|
}
|
|
175
223
|
function clearErrorOverlay() {}
|
|
176
224
|
function hasErrorOverlay() {
|
|
177
|
-
return
|
|
225
|
+
return false;
|
|
178
226
|
}
|
|
179
|
-
let pending =
|
|
180
|
-
|
|
227
|
+
let pending = false;
|
|
228
|
+
let queued = [];
|
|
181
229
|
async function queueUpdate(p) {
|
|
182
|
-
|
|
183
|
-
|
|
230
|
+
queued.push(p);
|
|
231
|
+
if (!pending) {
|
|
232
|
+
pending = true;
|
|
233
|
+
await Promise.resolve();
|
|
234
|
+
pending = false;
|
|
184
235
|
const loading = [...queued];
|
|
185
|
-
queued = []
|
|
236
|
+
queued = [];
|
|
237
|
+
(await Promise.all(loading)).forEach(fn => fn && fn());
|
|
186
238
|
}
|
|
187
239
|
}
|
|
188
240
|
async function waitForSuccessfulPing(socketProtocol2, hostAndPath, ms = 1e3) {
|
|
189
|
-
const pingHostProtocol = socketProtocol2 === "wss" ? "https" : "http"
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
241
|
+
const pingHostProtocol = socketProtocol2 === "wss" ? "https" : "http";
|
|
242
|
+
const ping = async () => {
|
|
243
|
+
try {
|
|
244
|
+
await fetch(`${pingHostProtocol}://${hostAndPath}`, {
|
|
245
|
+
mode: "no-cors",
|
|
246
|
+
headers: {
|
|
247
|
+
// Custom headers won't be included in a request with no-cors so (ab)use one of the
|
|
248
|
+
// safelisted headers to identify the ping request
|
|
249
|
+
Accept: "text/x-vite-ping"
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
return true;
|
|
253
|
+
} catch {}
|
|
254
|
+
return false;
|
|
255
|
+
};
|
|
256
|
+
if (await ping()) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
await wait(ms);
|
|
260
|
+
while (true) {
|
|
261
|
+
if (await ping()) {
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
await wait(ms);
|
|
265
|
+
}
|
|
204
266
|
}
|
|
205
267
|
function wait(ms) {
|
|
206
268
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
@@ -211,64 +273,83 @@ async function fetchUpdate({
|
|
|
211
273
|
timestamp,
|
|
212
274
|
explicitImportRequired
|
|
213
275
|
}) {
|
|
214
|
-
const path = pathIn.replace("/@id", "")
|
|
215
|
-
|
|
216
|
-
|
|
276
|
+
const path = pathIn.replace("/@id", "");
|
|
277
|
+
const acceptedPath = acceptedPathIn.replace("/@id", "");
|
|
278
|
+
const mod = hotModulesMap.get(path);
|
|
217
279
|
if (!mod) {
|
|
218
|
-
console.info(
|
|
280
|
+
console.info(` \u2776 hmr - No module found`);
|
|
281
|
+
console.info(` looked for ${path} in:`);
|
|
282
|
+
hotModulesMap.forEach((value, key) => {
|
|
219
283
|
console.info(` - ${key}`);
|
|
220
284
|
});
|
|
221
285
|
return;
|
|
222
286
|
}
|
|
223
287
|
let fetchedModule;
|
|
224
|
-
const isSelfUpdate = path === acceptedPath
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
288
|
+
const isSelfUpdate = path === acceptedPath;
|
|
289
|
+
const qualifiedCallbacks = mod.callbacks.filter(({
|
|
290
|
+
deps
|
|
291
|
+
}) => deps.includes(acceptedPath));
|
|
228
292
|
if (isSelfUpdate || qualifiedCallbacks.length > 0) {
|
|
229
293
|
const disposer = disposeMap.get(acceptedPath);
|
|
230
|
-
disposer
|
|
231
|
-
const [acceptedPathWithoutQuery, query] = acceptedPath.split(
|
|
294
|
+
if (disposer) await disposer(dataMap.get(acceptedPath));
|
|
295
|
+
const [acceptedPathWithoutQuery, query] = acceptedPath.split(`?`);
|
|
232
296
|
try {
|
|
233
|
-
const filePath = acceptedPathWithoutQuery
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
297
|
+
const filePath = acceptedPathWithoutQuery;
|
|
298
|
+
const finalQuery = `file?file=${encodeURIComponent(filePath)}&${explicitImportRequired ? "import&" : ""}t=${timestamp}${query ? `&${query}` : ""}`;
|
|
299
|
+
const scriptUrl =
|
|
300
|
+
// re-route to our cjs endpoint
|
|
301
|
+
`http://${rnDevServerHost ? rnDevServerHost + "/" : serverHost.replace("5173", "8081")}` + finalQuery;
|
|
238
302
|
console.info(` \u2776 hmr fetching update: ${scriptUrl}`);
|
|
239
|
-
const source = await fetch(scriptUrl).then(res => res.text())
|
|
240
|
-
|
|
303
|
+
const source = await fetch(scriptUrl).then(res => res.text());
|
|
304
|
+
const evaluatedModule = eval(source);
|
|
241
305
|
fetchedModule = evaluatedModule;
|
|
242
306
|
} catch (e) {
|
|
243
307
|
warnFailedFetch(e, acceptedPath);
|
|
244
308
|
}
|
|
245
|
-
} else
|
|
309
|
+
} else {
|
|
310
|
+
console.info(` \u2776 hmr can't accept - isSelfUpdate ${isSelfUpdate} - callbacks: ${JSON.stringify(mod.callbacks)} - acceptedPath: ${acceptedPath}`);
|
|
311
|
+
}
|
|
246
312
|
return () => {
|
|
247
313
|
for (const {
|
|
248
314
|
deps,
|
|
249
315
|
fn
|
|
250
|
-
} of qualifiedCallbacks)
|
|
316
|
+
} of qualifiedCallbacks) {
|
|
317
|
+
fn(deps.map(dep => dep === acceptedPath ? fetchedModule : void 0));
|
|
318
|
+
}
|
|
251
319
|
const loggedPath = isSelfUpdate ? path : `${acceptedPath} via ${path}`;
|
|
252
|
-
process.env.DEBUG
|
|
320
|
+
if (process.env.DEBUG) {
|
|
321
|
+
console.info(`[vite] hot updated: ${loggedPath}`);
|
|
322
|
+
}
|
|
253
323
|
};
|
|
254
324
|
}
|
|
255
325
|
function sendMessageBuffer() {
|
|
256
|
-
socket.readyState === 1
|
|
326
|
+
if (socket.readyState === 1) {
|
|
327
|
+
messageBuffer.forEach(msg => socket.send(msg));
|
|
328
|
+
messageBuffer.length = 0;
|
|
329
|
+
}
|
|
257
330
|
}
|
|
258
|
-
const hotModulesMap = /* @__PURE__ */new Map()
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
globalThis
|
|
265
|
-
dataMap.has(ownerPath)
|
|
331
|
+
const hotModulesMap = /* @__PURE__ */new Map();
|
|
332
|
+
const disposeMap = /* @__PURE__ */new Map();
|
|
333
|
+
const pruneMap = /* @__PURE__ */new Map();
|
|
334
|
+
const dataMap = /* @__PURE__ */new Map();
|
|
335
|
+
const customListenersMap = /* @__PURE__ */new Map();
|
|
336
|
+
const ctxToListenersMap = /* @__PURE__ */new Map();
|
|
337
|
+
globalThis["createHotContext"] = function createHotContext(ownerPath) {
|
|
338
|
+
if (!dataMap.has(ownerPath)) {
|
|
339
|
+
dataMap.set(ownerPath, {});
|
|
340
|
+
}
|
|
266
341
|
const mod2 = hotModulesMap.get(ownerPath);
|
|
267
|
-
|
|
342
|
+
if (mod2) {
|
|
343
|
+
mod2.callbacks = [];
|
|
344
|
+
}
|
|
268
345
|
const staleListeners = ctxToListenersMap.get(ownerPath);
|
|
269
|
-
if (staleListeners)
|
|
270
|
-
const
|
|
271
|
-
|
|
346
|
+
if (staleListeners) {
|
|
347
|
+
for (const [event, staleFns] of staleListeners) {
|
|
348
|
+
const listeners = customListenersMap.get(event);
|
|
349
|
+
if (listeners) {
|
|
350
|
+
customListenersMap.set(event, listeners.filter(l => !staleFns.includes(l)));
|
|
351
|
+
}
|
|
352
|
+
}
|
|
272
353
|
}
|
|
273
354
|
const newListeners = /* @__PURE__ */new Map();
|
|
274
355
|
ctxToListenersMap.set(ownerPath, newListeners);
|
|
@@ -280,14 +361,23 @@ globalThis.createHotContext = function createHotContext(ownerPath) {
|
|
|
280
361
|
mod3.callbacks.push({
|
|
281
362
|
deps,
|
|
282
363
|
fn: callback
|
|
283
|
-
})
|
|
364
|
+
});
|
|
365
|
+
hotModulesMap.set(ownerPath, mod3);
|
|
284
366
|
}
|
|
285
|
-
|
|
367
|
+
const hot = {
|
|
286
368
|
get data() {
|
|
287
369
|
return dataMap.get(ownerPath);
|
|
288
370
|
},
|
|
289
371
|
accept(deps, callback) {
|
|
290
|
-
if (typeof deps
|
|
372
|
+
if (typeof deps === "function" || !deps) {
|
|
373
|
+
acceptDeps([ownerPath], ([mod3]) => deps?.(mod3));
|
|
374
|
+
} else if (typeof deps === "string") {
|
|
375
|
+
acceptDeps([deps], ([mod3]) => callback?.(mod3));
|
|
376
|
+
} else if (Array.isArray(deps)) {
|
|
377
|
+
acceptDeps(deps, callback);
|
|
378
|
+
} else {
|
|
379
|
+
throw new Error(`invalid hot.accept() usage.`);
|
|
380
|
+
}
|
|
291
381
|
},
|
|
292
382
|
// export names (first arg) are irrelevant on the client side, they're
|
|
293
383
|
// extracted in the server for propagation
|
|
@@ -309,25 +399,31 @@ globalThis.createHotContext = function createHotContext(ownerPath) {
|
|
|
309
399
|
notifyListeners("vite:invalidate", {
|
|
310
400
|
path: ownerPath,
|
|
311
401
|
message
|
|
312
|
-
})
|
|
402
|
+
});
|
|
403
|
+
this.send("vite:invalidate", {
|
|
313
404
|
path: ownerPath,
|
|
314
405
|
message
|
|
315
|
-
})
|
|
406
|
+
});
|
|
407
|
+
console.info(`[vite] invalidate ${ownerPath}${message ? `: ${message}` : ""}`);
|
|
316
408
|
},
|
|
317
409
|
// custom events
|
|
318
410
|
on(event, cb) {
|
|
319
411
|
const addToMap = map => {
|
|
320
412
|
const existing = map.get(event) || [];
|
|
321
|
-
existing.push(cb)
|
|
413
|
+
existing.push(cb);
|
|
414
|
+
map.set(event, existing);
|
|
322
415
|
};
|
|
323
|
-
addToMap(customListenersMap)
|
|
416
|
+
addToMap(customListenersMap);
|
|
417
|
+
addToMap(newListeners);
|
|
324
418
|
},
|
|
325
419
|
send(event, data) {
|
|
326
420
|
messageBuffer.push(JSON.stringify({
|
|
327
421
|
type: "custom",
|
|
328
422
|
event,
|
|
329
423
|
data
|
|
330
|
-
}))
|
|
424
|
+
}));
|
|
425
|
+
sendMessageBuffer();
|
|
331
426
|
}
|
|
332
427
|
};
|
|
428
|
+
return hot;
|
|
333
429
|
};
|