vite 6.0.0-beta.7 → 6.0.0-beta.9

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.
@@ -1,6 +1,6 @@
1
1
  export { parseAst, parseAstAsync } from 'rollup/parseAst';
2
- import { i as isInNodeModules, a as arraify } from './chunks/dep-Vd7gFLqj.js';
3
- export { B as BuildEnvironment, D as DevEnvironment, S as ServerHMRConnector, b as build, j as buildErrorMessage, e as createBuilder, z as createFilter, f as createIdResolver, E as createLogger, k as createRunnableDevEnvironment, c as createServer, u as createServerHotChannel, q as createServerModuleRunner, d as defineConfig, n as fetchModule, g as formatPostcssSourceMap, H as isFileLoadingAllowed, G as isFileServingAllowed, m as isRunnableDevEnvironment, l as loadConfigFromFile, I as loadEnv, y as mergeAlias, x as mergeConfig, v as moduleRunnerTransform, w as normalizePath, o as optimizeDeps, h as preprocessCSS, p as preview, r as resolveConfig, J as resolveEnvPrefix, A as rollupVersion, F as searchForWorkspaceRoot, C as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-Vd7gFLqj.js';
2
+ import { i as isInNodeModules, a as arraify } from './chunks/dep-CG5ueZZV.js';
3
+ export { B as BuildEnvironment, D as DevEnvironment, b as build, j as buildErrorMessage, e as createBuilder, z as createFilter, f as createIdResolver, E as createLogger, k as createRunnableDevEnvironment, c as createServer, u as createServerHotChannel, q as createServerModuleRunner, d as defineConfig, n as fetchModule, g as formatPostcssSourceMap, H as isFileLoadingAllowed, G as isFileServingAllowed, m as isRunnableDevEnvironment, l as loadConfigFromFile, I as loadEnv, y as mergeAlias, x as mergeConfig, v as moduleRunnerTransform, w as normalizePath, o as optimizeDeps, h as preprocessCSS, p as preview, r as resolveConfig, J as resolveEnvPrefix, A as rollupVersion, F as searchForWorkspaceRoot, C as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-CG5ueZZV.js';
4
4
  export { VERSION as version } from './constants.js';
5
5
  export { version as esbuildVersion } from 'esbuild';
6
6
  import 'node:fs';
@@ -150,35 +150,4 @@ function splitVendorChunkPlugin() {
150
150
  };
151
151
  }
152
152
 
153
- class RemoteEnvironmentTransport {
154
- constructor(options) {
155
- this.options = options;
156
- }
157
- register(environment) {
158
- this.options.onMessage(async (data) => {
159
- if (typeof data !== "object" || !data || !data.__v) return;
160
- const method = data.m;
161
- const parameters = data.a;
162
- try {
163
- const result = await environment[method](...parameters);
164
- this.options.send({
165
- __v: true,
166
- r: result,
167
- i: data.i
168
- });
169
- } catch (error) {
170
- this.options.send({
171
- __v: true,
172
- e: {
173
- name: error.name,
174
- message: error.message,
175
- stack: error.stack
176
- },
177
- i: data.i
178
- });
179
- }
180
- });
181
- }
182
- }
183
-
184
- export { RemoteEnvironmentTransport, isCSSRequest, splitVendorChunk, splitVendorChunkPlugin };
153
+ export { isCSSRequest, splitVendorChunk, splitVendorChunkPlugin };
@@ -2,6 +2,89 @@ import { ModuleNamespace, ViteHotContext } from '../../types/hot.js';
2
2
  import { HotPayload, Update } from '../../types/hmrPayload.js';
3
3
  import { InferCustomEventPayload } from '../../types/customEvent.js';
4
4
 
5
+ interface FetchFunctionOptions {
6
+ cached?: boolean;
7
+ startOffset?: number;
8
+ }
9
+ type FetchResult = CachedFetchResult | ExternalFetchResult | ViteFetchResult;
10
+ interface CachedFetchResult {
11
+ /**
12
+ * If module cached in the runner, we can just confirm
13
+ * it wasn't invalidated on the server side.
14
+ */
15
+ cache: true;
16
+ }
17
+ interface ExternalFetchResult {
18
+ /**
19
+ * The path to the externalized module starting with file://,
20
+ * by default this will be imported via a dynamic "import"
21
+ * instead of being transformed by vite and loaded with vite runner
22
+ */
23
+ externalize: string;
24
+ /**
25
+ * Type of the module. Will be used to determine if import statement is correct.
26
+ * For example, if Vite needs to throw an error if variable is not actually exported
27
+ */
28
+ type: 'module' | 'commonjs' | 'builtin' | 'network';
29
+ }
30
+ interface ViteFetchResult {
31
+ /**
32
+ * Code that will be evaluated by vite runner
33
+ * by default this will be wrapped in an async function
34
+ */
35
+ code: string;
36
+ /**
37
+ * File path of the module on disk.
38
+ * This will be resolved as import.meta.url/filename
39
+ * Will be equal to `null` for virtual modules
40
+ */
41
+ file: string | null;
42
+ /**
43
+ * Module ID in the server module graph.
44
+ */
45
+ id: string;
46
+ /**
47
+ * Module URL used in the import.
48
+ */
49
+ url: string;
50
+ /**
51
+ * Invalidate module on the client side.
52
+ */
53
+ invalidate: boolean;
54
+ }
55
+ type InvokeMethods = {
56
+ fetchModule: (id: string, importer?: string, options?: FetchFunctionOptions) => Promise<FetchResult>;
57
+ };
58
+
59
+ type ModuleRunnerTransportHandlers = {
60
+ onMessage: (data: HotPayload) => void;
61
+ onDisconnection: () => void;
62
+ };
63
+ /**
64
+ * "send and connect" or "invoke" must be implemented
65
+ */
66
+ interface ModuleRunnerTransport {
67
+ connect?(handlers: ModuleRunnerTransportHandlers): Promise<void> | void;
68
+ disconnect?(): Promise<void> | void;
69
+ send?(data: HotPayload): Promise<void> | void;
70
+ invoke?(data: HotPayload): Promise<{
71
+ r: any;
72
+ } | {
73
+ e: any;
74
+ }>;
75
+ timeout?: number;
76
+ }
77
+ interface NormalizedModuleRunnerTransport {
78
+ connect?(onMessage?: (data: HotPayload) => void): Promise<void> | void;
79
+ disconnect?(): Promise<void> | void;
80
+ send(data: HotPayload): void;
81
+ invoke<T extends keyof InvokeMethods>(name: T, data: Parameters<InvokeMethods[T]>): Promise<ReturnType<Awaited<InvokeMethods[T]>>>;
82
+ }
83
+ declare const createWebSocketModuleRunnerTransport: (options: {
84
+ createConnection: () => WebSocket;
85
+ pingInterval?: number;
86
+ }) => Required<Pick<ModuleRunnerTransport, "connect" | "disconnect" | "send">>;
87
+
5
88
  interface SourceMapLike {
6
89
  version: number;
7
90
  mappings?: string;
@@ -39,25 +122,9 @@ interface HMRLogger {
39
122
  error(msg: string | Error): void;
40
123
  debug(...msg: unknown[]): void;
41
124
  }
42
- interface HMRConnection {
43
- /**
44
- * Checked before sending messages to the client.
45
- */
46
- isReady(): boolean;
47
- /**
48
- * Send message to the client.
49
- */
50
- send(messages: HotPayload): void;
51
- }
52
- declare class HMRMessenger {
53
- private connection;
54
- constructor(connection: HMRConnection);
55
- private queue;
56
- send(payload: HotPayload): void;
57
- flush(): void;
58
- }
59
125
  declare class HMRClient {
60
126
  logger: HMRLogger;
127
+ private transport;
61
128
  private importUpdatedModule;
62
129
  hotModulesMap: Map<string, HotModule>;
63
130
  disposeMap: Map<string, (data: any) => void | Promise<void>>;
@@ -65,9 +132,9 @@ declare class HMRClient {
65
132
  dataMap: Map<string, any>;
66
133
  customListenersMap: CustomListenersMap;
67
134
  ctxToListenersMap: Map<string, CustomListenersMap>;
68
- messenger: HMRMessenger;
69
- constructor(logger: HMRLogger, connection: HMRConnection, importUpdatedModule: (update: Update) => Promise<ModuleNamespace>);
135
+ constructor(logger: HMRLogger, transport: NormalizedModuleRunnerTransport, importUpdatedModule: (update: Update) => Promise<ModuleNamespace>);
70
136
  notifyListeners<T extends string>(event: T, data: InferCustomEventPayload<T>): Promise<void>;
137
+ send(payload: HotPayload): void;
71
138
  clear(): void;
72
139
  prunePaths(paths: string[]): Promise<void>;
73
140
  protected warnFailedUpdate(err: Error, path: string | string[]): void;
@@ -160,28 +227,6 @@ interface InterceptorOptions {
160
227
  retrieveSourceMap?: RetrieveSourceMapHandler;
161
228
  }
162
229
 
163
- interface RunnerTransport {
164
- fetchModule: FetchFunction;
165
- }
166
- declare class RemoteRunnerTransport implements RunnerTransport {
167
- private readonly options;
168
- private rpcPromises;
169
- constructor(options: {
170
- send: (data: any) => void;
171
- onMessage: (handler: (data: any) => void) => void;
172
- timeout?: number;
173
- });
174
- private resolve;
175
- fetchModule(id: string, importer?: string): Promise<FetchResult>;
176
- }
177
-
178
- interface ModuleRunnerHMRConnection extends HMRConnection {
179
- /**
180
- * Configure how HMR is handled when this connection triggers an update.
181
- * This method expects that connection will start listening for HMR updates and call this callback when it's received.
182
- */
183
- onUpdate(callback: (payload: HotPayload) => void): void;
184
- }
185
230
  interface ModuleRunnerImportMeta extends ImportMeta {
186
231
  url: string;
187
232
  env: ImportMetaEnv;
@@ -213,66 +258,12 @@ interface ModuleEvaluator {
213
258
  */
214
259
  runExternalModule(file: string): Promise<any>;
215
260
  }
216
- type FetchResult = CachedFetchResult | ExternalFetchResult | ViteFetchResult;
217
- interface CachedFetchResult {
218
- /**
219
- * If module cached in the runner, we can just confirm
220
- * it wasn't invalidated on the server side.
221
- */
222
- cache: true;
223
- }
224
- interface ExternalFetchResult {
225
- /**
226
- * The path to the externalized module starting with file://,
227
- * by default this will be imported via a dynamic "import"
228
- * instead of being transformed by vite and loaded with vite runner
229
- */
230
- externalize: string;
231
- /**
232
- * Type of the module. Will be used to determine if import statement is correct.
233
- * For example, if Vite needs to throw an error if variable is not actually exported
234
- */
235
- type: 'module' | 'commonjs' | 'builtin' | 'network';
236
- }
237
- interface ViteFetchResult {
238
- /**
239
- * Code that will be evaluated by vite runner
240
- * by default this will be wrapped in an async function
241
- */
242
- code: string;
243
- /**
244
- * File path of the module on disk.
245
- * This will be resolved as import.meta.url/filename
246
- * Will be equal to `null` for virtual modules
247
- */
248
- file: string | null;
249
- /**
250
- * Module ID in the server module graph.
251
- */
252
- id: string;
253
- /**
254
- * Module URL used in the import.
255
- */
256
- url: string;
257
- /**
258
- * Invalidate module on the client side.
259
- */
260
- invalidate: boolean;
261
- }
262
261
  type ResolvedResult = (ExternalFetchResult | ViteFetchResult) & {
263
262
  url: string;
264
263
  id: string;
265
264
  };
266
265
  type FetchFunction = (id: string, importer?: string, options?: FetchFunctionOptions) => Promise<FetchResult>;
267
- interface FetchFunctionOptions {
268
- cached?: boolean;
269
- startOffset?: number;
270
- }
271
266
  interface ModuleRunnerHmr {
272
- /**
273
- * Configure how HMR communicates between the client and the server.
274
- */
275
- connection: ModuleRunnerHMRConnection;
276
267
  /**
277
268
  * Configure HMR logger.
278
269
  */
@@ -286,7 +277,7 @@ interface ModuleRunnerOptions {
286
277
  /**
287
278
  * A set of methods to communicate with the server.
288
279
  */
289
- transport: RunnerTransport;
280
+ transport: ModuleRunnerTransport;
290
281
  /**
291
282
  * Configure how source maps are resolved. Prefers `node` if `process.setSourceMapsEnabled` is available.
292
283
  * Otherwise it will use `prepareStackTrace` by default which overrides `Error.prepareStackTrace` method.
@@ -296,7 +287,7 @@ interface ModuleRunnerOptions {
296
287
  /**
297
288
  * Disable HMR or configure HMR options.
298
289
  */
299
- hmr?: false | ModuleRunnerHmr;
290
+ hmr?: boolean | ModuleRunnerHmr;
300
291
  /**
301
292
  * Custom module cache. If not provided, creates a separate module cache for each ModuleRunner instance.
302
293
  */
@@ -373,4 +364,4 @@ declare class ESModulesEvaluator implements ModuleEvaluator {
373
364
  runExternalModule(filepath: string): Promise<any>;
374
365
  }
375
366
 
376
- export { ESModulesEvaluator, EvaluatedModuleNode, EvaluatedModules, type FetchFunction, type FetchFunctionOptions, type FetchResult, type HMRConnection, type HMRLogger, type ModuleEvaluator, ModuleRunner, type ModuleRunnerContext, type ModuleRunnerHMRConnection, type ModuleRunnerHmr, type ModuleRunnerImportMeta, type ModuleRunnerOptions, RemoteRunnerTransport, type ResolvedResult, type RunnerTransport, type SSRImportMetadata, ssrDynamicImportKey, ssrExportAllKey, ssrImportKey, ssrImportMetaKey, ssrModuleExportsKey };
367
+ export { ESModulesEvaluator, EvaluatedModuleNode, EvaluatedModules, type FetchFunction, type FetchFunctionOptions, type FetchResult, type HMRLogger, type ModuleEvaluator, ModuleRunner, type ModuleRunnerContext, type ModuleRunnerHmr, type ModuleRunnerImportMeta, type ModuleRunnerOptions, type ModuleRunnerTransport, type ModuleRunnerTransportHandlers, type ResolvedResult, type SSRImportMetadata, createWebSocketModuleRunnerTransport, ssrDynamicImportKey, ssrExportAllKey, ssrImportKey, ssrImportMetaKey, ssrModuleExportsKey };
@@ -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());
@@ -408,7 +414,7 @@ class HMRContext {
408
414
  removeFromMap(this.hmrClient.customListenersMap), removeFromMap(this.newListeners);
409
415
  }
410
416
  send(event, data) {
411
- this.hmrClient.messenger.send({ type: "custom", event, data });
417
+ this.hmrClient.send({ type: "custom", event, data });
412
418
  }
413
419
  acceptDeps(deps, callback = () => {
414
420
  }) {
@@ -422,21 +428,9 @@ class HMRContext {
422
428
  }), this.hmrClient.hotModulesMap.set(this.ownerPath, mod);
423
429
  }
424
430
  }
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
431
  class HMRClient {
438
- constructor(logger, connection, importUpdatedModule) {
439
- this.logger = logger, this.importUpdatedModule = importUpdatedModule, this.messenger = new HMRMessenger(connection);
432
+ constructor(logger, transport, importUpdatedModule) {
433
+ this.logger = logger, this.transport = transport, this.importUpdatedModule = importUpdatedModule;
440
434
  }
441
435
  hotModulesMap = /* @__PURE__ */ new Map();
442
436
  disposeMap = /* @__PURE__ */ new Map();
@@ -444,11 +438,13 @@ class HMRClient {
444
438
  dataMap = /* @__PURE__ */ new Map();
445
439
  customListenersMap = /* @__PURE__ */ new Map();
446
440
  ctxToListenersMap = /* @__PURE__ */ new Map();
447
- messenger;
448
441
  async notifyListeners(event, data) {
449
442
  const cbs = this.customListenersMap.get(event);
450
443
  cbs && await Promise.allSettled(cbs.map((cb) => cb(data)));
451
444
  }
445
+ send(payload) {
446
+ this.transport.send(payload);
447
+ }
452
448
  clear() {
453
449
  this.hotModulesMap.clear(), this.disposeMap.clear(), this.pruneMap.clear(), this.dataMap.clear(), this.customListenersMap.clear(), this.ctxToListenersMap.clear();
454
450
  }
@@ -528,7 +524,181 @@ const {${missingBindings.join(", ")}} = pkg;
528
524
  }
529
525
  }
530
526
  }
531
- const ssrModuleExportsKey = "__vite_ssr_exports__", ssrImportKey = "__vite_ssr_import__", ssrDynamicImportKey = "__vite_ssr_dynamic_import__", ssrExportAllKey = "__vite_ssr_exportAll__", ssrImportMetaKey = "__vite_ssr_import_meta__", noop = () => {
527
+ let urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict", nanoid = (size = 21) => {
528
+ let id = "", i = size;
529
+ for (; i--; )
530
+ id += urlAlphabet[Math.random() * 64 | 0];
531
+ return id;
532
+ };
533
+ const createInvokeableTransport = (transport) => {
534
+ if (transport.invoke)
535
+ return {
536
+ ...transport,
537
+ async invoke(name, data) {
538
+ const result = await transport.invoke({
539
+ type: "custom",
540
+ event: "vite:invoke",
541
+ data: {
542
+ id: "send",
543
+ name,
544
+ data
545
+ }
546
+ });
547
+ if ("e" in result)
548
+ throw result.e;
549
+ return result.r;
550
+ }
551
+ };
552
+ if (!transport.send || !transport.connect)
553
+ throw new Error(
554
+ "transport must implement send and connect when invoke is not implemented"
555
+ );
556
+ const rpcPromises = /* @__PURE__ */ new Map();
557
+ return {
558
+ ...transport,
559
+ connect({ onMessage, onDisconnection }) {
560
+ return transport.connect({
561
+ onMessage(payload) {
562
+ if (payload.type === "custom" && payload.event === "vite:invoke") {
563
+ const data = payload.data;
564
+ if (data.id.startsWith("response:")) {
565
+ const invokeId = data.id.slice(9), promise = rpcPromises.get(invokeId);
566
+ if (!promise) return;
567
+ promise.timeoutId && clearTimeout(promise.timeoutId), rpcPromises.delete(invokeId);
568
+ const { e, r } = data.data;
569
+ e ? promise.reject(e) : promise.resolve(r);
570
+ return;
571
+ }
572
+ }
573
+ onMessage(payload);
574
+ },
575
+ onDisconnection
576
+ });
577
+ },
578
+ disconnect() {
579
+ return rpcPromises.forEach((promise) => {
580
+ promise.reject(
581
+ new Error(
582
+ `transport was disconnected, cannot call ${JSON.stringify(promise.name)}`
583
+ )
584
+ );
585
+ }), rpcPromises.clear(), transport.disconnect?.();
586
+ },
587
+ send(data) {
588
+ return transport.send(data);
589
+ },
590
+ async invoke(name, data) {
591
+ const promiseId = nanoid(), wrappedData = {
592
+ type: "custom",
593
+ event: "vite:invoke",
594
+ data: {
595
+ name,
596
+ id: `send:${promiseId}`,
597
+ data
598
+ }
599
+ }, sendPromise = transport.send(wrappedData), { promise, resolve: resolve2, reject } = promiseWithResolvers(), timeout = transport.timeout ?? 6e4;
600
+ let timeoutId;
601
+ return timeout > 0 && (timeoutId = setTimeout(() => {
602
+ rpcPromises.delete(promiseId), reject(
603
+ new Error(
604
+ `transport invoke timed out after ${timeout}ms (data: ${JSON.stringify(wrappedData)})`
605
+ )
606
+ );
607
+ }, timeout), timeoutId?.unref?.()), rpcPromises.set(promiseId, { resolve: resolve2, reject, name, timeoutId }), sendPromise && sendPromise.catch((err) => {
608
+ clearTimeout(timeoutId), rpcPromises.delete(promiseId), reject(err);
609
+ }), await promise;
610
+ }
611
+ };
612
+ }, normalizeModuleRunnerTransport = (transport) => {
613
+ const invokeableTransport = createInvokeableTransport(transport);
614
+ let isConnected = !invokeableTransport.connect, connectingPromise;
615
+ return {
616
+ ...transport,
617
+ ...invokeableTransport.connect ? {
618
+ async connect(onMessage) {
619
+ if (isConnected) return;
620
+ if (connectingPromise) {
621
+ await connectingPromise;
622
+ return;
623
+ }
624
+ const maybePromise = invokeableTransport.connect({
625
+ onMessage: onMessage ?? (() => {
626
+ }),
627
+ onDisconnection() {
628
+ isConnected = !1;
629
+ }
630
+ });
631
+ maybePromise && (connectingPromise = maybePromise, await connectingPromise, connectingPromise = void 0), isConnected = !0;
632
+ }
633
+ } : {},
634
+ ...invokeableTransport.disconnect ? {
635
+ async disconnect() {
636
+ isConnected && (connectingPromise && await connectingPromise, isConnected = !1, await invokeableTransport.disconnect());
637
+ }
638
+ } : {},
639
+ async send(data) {
640
+ if (invokeableTransport.send) {
641
+ if (!isConnected)
642
+ if (connectingPromise)
643
+ await connectingPromise;
644
+ else
645
+ throw new Error("send was called before connect");
646
+ await invokeableTransport.send(data);
647
+ }
648
+ },
649
+ async invoke(name, data) {
650
+ if (!isConnected)
651
+ if (connectingPromise)
652
+ await connectingPromise;
653
+ else
654
+ throw new Error("invoke was called before connect");
655
+ return invokeableTransport.invoke(name, data);
656
+ }
657
+ };
658
+ }, createWebSocketModuleRunnerTransport = (options) => {
659
+ const pingInterval = options.pingInterval ?? 3e4;
660
+ let ws, pingIntervalId;
661
+ return {
662
+ async connect({ onMessage, onDisconnection }) {
663
+ const socket = options.createConnection();
664
+ socket.addEventListener("message", async ({ data }) => {
665
+ onMessage(JSON.parse(data));
666
+ });
667
+ let isOpened = socket.readyState === socket.OPEN;
668
+ isOpened || await new Promise((resolve2, reject) => {
669
+ socket.addEventListener(
670
+ "open",
671
+ () => {
672
+ isOpened = !0, resolve2();
673
+ },
674
+ { once: !0 }
675
+ ), socket.addEventListener("close", async () => {
676
+ if (!isOpened) {
677
+ reject(new Error("WebSocket closed without opened."));
678
+ return;
679
+ }
680
+ onMessage({
681
+ type: "custom",
682
+ event: "vite:ws:disconnect",
683
+ data: { webSocket: socket }
684
+ }), onDisconnection();
685
+ });
686
+ }), onMessage({
687
+ type: "custom",
688
+ event: "vite:ws:connect",
689
+ data: { webSocket: socket }
690
+ }), ws = socket, pingIntervalId = setInterval(() => {
691
+ socket.readyState === socket.OPEN && socket.send(JSON.stringify({ type: "ping" }));
692
+ }, pingInterval);
693
+ },
694
+ disconnect() {
695
+ clearInterval(pingIntervalId), ws?.close();
696
+ },
697
+ send(data) {
698
+ ws.send(JSON.stringify(data));
699
+ }
700
+ };
701
+ }, ssrModuleExportsKey = "__vite_ssr_exports__", ssrImportKey = "__vite_ssr_import__", ssrDynamicImportKey = "__vite_ssr_dynamic_import__", ssrExportAllKey = "__vite_ssr_exportAll__", ssrImportMetaKey = "__vite_ssr_import_meta__", noop = () => {
532
702
  }, silentConsole = {
533
703
  debug: noop,
534
704
  error: noop
@@ -545,7 +715,7 @@ async function handleHotPayload(runner, payload) {
545
715
  if (!(!hmrClient || runner.isClosed()))
546
716
  switch (payload.type) {
547
717
  case "connected":
548
- hmrClient.logger.debug("connected."), hmrClient.messenger.flush();
718
+ hmrClient.logger.debug("connected.");
549
719
  break;
550
720
  case "update":
551
721
  await hmrClient.notifyListeners("vite:beforeUpdate", payload), await Promise.all(
@@ -584,6 +754,8 @@ ${err.stack}`
584
754
  );
585
755
  break;
586
756
  }
757
+ case "ping":
758
+ break;
587
759
  default:
588
760
  return payload;
589
761
  }
@@ -851,11 +1023,20 @@ class ModuleRunner {
851
1023
  constructor(options, evaluator, debug) {
852
1024
  this.options = options, this.evaluator = evaluator, this.debug = debug;
853
1025
  const root = this.options.root;
854
- this.root = root[root.length - 1] === "/" ? root : `${root}/`, this.evaluatedModules = options.evaluatedModules ?? new EvaluatedModules(), this.transport = options.transport, typeof options.hmr == "object" && (this.hmrClient = new HMRClient(
855
- options.hmr.logger === !1 ? silentConsole : options.hmr.logger || hmrLogger,
856
- options.hmr.connection,
857
- ({ acceptedPath }) => this.import(acceptedPath)
858
- ), options.hmr.connection.onUpdate(createHMRHandler(this))), options.sourcemapInterceptor !== !1 && (this.resetSourceMapSupport = enableSourceMapSupport(this));
1026
+ if (this.root = root[root.length - 1] === "/" ? root : `${root}/`, this.evaluatedModules = options.evaluatedModules ?? new EvaluatedModules(), this.transport = normalizeModuleRunnerTransport(options.transport), options.hmr) {
1027
+ const resolvedHmrLogger = options.hmr === !0 || options.hmr.logger === void 0 ? hmrLogger : options.hmr.logger === !1 ? silentConsole : options.hmr.logger;
1028
+ if (this.hmrClient = new HMRClient(
1029
+ resolvedHmrLogger,
1030
+ this.transport,
1031
+ ({ acceptedPath }) => this.import(acceptedPath)
1032
+ ), !this.transport.connect)
1033
+ throw new Error(
1034
+ "HMR is not supported by this runner transport, but `hmr` option was set to true"
1035
+ );
1036
+ this.transport.connect(createHMRHandler(this));
1037
+ } else
1038
+ this.transport.connect?.();
1039
+ options.sourcemapInterceptor !== !1 && (this.resetSourceMapSupport = enableSourceMapSupport(this));
859
1040
  }
860
1041
  evaluatedModules;
861
1042
  hmrClient;
@@ -889,7 +1070,7 @@ class ModuleRunner {
889
1070
  * This method doesn't stop the HMR connection.
890
1071
  */
891
1072
  async close() {
892
- this.resetSourceMapSupport?.(), this.clearCache(), this.hmrClient = void 0, this.closed = !0;
1073
+ this.resetSourceMapSupport?.(), this.clearCache(), this.hmrClient = void 0, this.closed = !0, await this.transport.disconnect?.();
893
1074
  }
894
1075
  /**
895
1076
  * Returns `true` if the runtime has been closed by calling `close()` method.
@@ -965,10 +1146,14 @@ ${getStack()}`
965
1146
  this.debug?.("[module runner] fetching", url);
966
1147
  const isCached = !!(typeof cachedModule == "object" && cachedModule.meta), fetchedModule = (
967
1148
  // fast return for established externalized pattern
968
- url.startsWith("data:") ? { externalize: url, type: "builtin" } : await this.transport.fetchModule(url, importer, {
969
- cached: isCached,
970
- startOffset: this.evaluator.startOffset
971
- })
1149
+ url.startsWith("data:") ? { externalize: url, type: "builtin" } : await this.transport.invoke("fetchModule", [
1150
+ url,
1151
+ importer,
1152
+ {
1153
+ cached: isCached,
1154
+ startOffset: this.evaluator.startOffset
1155
+ }
1156
+ ])
972
1157
  );
973
1158
  if ("cache" in fetchedModule) {
974
1159
  if (!cachedModule || !cachedModule.meta)
@@ -1080,49 +1265,11 @@ class ESModulesEvaluator {
1080
1265
  return import(filepath);
1081
1266
  }
1082
1267
  }
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
1268
  export {
1122
1269
  ESModulesEvaluator,
1123
1270
  EvaluatedModules,
1124
1271
  ModuleRunner,
1125
- RemoteRunnerTransport,
1272
+ createWebSocketModuleRunnerTransport,
1126
1273
  ssrDynamicImportKey,
1127
1274
  ssrExportAllKey,
1128
1275
  ssrImportKey,
@@ -3547,10 +3547,8 @@ function loadPackageData(pkgPath) {
3547
3547
  function getResolveCacheKey(key, options) {
3548
3548
  return [
3549
3549
  key,
3550
- options.webCompatible ? "1" : "0",
3551
3550
  options.isRequire ? "1" : "0",
3552
3551
  options.conditions.join("_"),
3553
- options.overrideConditions?.join("_") || "",
3554
3552
  options.extensions.join("_"),
3555
3553
  options.mainFields.join("_")
3556
3554
  ].join("|");
@@ -3569,7 +3567,7 @@ const DEBUG = process.env.DEBUG;
3569
3567
  function createDebugger(namespace, options = {}) {
3570
3568
  const log = debug$2(namespace);
3571
3569
  const { onlyWhenFocused, depth } = options;
3572
- if (depth && log.inspectOpts.depth == null) {
3570
+ if (depth && log.inspectOpts && log.inspectOpts.depth == null) {
3573
3571
  log.inspectOpts.depth = options.depth;
3574
3572
  }
3575
3573
  let enabled = log.enabled;