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