vite 6.0.0-beta.8 → 6.0.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.
Potentially problematic release.
This version of vite might be problematic. Click here for more details.
- package/LICENSE.md +247 -13
- package/client.d.ts +14 -0
- package/dist/client/client.mjs +343 -93
- package/dist/node/chunks/dep-0q9rEWat.js +822 -0
- package/dist/node/chunks/dep-3RmXg9uo.js +553 -0
- package/dist/node/chunks/dep-C1dfssTZ.js +7002 -0
- package/dist/node/chunks/{dep-Ddvoc4zx.js → dep-C6qYk3zB.js} +21241 -16553
- package/dist/node/chunks/{dep-CdoEeCn3.js → dep-DnSxfB-q.js} +0 -4
- package/dist/node/cli.js +7 -8
- package/dist/node/constants.js +13 -18
- package/dist/node/index.d.ts +1728 -1590
- package/dist/node/index.js +6 -38
- package/dist/node/module-runner.d.ts +92 -99
- package/dist/node/module-runner.js +269 -94
- package/dist/node-cjs/publicUtils.cjs +2699 -2747
- package/index.cjs +35 -3
- package/misc/false.js +1 -0
- package/misc/true.js +1 -0
- package/package.json +32 -31
- package/types/hmrPayload.d.ts +5 -0
- package/dist/node/chunks/dep-DUn1iy3F.js +0 -913
- package/dist/node/chunks/dep-mtw2NpNs.js +0 -589
- package/dist/node/chunks/dep-qU9-vqRp.js +0 -7216
@@ -1,7 +1,7 @@
|
|
1
1
|
const VALID_ID_PREFIX = "/@id/", NULL_BYTE_PLACEHOLDER = "__x00__";
|
2
2
|
let SOURCEMAPPING_URL = "sourceMa";
|
3
3
|
SOURCEMAPPING_URL += "ppingURL";
|
4
|
-
const isWindows = typeof process < "u" && process.platform === "win32";
|
4
|
+
const ERR_OUTDATED_OPTIMIZED_DEP = "ERR_OUTDATED_OPTIMIZED_DEP", isWindows = typeof process < "u" && process.platform === "win32";
|
5
5
|
function unwrapId(id) {
|
6
6
|
return id.startsWith(VALID_ID_PREFIX) ? id.slice(VALID_ID_PREFIX.length).replace(NULL_BYTE_PLACEHOLDER, "\0") : id;
|
7
7
|
}
|
@@ -27,6 +27,12 @@ function getAsyncFunctionDeclarationPaddingLineCount() {
|
|
27
27
|
}
|
28
28
|
return asyncFunctionDeclarationPaddingLineCount;
|
29
29
|
}
|
30
|
+
function promiseWithResolvers() {
|
31
|
+
let resolve2, reject;
|
32
|
+
return { promise: new Promise((_resolve, _reject) => {
|
33
|
+
resolve2 = _resolve, reject = _reject;
|
34
|
+
}), resolve: resolve2, reject };
|
35
|
+
}
|
30
36
|
const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
31
37
|
function normalizeWindowsPath(input = "") {
|
32
38
|
return input && input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
|
@@ -326,7 +332,12 @@ class EvaluatedModules {
|
|
326
332
|
this.idToModuleMap.clear(), this.fileToModulesMap.clear(), this.urlToIdModuleMap.clear();
|
327
333
|
}
|
328
334
|
}
|
329
|
-
const prefixedBuiltins = /* @__PURE__ */ new Set([
|
335
|
+
const prefixedBuiltins = /* @__PURE__ */ new Set([
|
336
|
+
"node:sea",
|
337
|
+
"node:sqlite",
|
338
|
+
"node:test",
|
339
|
+
"node:test/reporters"
|
340
|
+
]);
|
330
341
|
function normalizeModuleId(file) {
|
331
342
|
return prefixedBuiltins.has(file) ? file : slash(file).replace(/^\/@fs\//, isWindows ? "" : "/").replace(/^node:/, "").replace(/^\/+/, "/").replace(/^file:\//, "/");
|
332
343
|
}
|
@@ -408,7 +419,7 @@ class HMRContext {
|
|
408
419
|
removeFromMap(this.hmrClient.customListenersMap), removeFromMap(this.newListeners);
|
409
420
|
}
|
410
421
|
send(event, data) {
|
411
|
-
this.hmrClient.
|
422
|
+
this.hmrClient.send({ type: "custom", event, data });
|
412
423
|
}
|
413
424
|
acceptDeps(deps, callback = () => {
|
414
425
|
}) {
|
@@ -422,21 +433,9 @@ class HMRContext {
|
|
422
433
|
}), this.hmrClient.hotModulesMap.set(this.ownerPath, mod);
|
423
434
|
}
|
424
435
|
}
|
425
|
-
class HMRMessenger {
|
426
|
-
constructor(connection) {
|
427
|
-
this.connection = connection;
|
428
|
-
}
|
429
|
-
queue = [];
|
430
|
-
send(payload) {
|
431
|
-
this.queue.push(payload), this.flush();
|
432
|
-
}
|
433
|
-
flush() {
|
434
|
-
this.connection.isReady() && (this.queue.forEach((msg) => this.connection.send(msg)), this.queue = []);
|
435
|
-
}
|
436
|
-
}
|
437
436
|
class HMRClient {
|
438
|
-
constructor(logger,
|
439
|
-
this.logger = logger, this.
|
437
|
+
constructor(logger, transport, importUpdatedModule) {
|
438
|
+
this.logger = logger, this.transport = transport, this.importUpdatedModule = importUpdatedModule;
|
440
439
|
}
|
441
440
|
hotModulesMap = /* @__PURE__ */ new Map();
|
442
441
|
disposeMap = /* @__PURE__ */ new Map();
|
@@ -444,11 +443,15 @@ class HMRClient {
|
|
444
443
|
dataMap = /* @__PURE__ */ new Map();
|
445
444
|
customListenersMap = /* @__PURE__ */ new Map();
|
446
445
|
ctxToListenersMap = /* @__PURE__ */ new Map();
|
447
|
-
messenger;
|
448
446
|
async notifyListeners(event, data) {
|
449
447
|
const cbs = this.customListenersMap.get(event);
|
450
448
|
cbs && await Promise.allSettled(cbs.map((cb) => cb(data)));
|
451
449
|
}
|
450
|
+
send(payload) {
|
451
|
+
this.transport.send(payload).catch((err) => {
|
452
|
+
this.logger.error(err);
|
453
|
+
});
|
454
|
+
}
|
452
455
|
clear() {
|
453
456
|
this.hotModulesMap.clear(), this.disposeMap.clear(), this.pruneMap.clear(), this.dataMap.clear(), this.customListenersMap.clear(), this.ctxToListenersMap.clear();
|
454
457
|
}
|
@@ -528,7 +531,194 @@ const {${missingBindings.join(", ")}} = pkg;
|
|
528
531
|
}
|
529
532
|
}
|
530
533
|
}
|
531
|
-
|
534
|
+
let urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict", nanoid = (size = 21) => {
|
535
|
+
let id = "", i = size;
|
536
|
+
for (; i--; )
|
537
|
+
id += urlAlphabet[Math.random() * 64 | 0];
|
538
|
+
return id;
|
539
|
+
};
|
540
|
+
function reviveInvokeError(e) {
|
541
|
+
const error = new Error(e.message || "Unknown invoke error");
|
542
|
+
return Object.assign(error, e, {
|
543
|
+
// pass the whole error instead of just the stacktrace
|
544
|
+
// so that it gets formatted nicely with console.log
|
545
|
+
runnerError: new Error("RunnerError")
|
546
|
+
}), error;
|
547
|
+
}
|
548
|
+
const createInvokeableTransport = (transport) => {
|
549
|
+
if (transport.invoke)
|
550
|
+
return {
|
551
|
+
...transport,
|
552
|
+
async invoke(name, data) {
|
553
|
+
const result = await transport.invoke({
|
554
|
+
type: "custom",
|
555
|
+
event: "vite:invoke",
|
556
|
+
data: {
|
557
|
+
id: "send",
|
558
|
+
name,
|
559
|
+
data
|
560
|
+
}
|
561
|
+
});
|
562
|
+
if ("e" in result)
|
563
|
+
throw reviveInvokeError(result.e);
|
564
|
+
return result.r;
|
565
|
+
}
|
566
|
+
};
|
567
|
+
if (!transport.send || !transport.connect)
|
568
|
+
throw new Error(
|
569
|
+
"transport must implement send and connect when invoke is not implemented"
|
570
|
+
);
|
571
|
+
const rpcPromises = /* @__PURE__ */ new Map();
|
572
|
+
return {
|
573
|
+
...transport,
|
574
|
+
connect({ onMessage, onDisconnection }) {
|
575
|
+
return transport.connect({
|
576
|
+
onMessage(payload) {
|
577
|
+
if (payload.type === "custom" && payload.event === "vite:invoke") {
|
578
|
+
const data = payload.data;
|
579
|
+
if (data.id.startsWith("response:")) {
|
580
|
+
const invokeId = data.id.slice(9), promise = rpcPromises.get(invokeId);
|
581
|
+
if (!promise) return;
|
582
|
+
promise.timeoutId && clearTimeout(promise.timeoutId), rpcPromises.delete(invokeId);
|
583
|
+
const { e, r } = data.data;
|
584
|
+
e ? promise.reject(e) : promise.resolve(r);
|
585
|
+
return;
|
586
|
+
}
|
587
|
+
}
|
588
|
+
onMessage(payload);
|
589
|
+
},
|
590
|
+
onDisconnection
|
591
|
+
});
|
592
|
+
},
|
593
|
+
disconnect() {
|
594
|
+
return rpcPromises.forEach((promise) => {
|
595
|
+
promise.reject(
|
596
|
+
new Error(
|
597
|
+
`transport was disconnected, cannot call ${JSON.stringify(promise.name)}`
|
598
|
+
)
|
599
|
+
);
|
600
|
+
}), rpcPromises.clear(), transport.disconnect?.();
|
601
|
+
},
|
602
|
+
send(data) {
|
603
|
+
return transport.send(data);
|
604
|
+
},
|
605
|
+
async invoke(name, data) {
|
606
|
+
const promiseId = nanoid(), wrappedData = {
|
607
|
+
type: "custom",
|
608
|
+
event: "vite:invoke",
|
609
|
+
data: {
|
610
|
+
name,
|
611
|
+
id: `send:${promiseId}`,
|
612
|
+
data
|
613
|
+
}
|
614
|
+
}, sendPromise = transport.send(wrappedData), { promise, resolve: resolve2, reject } = promiseWithResolvers(), timeout = transport.timeout ?? 6e4;
|
615
|
+
let timeoutId;
|
616
|
+
timeout > 0 && (timeoutId = setTimeout(() => {
|
617
|
+
rpcPromises.delete(promiseId), reject(
|
618
|
+
new Error(
|
619
|
+
`transport invoke timed out after ${timeout}ms (data: ${JSON.stringify(wrappedData)})`
|
620
|
+
)
|
621
|
+
);
|
622
|
+
}, timeout), timeoutId?.unref?.()), rpcPromises.set(promiseId, { resolve: resolve2, reject, name, timeoutId }), sendPromise && sendPromise.catch((err) => {
|
623
|
+
clearTimeout(timeoutId), rpcPromises.delete(promiseId), reject(err);
|
624
|
+
});
|
625
|
+
try {
|
626
|
+
return await promise;
|
627
|
+
} catch (err) {
|
628
|
+
throw reviveInvokeError(err);
|
629
|
+
}
|
630
|
+
}
|
631
|
+
};
|
632
|
+
}, normalizeModuleRunnerTransport = (transport) => {
|
633
|
+
const invokeableTransport = createInvokeableTransport(transport);
|
634
|
+
let isConnected = !invokeableTransport.connect, connectingPromise;
|
635
|
+
return {
|
636
|
+
...transport,
|
637
|
+
...invokeableTransport.connect ? {
|
638
|
+
async connect(onMessage) {
|
639
|
+
if (isConnected) return;
|
640
|
+
if (connectingPromise) {
|
641
|
+
await connectingPromise;
|
642
|
+
return;
|
643
|
+
}
|
644
|
+
const maybePromise = invokeableTransport.connect({
|
645
|
+
onMessage: onMessage ?? (() => {
|
646
|
+
}),
|
647
|
+
onDisconnection() {
|
648
|
+
isConnected = !1;
|
649
|
+
}
|
650
|
+
});
|
651
|
+
maybePromise && (connectingPromise = maybePromise, await connectingPromise, connectingPromise = void 0), isConnected = !0;
|
652
|
+
}
|
653
|
+
} : {},
|
654
|
+
...invokeableTransport.disconnect ? {
|
655
|
+
async disconnect() {
|
656
|
+
isConnected && (connectingPromise && await connectingPromise, isConnected = !1, await invokeableTransport.disconnect());
|
657
|
+
}
|
658
|
+
} : {},
|
659
|
+
async send(data) {
|
660
|
+
if (invokeableTransport.send) {
|
661
|
+
if (!isConnected)
|
662
|
+
if (connectingPromise)
|
663
|
+
await connectingPromise;
|
664
|
+
else
|
665
|
+
throw new Error("send was called before connect");
|
666
|
+
await invokeableTransport.send(data);
|
667
|
+
}
|
668
|
+
},
|
669
|
+
async invoke(name, data) {
|
670
|
+
if (!isConnected)
|
671
|
+
if (connectingPromise)
|
672
|
+
await connectingPromise;
|
673
|
+
else
|
674
|
+
throw new Error("invoke was called before connect");
|
675
|
+
return invokeableTransport.invoke(name, data);
|
676
|
+
}
|
677
|
+
};
|
678
|
+
}, createWebSocketModuleRunnerTransport = (options) => {
|
679
|
+
const pingInterval = options.pingInterval ?? 3e4;
|
680
|
+
let ws, pingIntervalId;
|
681
|
+
return {
|
682
|
+
async connect({ onMessage, onDisconnection }) {
|
683
|
+
const socket = options.createConnection();
|
684
|
+
socket.addEventListener("message", async ({ data }) => {
|
685
|
+
onMessage(JSON.parse(data));
|
686
|
+
});
|
687
|
+
let isOpened = socket.readyState === socket.OPEN;
|
688
|
+
isOpened || await new Promise((resolve2, reject) => {
|
689
|
+
socket.addEventListener(
|
690
|
+
"open",
|
691
|
+
() => {
|
692
|
+
isOpened = !0, resolve2();
|
693
|
+
},
|
694
|
+
{ once: !0 }
|
695
|
+
), socket.addEventListener("close", async () => {
|
696
|
+
if (!isOpened) {
|
697
|
+
reject(new Error("WebSocket closed without opened."));
|
698
|
+
return;
|
699
|
+
}
|
700
|
+
onMessage({
|
701
|
+
type: "custom",
|
702
|
+
event: "vite:ws:disconnect",
|
703
|
+
data: { webSocket: socket }
|
704
|
+
}), onDisconnection();
|
705
|
+
});
|
706
|
+
}), onMessage({
|
707
|
+
type: "custom",
|
708
|
+
event: "vite:ws:connect",
|
709
|
+
data: { webSocket: socket }
|
710
|
+
}), ws = socket, pingIntervalId = setInterval(() => {
|
711
|
+
socket.readyState === socket.OPEN && socket.send(JSON.stringify({ type: "ping" }));
|
712
|
+
}, pingInterval);
|
713
|
+
},
|
714
|
+
disconnect() {
|
715
|
+
clearInterval(pingIntervalId), ws?.close();
|
716
|
+
},
|
717
|
+
send(data) {
|
718
|
+
ws.send(JSON.stringify(data));
|
719
|
+
}
|
720
|
+
};
|
721
|
+
}, ssrModuleExportsKey = "__vite_ssr_exports__", ssrImportKey = "__vite_ssr_import__", ssrDynamicImportKey = "__vite_ssr_dynamic_import__", ssrExportAllKey = "__vite_ssr_exportAll__", ssrImportMetaKey = "__vite_ssr_import_meta__", noop = () => {
|
532
722
|
}, silentConsole = {
|
533
723
|
debug: noop,
|
534
724
|
error: noop
|
@@ -545,7 +735,7 @@ async function handleHotPayload(runner, payload) {
|
|
545
735
|
if (!(!hmrClient || runner.isClosed()))
|
546
736
|
switch (payload.type) {
|
547
737
|
case "connected":
|
548
|
-
hmrClient.logger.debug("connected.")
|
738
|
+
hmrClient.logger.debug("connected.");
|
549
739
|
break;
|
550
740
|
case "update":
|
551
741
|
await hmrClient.notifyListeners("vite:beforeUpdate", payload), await Promise.all(
|
@@ -568,7 +758,15 @@ async function handleHotPayload(runner, payload) {
|
|
568
758
|
if (!clearEntrypointUrls.size) break;
|
569
759
|
hmrClient.logger.debug("program reload"), await hmrClient.notifyListeners("vite:beforeFullReload", payload), runner.evaluatedModules.clear();
|
570
760
|
for (const url of clearEntrypointUrls)
|
571
|
-
|
761
|
+
try {
|
762
|
+
await runner.import(url);
|
763
|
+
} catch (err) {
|
764
|
+
err.code !== ERR_OUTDATED_OPTIMIZED_DEP && hmrClient.logger.error(
|
765
|
+
`An error happened during full reload
|
766
|
+
${err.message}
|
767
|
+
${err.stack}`
|
768
|
+
);
|
769
|
+
}
|
572
770
|
break;
|
573
771
|
}
|
574
772
|
case "prune":
|
@@ -584,6 +782,8 @@ ${err.stack}`
|
|
584
782
|
);
|
585
783
|
break;
|
586
784
|
}
|
785
|
+
case "ping":
|
786
|
+
break;
|
587
787
|
default:
|
588
788
|
return payload;
|
589
789
|
}
|
@@ -847,15 +1047,47 @@ function enableSourceMapSupport(runner) {
|
|
847
1047
|
typeof runner.options.sourcemapInterceptor == "object" ? runner.options.sourcemapInterceptor : void 0
|
848
1048
|
);
|
849
1049
|
}
|
1050
|
+
class ESModulesEvaluator {
|
1051
|
+
startOffset = getAsyncFunctionDeclarationPaddingLineCount();
|
1052
|
+
async runInlinedModule(context, code) {
|
1053
|
+
await new AsyncFunction(
|
1054
|
+
ssrModuleExportsKey,
|
1055
|
+
ssrImportMetaKey,
|
1056
|
+
ssrImportKey,
|
1057
|
+
ssrDynamicImportKey,
|
1058
|
+
ssrExportAllKey,
|
1059
|
+
// source map should already be inlined by Vite
|
1060
|
+
'"use strict";' + code
|
1061
|
+
)(
|
1062
|
+
context[ssrModuleExportsKey],
|
1063
|
+
context[ssrImportMetaKey],
|
1064
|
+
context[ssrImportKey],
|
1065
|
+
context[ssrDynamicImportKey],
|
1066
|
+
context[ssrExportAllKey]
|
1067
|
+
), Object.seal(context[ssrModuleExportsKey]);
|
1068
|
+
}
|
1069
|
+
runExternalModule(filepath) {
|
1070
|
+
return import(filepath);
|
1071
|
+
}
|
1072
|
+
}
|
850
1073
|
class ModuleRunner {
|
851
|
-
constructor(options, evaluator, debug) {
|
1074
|
+
constructor(options, evaluator = new ESModulesEvaluator(), debug) {
|
852
1075
|
this.options = options, this.evaluator = evaluator, this.debug = debug;
|
853
1076
|
const root = this.options.root;
|
854
|
-
this.root = root[root.length - 1] === "/" ? root : `${root}/`, this.evaluatedModules = options.evaluatedModules ?? new EvaluatedModules(), this.transport = options.transport,
|
855
|
-
options.hmr.logger === !1 ? silentConsole :
|
856
|
-
|
857
|
-
|
858
|
-
|
1077
|
+
if (this.root = root[root.length - 1] === "/" ? root : `${root}/`, this.evaluatedModules = options.evaluatedModules ?? new EvaluatedModules(), this.transport = normalizeModuleRunnerTransport(options.transport), options.hmr !== !1) {
|
1078
|
+
const optionsHmr = options.hmr ?? !0, resolvedHmrLogger = optionsHmr === !0 || optionsHmr.logger === void 0 ? hmrLogger : optionsHmr.logger === !1 ? silentConsole : optionsHmr.logger;
|
1079
|
+
if (this.hmrClient = new HMRClient(
|
1080
|
+
resolvedHmrLogger,
|
1081
|
+
this.transport,
|
1082
|
+
({ acceptedPath }) => this.import(acceptedPath)
|
1083
|
+
), !this.transport.connect)
|
1084
|
+
throw new Error(
|
1085
|
+
"HMR is not supported by this runner transport, but `hmr` option was set to true"
|
1086
|
+
);
|
1087
|
+
this.transport.connect(createHMRHandler(this));
|
1088
|
+
} else
|
1089
|
+
this.transport.connect?.();
|
1090
|
+
options.sourcemapInterceptor !== !1 && (this.resetSourceMapSupport = enableSourceMapSupport(this));
|
859
1091
|
}
|
860
1092
|
evaluatedModules;
|
861
1093
|
hmrClient;
|
@@ -889,7 +1121,7 @@ class ModuleRunner {
|
|
889
1121
|
* This method doesn't stop the HMR connection.
|
890
1122
|
*/
|
891
1123
|
async close() {
|
892
|
-
this.resetSourceMapSupport?.(), this.clearCache(), this.hmrClient = void 0, this.closed = !0;
|
1124
|
+
this.resetSourceMapSupport?.(), this.clearCache(), this.hmrClient = void 0, this.closed = !0, await this.transport.disconnect?.();
|
893
1125
|
}
|
894
1126
|
/**
|
895
1127
|
* Returns `true` if the runtime has been closed by calling `close()` method.
|
@@ -965,10 +1197,14 @@ ${getStack()}`
|
|
965
1197
|
this.debug?.("[module runner] fetching", url);
|
966
1198
|
const isCached = !!(typeof cachedModule == "object" && cachedModule.meta), fetchedModule = (
|
967
1199
|
// fast return for established externalized pattern
|
968
|
-
url.startsWith("data:") ? { externalize: url, type: "builtin" } : await this.transport.fetchModule
|
969
|
-
|
970
|
-
|
971
|
-
|
1200
|
+
url.startsWith("data:") ? { externalize: url, type: "builtin" } : await this.transport.invoke("fetchModule", [
|
1201
|
+
url,
|
1202
|
+
importer,
|
1203
|
+
{
|
1204
|
+
cached: isCached,
|
1205
|
+
startOffset: this.evaluator.startOffset
|
1206
|
+
}
|
1207
|
+
])
|
972
1208
|
);
|
973
1209
|
if ("cache" in fetchedModule) {
|
974
1210
|
if (!cachedModule || !cachedModule.meta)
|
@@ -1057,72 +1293,11 @@ function exportAll(exports, sourceModule) {
|
|
1057
1293
|
}
|
1058
1294
|
}
|
1059
1295
|
}
|
1060
|
-
class ESModulesEvaluator {
|
1061
|
-
startOffset = getAsyncFunctionDeclarationPaddingLineCount();
|
1062
|
-
async runInlinedModule(context, code) {
|
1063
|
-
await new AsyncFunction(
|
1064
|
-
ssrModuleExportsKey,
|
1065
|
-
ssrImportMetaKey,
|
1066
|
-
ssrImportKey,
|
1067
|
-
ssrDynamicImportKey,
|
1068
|
-
ssrExportAllKey,
|
1069
|
-
// source map should already be inlined by Vite
|
1070
|
-
'"use strict";' + code
|
1071
|
-
)(
|
1072
|
-
context[ssrModuleExportsKey],
|
1073
|
-
context[ssrImportMetaKey],
|
1074
|
-
context[ssrImportKey],
|
1075
|
-
context[ssrDynamicImportKey],
|
1076
|
-
context[ssrExportAllKey]
|
1077
|
-
), Object.seal(context[ssrModuleExportsKey]);
|
1078
|
-
}
|
1079
|
-
runExternalModule(filepath) {
|
1080
|
-
return import(filepath);
|
1081
|
-
}
|
1082
|
-
}
|
1083
|
-
let urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict", nanoid = (size = 21) => {
|
1084
|
-
let id = "", i = size;
|
1085
|
-
for (; i--; )
|
1086
|
-
id += urlAlphabet[Math.random() * 64 | 0];
|
1087
|
-
return id;
|
1088
|
-
};
|
1089
|
-
class RemoteRunnerTransport {
|
1090
|
-
constructor(options) {
|
1091
|
-
this.options = options, this.options.onMessage(async (data) => {
|
1092
|
-
if (typeof data != "object" || !data || !data.__v) return;
|
1093
|
-
const promise = this.rpcPromises.get(data.i);
|
1094
|
-
promise && (promise.timeoutId && clearTimeout(promise.timeoutId), this.rpcPromises.delete(data.i), data.e ? promise.reject(data.e) : promise.resolve(data.r));
|
1095
|
-
});
|
1096
|
-
}
|
1097
|
-
rpcPromises = /* @__PURE__ */ new Map();
|
1098
|
-
resolve(method, ...args) {
|
1099
|
-
const promiseId = nanoid();
|
1100
|
-
return this.options.send({
|
1101
|
-
__v: !0,
|
1102
|
-
m: method,
|
1103
|
-
a: args,
|
1104
|
-
i: promiseId
|
1105
|
-
}), new Promise((resolve2, reject) => {
|
1106
|
-
const timeout = this.options.timeout ?? 6e4;
|
1107
|
-
let timeoutId;
|
1108
|
-
timeout > 0 && (timeoutId = setTimeout(() => {
|
1109
|
-
this.rpcPromises.delete(promiseId), reject(
|
1110
|
-
new Error(
|
1111
|
-
`${method}(${args.map((arg) => JSON.stringify(arg)).join(", ")}) timed out after ${timeout}ms`
|
1112
|
-
)
|
1113
|
-
);
|
1114
|
-
}, timeout), timeoutId?.unref?.()), this.rpcPromises.set(promiseId, { resolve: resolve2, reject, timeoutId });
|
1115
|
-
});
|
1116
|
-
}
|
1117
|
-
fetchModule(id, importer) {
|
1118
|
-
return this.resolve("fetchModule", id, importer);
|
1119
|
-
}
|
1120
|
-
}
|
1121
1296
|
export {
|
1122
1297
|
ESModulesEvaluator,
|
1123
1298
|
EvaluatedModules,
|
1124
1299
|
ModuleRunner,
|
1125
|
-
|
1300
|
+
createWebSocketModuleRunnerTransport,
|
1126
1301
|
ssrDynamicImportKey,
|
1127
1302
|
ssrExportAllKey,
|
1128
1303
|
ssrImportKey,
|