@cloudflare/vite-plugin 2.0.0-rc.1 → 2.0.0-rc.2

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,18 +1,13 @@
1
1
  import { DurableObject, WorkerEntrypoint, WorkflowEntrypoint } from "cloudflare:workers";
2
2
  import { ModuleRunner, ssrDynamicImportKey, ssrModuleExportsKey } from "vite/module-runner";
3
-
4
3
  //#region src/shared.ts
5
4
  const UNKNOWN_HOST = "http://localhost";
6
- const INIT_PATH = "/__vite_plugin_cloudflare_init__";
7
- const GET_EXPORT_TYPES_PATH = "/__vite_plugin_cloudflare_get_export_types__";
8
5
  const WORKER_ENTRY_PATH_HEADER = "__VITE_WORKER_ENTRY_PATH__";
9
6
  const IS_ENTRY_WORKER_HEADER = "__VITE_IS_ENTRY_WORKER__";
10
7
  const ENVIRONMENT_NAME_HEADER = "__VITE_ENVIRONMENT_NAME__";
11
- const IS_PARENT_ENVIRONMENT_HEADER = "__VITE_IS_PARENT_ENVIRONMENT__";
12
8
  const virtualPrefix = "virtual:cloudflare/";
13
9
  const VIRTUAL_WORKER_ENTRY = `${virtualPrefix}worker-entry`;
14
10
  const VIRTUAL_EXPORT_TYPES = `${virtualPrefix}export-types`;
15
-
16
11
  //#endregion
17
12
  //#region src/workers/runner-worker/env.ts
18
13
  /**
@@ -21,10 +16,9 @@ const VIRTUAL_EXPORT_TYPES = `${virtualPrefix}export-types`;
21
16
  * @returns The user-defined env
22
17
  */
23
18
  function stripInternalEnv(internalEnv) {
24
- const { __VITE_RUNNER_OBJECT__: __VITE_RUNNER_OBJECT__$1, __VITE_INVOKE_MODULE__, __VITE_UNSAFE_EVAL__,...userEnv } = internalEnv;
19
+ const { __VITE_RUNNER_OBJECT__, __VITE_INVOKE_MODULE__, __VITE_UNSAFE_EVAL__, ...userEnv } = internalEnv;
25
20
  return userEnv;
26
21
  }
27
-
28
22
  //#endregion
29
23
  //#region src/workers/runner-worker/errors.ts
30
24
  /**
@@ -56,7 +50,6 @@ async function maybeCaptureError(options, fn) {
56
50
  });
57
51
  }
58
52
  }
59
-
60
53
  //#endregion
61
54
  //#region src/workers/runner-worker/keys.ts
62
55
  /** Keys that should be ignored during RPC property access */
@@ -84,7 +77,6 @@ const DURABLE_OBJECT_KEYS = [
84
77
  ];
85
78
  /** Available methods for `WorkflowEntrypoint` classes */
86
79
  const WORKFLOW_ENTRYPOINT_KEYS = ["run"];
87
-
88
80
  //#endregion
89
81
  //#region src/workers/runner-worker/module-runner.ts
90
82
  /** Module runner instances keyed by environment name */
@@ -127,11 +119,11 @@ var __VITE_RUNNER_OBJECT__ = class extends DurableObject {
127
119
  */
128
120
  async fetch(request) {
129
121
  const { pathname } = new URL(request.url);
130
- if (pathname !== INIT_PATH) throw new Error(`__VITE_RUNNER_OBJECT__ received invalid pathname: "${pathname}"`);
122
+ if (pathname !== "/__vite_plugin_cloudflare_init__") throw new Error(`__VITE_RUNNER_OBJECT__ received invalid pathname: "${pathname}"`);
131
123
  const environmentName = request.headers.get(ENVIRONMENT_NAME_HEADER);
132
124
  if (!environmentName) throw new Error(`__VITE_RUNNER_OBJECT__ received request without "${ENVIRONMENT_NAME_HEADER}" header`);
133
125
  if (moduleRunners.has(environmentName)) throw new Error(`Module runner already initialized for environment: "${environmentName}"`);
134
- if (request.headers.get(IS_PARENT_ENVIRONMENT_HEADER) === "true") {
126
+ if (request.headers.get("__VITE_IS_PARENT_ENVIRONMENT__") === "true") {
135
127
  parentEnvironmentName = environmentName;
136
128
  globalThis.__VITE_ENVIRONMENT_RUNNER_IMPORT__ = async (envName, id) => {
137
129
  const runner = moduleRunners.get(envName);
@@ -236,11 +228,11 @@ async function createModuleRunner(env, webSocket, environmentName) {
236
228
  /**
237
229
  * Retrieves a specific export from a Worker entry module using the module runner.
238
230
  */
239
- async function getWorkerEntryExport(workerEntryPath$1, exportName) {
231
+ async function getWorkerEntryExport(workerEntryPath, exportName) {
240
232
  if (!parentEnvironmentName) throw new Error(`Parent environment not initialized`);
241
233
  const module = await globalThis.__VITE_ENVIRONMENT_RUNNER_IMPORT__(parentEnvironmentName, VIRTUAL_WORKER_ENTRY);
242
234
  const exportValue = typeof module === "object" && module !== null && exportName in module && module[exportName];
243
- if (!exportValue) throw new Error(`"${workerEntryPath$1}" does not define a "${exportName}" export.`);
235
+ if (!exportValue) throw new Error(`"${workerEntryPath}" does not define a "${exportName}" export.`);
244
236
  return exportValue;
245
237
  }
246
238
  /**
@@ -251,7 +243,6 @@ async function getWorkerEntryExportTypes() {
251
243
  const { getExportTypes } = await globalThis.__VITE_ENVIRONMENT_RUNNER_IMPORT__(parentEnvironmentName, VIRTUAL_EXPORT_TYPES);
252
244
  return getExportTypes(await globalThis.__VITE_ENVIRONMENT_RUNNER_IMPORT__(parentEnvironmentName, VIRTUAL_WORKER_ENTRY));
253
245
  }
254
-
255
246
  //#endregion
256
247
  //#region src/workers/runner-worker/index.ts
257
248
  /** The path to the Worker entry file. We store it in the module scope so that it is easily accessible in error messages etc.. */
@@ -341,8 +332,8 @@ function createWorkerEntrypointWrapper(exportName) {
341
332
  if (key === "fetch") {
342
333
  const request = arg;
343
334
  const url = new URL(request.url);
344
- if (url.pathname === INIT_PATH) {
345
- if (request.headers.get(IS_PARENT_ENVIRONMENT_HEADER) === "true") {
335
+ if (url.pathname === "/__vite_plugin_cloudflare_init__") {
336
+ if (request.headers.get("__VITE_IS_PARENT_ENVIRONMENT__") === "true") {
346
337
  const workerEntryPathHeader = request.headers.get(WORKER_ENTRY_PATH_HEADER);
347
338
  if (!workerEntryPathHeader) throw new Error(`Unexpected error: "${WORKER_ENTRY_PATH_HEADER}" header not set.`);
348
339
  const isEntryWorkerHeader = request.headers.get(IS_ENTRY_WORKER_HEADER);
@@ -352,7 +343,7 @@ function createWorkerEntrypointWrapper(exportName) {
352
343
  }
353
344
  return this.env.__VITE_RUNNER_OBJECT__.get("singleton").fetch(request);
354
345
  }
355
- if (url.pathname === GET_EXPORT_TYPES_PATH) {
346
+ if (url.pathname === "/__vite_plugin_cloudflare_get_export_types__") {
356
347
  const workerEntryExportTypes = await getWorkerEntryExportTypes();
357
348
  return Response.json(workerEntryExportTypes);
358
349
  }
@@ -415,9 +406,10 @@ function createDurableObjectWrapper(exportName) {
415
406
  if (typeof ctor !== "function") throw new TypeError(`Expected "${exportName}" export of "${workerEntryPath}" to be a subclass of \`DurableObject\`.`);
416
407
  if (!this[kInstance] || this[kInstance].ctor !== ctor) {
417
408
  const userEnv = stripInternalEnv(this.env);
409
+ const instance = new ctor(this.ctx, userEnv);
418
410
  this[kInstance] = {
419
411
  ctor,
420
- instance: new ctor(this.ctx, userEnv)
412
+ instance
421
413
  };
422
414
  await this.ctx.blockConcurrencyWhile(async () => {});
423
415
  }
@@ -451,6 +443,5 @@ function createWorkflowEntrypointWrapper(exportName) {
451
443
  };
452
444
  return Wrapper;
453
445
  }
454
-
455
446
  //#endregion
456
- export { __VITE_RUNNER_OBJECT__, createDurableObjectWrapper, createWorkerEntrypointWrapper, createWorkflowEntrypointWrapper };
447
+ export { __VITE_RUNNER_OBJECT__, createDurableObjectWrapper, createWorkerEntrypointWrapper, createWorkflowEntrypointWrapper };
@@ -39,7 +39,8 @@ const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
39
39
  function normalizeWindowsPath(input = "") {
40
40
  return input && input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
41
41
  }
42
- const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/, _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
42
+ const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
43
+ const _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
43
44
  function cwd() {
44
45
  return typeof process < "u" && typeof process.cwd == "function" ? process.cwd().replace(/\\/g, "/") : "/";
45
46
  }
@@ -79,14 +80,24 @@ function normalizeString(path, allowAboveRoot) {
79
80
  }
80
81
  const isAbsolute = function(p) {
81
82
  return _IS_ABSOLUTE_RE.test(p);
82
- }, dirname = function(p) {
83
+ };
84
+ const dirname = function(p) {
83
85
  let segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
84
86
  return segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0]) && (segments[0] += "/"), segments.join("/") || (isAbsolute(p) ? "/" : ".");
85
- }, decodeBase64 = typeof atob < "u" ? atob : (str) => Buffer.from(str, "base64").toString("utf-8"), percentRegEx = /%/g, backslashRegEx = /\\/g, newlineRegEx = /\n/g, carriageReturnRegEx = /\r/g, tabRegEx = /\t/g, questionRegex = /\?/g, hashRegex = /#/g;
87
+ };
88
+ const decodeBase64 = typeof atob < "u" ? atob : (str) => Buffer.from(str, "base64").toString("utf-8");
89
+ const percentRegEx = /%/g;
90
+ const backslashRegEx = /\\/g;
91
+ const newlineRegEx = /\n/g;
92
+ const carriageReturnRegEx = /\r/g;
93
+ const tabRegEx = /\t/g;
94
+ const questionRegex = /\?/g;
95
+ const hashRegex = /#/g;
86
96
  function encodePathChars(filepath) {
87
97
  return filepath.indexOf("%") !== -1 && (filepath = filepath.replace(percentRegEx, "%25")), !isWindows && filepath.indexOf("\\") !== -1 && (filepath = filepath.replace(backslashRegEx, "%5C")), filepath.indexOf("\n") !== -1 && (filepath = filepath.replace(newlineRegEx, "%0A")), filepath.indexOf("\r") !== -1 && (filepath = filepath.replace(carriageReturnRegEx, "%0D")), filepath.indexOf(" ") !== -1 && (filepath = filepath.replace(tabRegEx, "%09")), filepath;
88
98
  }
89
- const posixDirname = dirname, posixResolve = resolve;
99
+ const posixDirname = dirname;
100
+ const posixResolve = resolve;
90
101
  function posixPathToFileHref(posixPath) {
91
102
  let resolved = posixResolve(posixPath), filePathLast = posixPath.charCodeAt(posixPath.length - 1);
92
103
  return (filePathLast === 47 || isWindows && filePathLast === 92) && resolved[resolved.length - 1] !== "/" && (resolved += "/"), resolved = encodePathChars(resolved), resolved.indexOf("?") !== -1 && (resolved = resolved.replace(questionRegex, "%3F")), resolved.indexOf("#") !== -1 && (resolved = resolved.replace(hashRegex, "%23")), new URL(`file://${resolved}`).href;
@@ -94,7 +105,10 @@ function posixPathToFileHref(posixPath) {
94
105
  function toWindowsPath(path) {
95
106
  return path.replace(/\//g, "\\");
96
107
  }
97
- var comma = 44, chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", intToChar = new Uint8Array(64), charToInt = new Uint8Array(128);
108
+ var comma = 44;
109
+ var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
110
+ var intToChar = /* @__PURE__ */ new Uint8Array(64);
111
+ var charToInt = /* @__PURE__ */ new Uint8Array(128);
98
112
  for (let i = 0; i < chars.length; i++) {
99
113
  let c = chars.charCodeAt(i);
100
114
  intToChar[i] = c, charToInt[c] = i;
@@ -154,7 +168,12 @@ function sort(line) {
154
168
  function sortComparator(a, b) {
155
169
  return a[0] - b[0];
156
170
  }
157
- var COLUMN = 0, SOURCES_INDEX = 1, SOURCE_LINE = 2, SOURCE_COLUMN = 3, NAMES_INDEX = 4, found = !1;
171
+ var COLUMN = 0;
172
+ var SOURCES_INDEX = 1;
173
+ var SOURCE_LINE = 2;
174
+ var SOURCE_COLUMN = 3;
175
+ var NAMES_INDEX = 4;
176
+ var found = !1;
158
177
  function binarySearch(haystack, needle, low, high) {
159
178
  for (; low <= high;) {
160
179
  let mid = low + (high - low >> 1), cmp = haystack[mid][COLUMN] - needle;
@@ -179,7 +198,10 @@ function memoizedBinarySearch(haystack, needle, state, key) {
179
198
  }
180
199
  return state.lastKey = key, state.lastNeedle = needle, state.lastIndex = binarySearch(haystack, needle, low, high);
181
200
  }
182
- var LINE_GTR_ZERO = "`line` must be greater than 0 (lines start at line 1)", COL_GTR_EQ_ZERO = "`column` must be greater than or equal to 0 (columns start at column 0)", LEAST_UPPER_BOUND = -1, GREATEST_LOWER_BOUND = 1;
201
+ var LINE_GTR_ZERO = "`line` must be greater than 0 (lines start at line 1)";
202
+ var COL_GTR_EQ_ZERO = "`column` must be greater than or equal to 0 (columns start at column 0)";
203
+ var LEAST_UPPER_BOUND = -1;
204
+ var GREATEST_LOWER_BOUND = 1;
183
205
  function cast(map) {
184
206
  return map;
185
207
  }
@@ -250,7 +272,8 @@ var EvaluatedModuleNode = class {
250
272
  constructor(id, url) {
251
273
  this.id = id, this.url = url, this.file = cleanUrl(id);
252
274
  }
253
- }, EvaluatedModules = class {
275
+ };
276
+ var EvaluatedModules = class {
254
277
  idToModuleMap = /* @__PURE__ */ new Map();
255
278
  fileToModulesMap = /* @__PURE__ */ new Map();
256
279
  urlToIdModuleMap = /* @__PURE__ */ new Map();
@@ -290,7 +313,7 @@ var EvaluatedModuleNode = class {
290
313
  this.idToModuleMap.clear(), this.fileToModulesMap.clear(), this.urlToIdModuleMap.clear();
291
314
  }
292
315
  };
293
- const prefixedBuiltins = new Set([
316
+ const prefixedBuiltins = /* @__PURE__ */ new Set([
294
317
  "node:sea",
295
318
  "node:sqlite",
296
319
  "node:test",
@@ -380,7 +403,8 @@ var HMRContext = class {
380
403
  fn: callback
381
404
  }), this.hmrClient.hotModulesMap.set(this.ownerPath, mod);
382
405
  }
383
- }, HMRClient = class {
406
+ };
407
+ var HMRClient = class {
384
408
  hotModulesMap = /* @__PURE__ */ new Map();
385
409
  disposeMap = /* @__PURE__ */ new Map();
386
410
  pruneMap = /* @__PURE__ */ new Map();
@@ -548,7 +572,8 @@ const createInvokeableTransport = (transport) => {
548
572
  }
549
573
  }
550
574
  };
551
- }, normalizeModuleRunnerTransport = (transport) => {
575
+ };
576
+ const normalizeModuleRunnerTransport = (transport) => {
552
577
  let invokeableTransport = createInvokeableTransport(transport), isConnected = !invokeableTransport.connect, connectingPromise;
553
578
  return {
554
579
  ...transport,
@@ -582,7 +607,8 @@ const createInvokeableTransport = (transport) => {
582
607
  return invokeableTransport.invoke(name, data);
583
608
  }
584
609
  };
585
- }, createWebSocketModuleRunnerTransport = (options) => {
610
+ };
611
+ const createWebSocketModuleRunnerTransport = (options) => {
586
612
  let pingInterval = options.pingInterval ?? 3e4, ws, pingIntervalId;
587
613
  return {
588
614
  async connect({ onMessage, onDisconnection }) {
@@ -620,10 +646,19 @@ const createInvokeableTransport = (transport) => {
620
646
  ws.send(JSON.stringify(data));
621
647
  }
622
648
  };
623
- }, ssrModuleExportsKey = "__vite_ssr_exports__", ssrImportKey = "__vite_ssr_import__", ssrDynamicImportKey = "__vite_ssr_dynamic_import__", ssrExportAllKey = "__vite_ssr_exportAll__", ssrExportNameKey = "__vite_ssr_exportName__", ssrImportMetaKey = "__vite_ssr_import_meta__", noop = () => {}, silentConsole = {
649
+ };
650
+ const ssrModuleExportsKey = "__vite_ssr_exports__";
651
+ const ssrImportKey = "__vite_ssr_import__";
652
+ const ssrDynamicImportKey = "__vite_ssr_dynamic_import__";
653
+ const ssrExportAllKey = "__vite_ssr_exportAll__";
654
+ const ssrExportNameKey = "__vite_ssr_exportName__";
655
+ const ssrImportMetaKey = "__vite_ssr_import_meta__";
656
+ const noop = () => {};
657
+ const silentConsole = {
624
658
  debug: noop,
625
659
  error: noop
626
- }, hmrLogger = {
660
+ };
661
+ const hmrLogger = {
627
662
  debug: (...msg) => console.log("[vite]", ...msg),
628
663
  error: (error) => console.log("[vite]", error)
629
664
  };
@@ -715,13 +750,20 @@ function findAllEntrypoints(runner, entrypoints = /* @__PURE__ */ new Set()) {
715
750
  for (let mod of runner.evaluatedModules.idToModuleMap.values()) mod.importers.size || entrypoints.add(mod.url);
716
751
  return entrypoints;
717
752
  }
718
- const sourceMapCache = {}, fileContentsCache = {}, evaluatedModulesCache = /* @__PURE__ */ new Set(), retrieveFileHandlers = /* @__PURE__ */ new Set(), retrieveSourceMapHandlers = /* @__PURE__ */ new Set(), createExecHandlers = (handlers) => ((...args) => {
753
+ const sourceMapCache = {};
754
+ const fileContentsCache = {};
755
+ const evaluatedModulesCache = /* @__PURE__ */ new Set();
756
+ const retrieveFileHandlers = /* @__PURE__ */ new Set();
757
+ const retrieveSourceMapHandlers = /* @__PURE__ */ new Set();
758
+ const createExecHandlers = (handlers) => ((...args) => {
719
759
  for (let handler of handlers) {
720
760
  let result = handler(...args);
721
761
  if (result) return result;
722
762
  }
723
763
  return null;
724
- }), retrieveFileFromHandlers = createExecHandlers(retrieveFileHandlers), retrieveSourceMapFromHandlers = createExecHandlers(retrieveSourceMapHandlers);
764
+ });
765
+ const retrieveFileFromHandlers = createExecHandlers(retrieveFileHandlers);
766
+ const retrieveSourceMapFromHandlers = createExecHandlers(retrieveSourceMapHandlers);
725
767
  let overridden = !1;
726
768
  const originalPrepare = Error.prepareStackTrace;
727
769
  function resetInterceptor(runner, options) {
@@ -909,7 +951,8 @@ var ESModulesEvaluator = class {
909
951
  return import(filepath);
910
952
  }
911
953
  };
912
- const customizationHookNamespace = "vite-module-runner:import-meta-resolve/v1/", customizationHooksModule = `
954
+ const customizationHookNamespace = "vite-module-runner:import-meta-resolve/v1/";
955
+ const customizationHooksModule = `
913
956
 
914
957
  export async function resolve(specifier, context, nextResolve) {
915
958
  if (specifier.startsWith(${JSON.stringify(customizationHookNamespace)})) {
@@ -1124,6 +1167,5 @@ function exportAll(exports, sourceModule) {
1124
1167
  } catch {}
1125
1168
  }
1126
1169
  }
1127
-
1128
1170
  //#endregion
1129
- export { ESModulesEvaluator, EvaluatedModules, ModuleRunner, createDefaultImportMeta, createNodeImportMeta, createWebSocketModuleRunnerTransport, normalizeModuleId, ssrDynamicImportKey, ssrExportAllKey, ssrExportNameKey, ssrImportKey, ssrImportMetaKey, ssrModuleExportsKey };
1171
+ export { ESModulesEvaluator, EvaluatedModules, ModuleRunner, createDefaultImportMeta, createNodeImportMeta, createWebSocketModuleRunnerTransport, normalizeModuleId, ssrDynamicImportKey, ssrExportAllKey, ssrExportNameKey, ssrImportKey, ssrImportMetaKey, ssrModuleExportsKey };
@@ -29,16 +29,17 @@ function getAsyncFunctionDeclarationPaddingLineCount() {
29
29
  return asyncFunctionDeclarationPaddingLineCount;
30
30
  }
31
31
  function promiseWithResolvers() {
32
- let resolve$1, reject;
32
+ let resolve, reject;
33
33
  return {
34
34
  promise: new Promise((_resolve, _reject) => {
35
- resolve$1 = _resolve, reject = _reject;
35
+ resolve = _resolve, reject = _reject;
36
36
  }),
37
- resolve: resolve$1,
37
+ resolve,
38
38
  reject
39
39
  };
40
40
  }
41
- const percentEncodedRE = /(?:%[0-9a-f]{2})+/gi, whitespaceOnlyRE = /^\s+$/;
41
+ const percentEncodedRE = /(?:%[0-9a-f]{2})+/gi;
42
+ const whitespaceOnlyRE = /^\s+$/;
42
43
  /** Reverses {@link encodeSourceURL}. */
43
44
  function decodeSourceURL(url) {
44
45
  return url.replace(percentEncodedRE, (match) => {
@@ -51,7 +52,10 @@ function decodeSourceURL(url) {
51
52
  return whitespaceOnlyRE.test(decoded) ? decoded : match;
52
53
  });
53
54
  }
54
- var comma = 44, chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", intToChar = /* @__PURE__ */ new Uint8Array(64), charToInt = /* @__PURE__ */ new Uint8Array(128);
55
+ var comma = 44;
56
+ var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
57
+ var intToChar = /* @__PURE__ */ new Uint8Array(64);
58
+ var charToInt = /* @__PURE__ */ new Uint8Array(128);
55
59
  for (let i = 0; i < chars.length; i++) {
56
60
  let c = chars.charCodeAt(i);
57
61
  intToChar[i] = c, charToInt[c] = i;
@@ -113,7 +117,12 @@ function sort(line) {
113
117
  function sortComparator(a, b) {
114
118
  return a[0] - b[0];
115
119
  }
116
- var COLUMN = 0, SOURCES_INDEX = 1, SOURCE_LINE = 2, SOURCE_COLUMN = 3, NAMES_INDEX = 4, found = !1;
120
+ var COLUMN = 0;
121
+ var SOURCES_INDEX = 1;
122
+ var SOURCE_LINE = 2;
123
+ var SOURCE_COLUMN = 3;
124
+ var NAMES_INDEX = 4;
125
+ var found = !1;
117
126
  function binarySearch(haystack, needle, low, high) {
118
127
  for (; low <= high;) {
119
128
  let mid = low + (high - low >> 1), cmp = haystack[mid][COLUMN] - needle;
@@ -138,7 +147,8 @@ function memoizedBinarySearch(haystack, needle, state, key) {
138
147
  }
139
148
  return state.lastKey = key, state.lastNeedle = needle, state.lastIndex = binarySearch(haystack, needle, low, high);
140
149
  }
141
- var LINE_GTR_ZERO = "`line` must be greater than 0 (lines start at line 1)", COL_GTR_EQ_ZERO = "`column` must be greater than or equal to 0 (columns start at column 0)";
150
+ var LINE_GTR_ZERO = "`line` must be greater than 0 (lines start at line 1)";
151
+ var COL_GTR_EQ_ZERO = "`column` must be greater than or equal to 0 (columns start at column 0)";
142
152
  function cast(map) {
143
153
  return map;
144
154
  }
@@ -175,7 +185,8 @@ const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
175
185
  function normalizeWindowsPath(input = "") {
176
186
  return input && input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
177
187
  }
178
- const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/, _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
188
+ const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
189
+ const _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
179
190
  function cwd() {
180
191
  return typeof process < "u" && typeof process.cwd == "function" ? process.cwd().replace(/\\/g, "/") : "/";
181
192
  }
@@ -195,20 +206,22 @@ function normalizeString(path, allowAboveRoot) {
195
206
  else if (char === "/") break;
196
207
  else char = "/";
197
208
  if (char === "/") {
198
- if (lastSlash !== index - 1 && dots !== 1) if (dots === 2) {
199
- if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
200
- if (res.length > 2) {
201
- let lastSlashIndex = res.lastIndexOf("/");
202
- lastSlashIndex === -1 ? (res = "", lastSegmentLength = 0) : (res = res.slice(0, lastSlashIndex), lastSegmentLength = res.length - 1 - res.lastIndexOf("/")), lastSlash = index, dots = 0;
203
- continue;
204
- }
205
- if (res.length > 0) {
206
- res = "", lastSegmentLength = 0, lastSlash = index, dots = 0;
207
- continue;
209
+ if (lastSlash !== index - 1 && dots !== 1) {
210
+ if (dots === 2) {
211
+ if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
212
+ if (res.length > 2) {
213
+ let lastSlashIndex = res.lastIndexOf("/");
214
+ lastSlashIndex === -1 ? (res = "", lastSegmentLength = 0) : (res = res.slice(0, lastSlashIndex), lastSegmentLength = res.length - 1 - res.lastIndexOf("/")), lastSlash = index, dots = 0;
215
+ continue;
216
+ }
217
+ if (res.length > 0) {
218
+ res = "", lastSegmentLength = 0, lastSlash = index, dots = 0;
219
+ continue;
220
+ }
208
221
  }
209
- }
210
- allowAboveRoot && (res += res.length > 0 ? "/.." : "..", lastSegmentLength = 2);
211
- } else res.length > 0 ? res += `/${path.slice(lastSlash + 1, index)}` : res = path.slice(lastSlash + 1, index), lastSegmentLength = index - lastSlash - 1;
222
+ allowAboveRoot && (res += res.length > 0 ? "/.." : "..", lastSegmentLength = 2);
223
+ } else res.length > 0 ? res += `/${path.slice(lastSlash + 1, index)}` : res = path.slice(lastSlash + 1, index), lastSegmentLength = index - lastSlash - 1;
224
+ }
212
225
  lastSlash = index, dots = 0;
213
226
  } else char === "." && dots !== -1 ? ++dots : dots = -1;
214
227
  }
@@ -216,17 +229,28 @@ function normalizeString(path, allowAboveRoot) {
216
229
  }
217
230
  const isAbsolute = function(p) {
218
231
  return _IS_ABSOLUTE_RE.test(p);
219
- }, dirname = function(p) {
232
+ };
233
+ const dirname = function(p) {
220
234
  let segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
221
235
  return segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0]) && (segments[0] += "/"), segments.join("/") || (isAbsolute(p) ? "/" : ".");
222
- }, textDecoder = new TextDecoder(), decodeBase64 = (() => {
236
+ };
237
+ const textDecoder = new TextDecoder();
238
+ const decodeBase64 = (() => {
223
239
  let capturedBuffer = typeof Buffer == "function" ? Buffer : void 0;
224
240
  return capturedBuffer && typeof capturedBuffer.from == "function" ? (base64) => capturedBuffer.from(base64, "base64").toString("utf-8") : (base64) => textDecoder.decode(Uint8Array.from(atob(base64), (c) => c.charCodeAt(0)));
225
- })(), percentRegEx = /%/g, backslashRegEx = /\\/g, newlineRegEx = /\n/g, carriageReturnRegEx = /\r/g, tabRegEx = /\t/g, questionRegex = /\?/g, hashRegex = /#/g;
241
+ })();
242
+ const percentRegEx = /%/g;
243
+ const backslashRegEx = /\\/g;
244
+ const newlineRegEx = /\n/g;
245
+ const carriageReturnRegEx = /\r/g;
246
+ const tabRegEx = /\t/g;
247
+ const questionRegex = /\?/g;
248
+ const hashRegex = /#/g;
226
249
  function encodePathChars(filepath) {
227
250
  return filepath.includes("%") && (filepath = filepath.replace(percentRegEx, "%25")), !isWindows && filepath.includes("\\") && (filepath = filepath.replace(backslashRegEx, "%5C")), filepath.includes("\n") && (filepath = filepath.replace(newlineRegEx, "%0A")), filepath.includes("\r") && (filepath = filepath.replace(carriageReturnRegEx, "%0D")), filepath.includes(" ") && (filepath = filepath.replace(tabRegEx, "%09")), filepath;
228
251
  }
229
- const posixDirname = dirname, posixResolve = resolve;
252
+ const posixDirname = dirname;
253
+ const posixResolve = resolve;
230
254
  function posixPathToFileHref(posixPath) {
231
255
  let resolved = posixResolve(posixPath), filePathLast = posixPath.charCodeAt(posixPath.length - 1);
232
256
  return (filePathLast === 47 || isWindows && filePathLast === 92) && resolved.at(-1) !== "/" && (resolved += "/"), resolved = encodePathChars(resolved), resolved.includes("?") && (resolved = resolved.replace(questionRegex, "%3F")), resolved.includes("#") && (resolved = resolved.replace(hashRegex, "%23")), new URL(`file://${resolved}`).href;
@@ -278,7 +302,8 @@ var EvaluatedModuleNode = class {
278
302
  constructor(id, url) {
279
303
  this.id = id, this.url = url, this.file = cleanUrl(id);
280
304
  }
281
- }, EvaluatedModules = class {
305
+ };
306
+ var EvaluatedModules = class {
282
307
  idToModuleMap = /* @__PURE__ */ new Map();
283
308
  fileToModulesMap = /* @__PURE__ */ new Map();
284
309
  urlToIdModuleMap = /* @__PURE__ */ new Map();
@@ -318,8 +343,8 @@ var EvaluatedModuleNode = class {
318
343
  */
319
344
  ensureModule(id, url) {
320
345
  if (id = normalizeModuleId(id), this.idToModuleMap.has(id)) {
321
- let moduleNode$1 = this.idToModuleMap.get(id);
322
- return this.urlToIdModuleMap.set(url, moduleNode$1), moduleNode$1;
346
+ let moduleNode = this.idToModuleMap.get(id);
347
+ return this.urlToIdModuleMap.set(url, moduleNode), moduleNode;
323
348
  }
324
349
  let moduleNode = new EvaluatedModuleNode(id, url);
325
350
  this.idToModuleMap.set(id, moduleNode), this.urlToIdModuleMap.set(url, moduleNode);
@@ -445,7 +470,8 @@ var HMRContext = class {
445
470
  exports
446
471
  }), this.hmrClient.hotModulesMap.set(this.ownerPath, mod);
447
472
  }
448
- }, HMRClient = class {
473
+ };
474
+ var HMRClient = class {
449
475
  logger;
450
476
  transport;
451
477
  importUpdatedModule;
@@ -592,11 +618,11 @@ const createInvokeableTransport = (transport) => {
592
618
  id: `send:${promiseId}`,
593
619
  data
594
620
  }
595
- }, sendPromise = transport.send(wrappedData), { promise, resolve: resolve$1, reject } = promiseWithResolvers(), timeout = transport.timeout ?? 6e4, timeoutId;
621
+ }, sendPromise = transport.send(wrappedData), { promise, resolve, reject } = promiseWithResolvers(), timeout = transport.timeout ?? 6e4, timeoutId;
596
622
  timeout > 0 && (timeoutId = setTimeout(() => {
597
623
  rpcPromises.delete(promiseId), reject(/* @__PURE__ */ Error(`transport invoke timed out after ${timeout}ms (data: ${JSON.stringify(wrappedData)})`));
598
624
  }, timeout), timeoutId?.unref?.()), rpcPromises.set(promiseId, {
599
- resolve: resolve$1,
625
+ resolve,
600
626
  reject,
601
627
  name,
602
628
  timeoutId
@@ -610,7 +636,8 @@ const createInvokeableTransport = (transport) => {
610
636
  }
611
637
  }
612
638
  };
613
- }, normalizeModuleRunnerTransport = (transport) => {
639
+ };
640
+ const normalizeModuleRunnerTransport = (transport) => {
614
641
  let invokeableTransport = createInvokeableTransport(transport), isConnected = !invokeableTransport.connect, connectingPromise;
615
642
  return {
616
643
  ...transport,
@@ -633,14 +660,18 @@ const createInvokeableTransport = (transport) => {
633
660
  } } : {},
634
661
  async send(data) {
635
662
  if (invokeableTransport.send) {
636
- if (!isConnected) if (connectingPromise) await connectingPromise;
637
- else throw new SendBeforeConnectError("send was called before connect");
663
+ if (!isConnected) {
664
+ if (connectingPromise) await connectingPromise;
665
+ else throw new SendBeforeConnectError("send was called before connect");
666
+ }
638
667
  await invokeableTransport.send(data);
639
668
  }
640
669
  },
641
670
  async invoke(name, data) {
642
- if (!isConnected) if (connectingPromise) await connectingPromise;
643
- else throw new SendBeforeConnectError("invoke was called before connect");
671
+ if (!isConnected) {
672
+ if (connectingPromise) await connectingPromise;
673
+ else throw new SendBeforeConnectError("invoke was called before connect");
674
+ }
644
675
  return invokeableTransport.invoke(name, data);
645
676
  }
646
677
  };
@@ -659,9 +690,9 @@ const createWebSocketModuleRunnerTransport = (options) => {
659
690
  onMessage(JSON.parse(data));
660
691
  });
661
692
  let isOpened = socket.readyState === socket.OPEN;
662
- isOpened || await new Promise((resolve$1, reject) => {
693
+ isOpened || await new Promise((resolve, reject) => {
663
694
  socket.addEventListener("open", () => {
664
- isOpened = !0, resolve$1();
695
+ isOpened = !0, resolve();
665
696
  }, { once: !0 }), socket.addEventListener("close", () => {
666
697
  if (!isOpened) {
667
698
  reject(/* @__PURE__ */ Error("WebSocket closed without opened."));
@@ -709,7 +740,14 @@ const {${missingBindings.join(", ")}} = pkg;
709
740
  }
710
741
  }
711
742
  }
712
- const ssrModuleExportsKey = "__vite_ssr_exports__", ssrImportKey = "__vite_ssr_import__", ssrDynamicImportKey = "__vite_ssr_dynamic_import__", ssrExportAllKey = "__vite_ssr_exportAll__", ssrExportNameKey = "__vite_ssr_exportName__", ssrImportMetaKey = "__vite_ssr_import_meta__", customizationHookNamespace = "vite-module-runner:import-meta-resolve/v1/", customizationHooksModule = `
743
+ const ssrModuleExportsKey = "__vite_ssr_exports__";
744
+ const ssrImportKey = "__vite_ssr_import__";
745
+ const ssrDynamicImportKey = "__vite_ssr_dynamic_import__";
746
+ const ssrExportAllKey = "__vite_ssr_exportAll__";
747
+ const ssrExportNameKey = "__vite_ssr_exportName__";
748
+ const ssrImportMetaKey = "__vite_ssr_import_meta__";
749
+ const customizationHookNamespace = "vite-module-runner:import-meta-resolve/v1/";
750
+ const customizationHooksModule = `
713
751
 
714
752
  export async function resolve(specifier, context, nextResolve) {
715
753
  if (specifier.startsWith(${JSON.stringify(customizationHookNamespace)})) {
@@ -759,10 +797,10 @@ const envProxy = new Proxy({}, { get(_, p) {
759
797
  throw Error(`[module runner] Dynamic access of "import.meta.env" is not supported. Please, use "import.meta.env.${String(p)}" instead.`);
760
798
  } });
761
799
  function createDefaultImportMeta(modulePath) {
762
- let href = posixPathToFileHref(modulePath), filename = modulePath, dirname$1 = posixDirname(modulePath);
800
+ let href = posixPathToFileHref(modulePath), filename = modulePath, dirname = posixDirname(modulePath);
763
801
  return {
764
802
  filename: isWindows ? toWindowsPath(filename) : filename,
765
- dirname: isWindows ? toWindowsPath(dirname$1) : dirname$1,
803
+ dirname: isWindows ? toWindowsPath(dirname) : dirname,
766
804
  url: href,
767
805
  env: envProxy,
768
806
  resolve(_id, _parent) {
@@ -803,10 +841,10 @@ var Queue = class {
803
841
  queue = [];
804
842
  pending = !1;
805
843
  enqueue(promise) {
806
- return new Promise((resolve$1, reject) => {
844
+ return new Promise((resolve, reject) => {
807
845
  this.queue.push({
808
846
  promise,
809
- resolve: resolve$1,
847
+ resolve,
810
848
  reject
811
849
  }), this.dequeue();
812
850
  });
@@ -888,19 +926,29 @@ function findAllEntrypoints(runner, entrypoints = /* @__PURE__ */ new Set()) {
888
926
  for (let mod of runner.evaluatedModules.idToModuleMap.values()) mod.importers.size || entrypoints.add(mod.url);
889
927
  return entrypoints;
890
928
  }
891
- const noop = () => {}, silentConsole = {
929
+ const noop = () => {};
930
+ const silentConsole = {
892
931
  debug: noop,
893
932
  error: noop
894
- }, hmrLogger = {
933
+ };
934
+ const hmrLogger = {
895
935
  debug: (...msg) => console.log("[vite]", ...msg),
896
936
  error: (error) => console.log("[vite]", error)
897
- }, sourceMapCache = {}, fileContentsCache = {}, evaluatedModulesCache = /* @__PURE__ */ new Set(), retrieveFileHandlers = /* @__PURE__ */ new Set(), retrieveSourceMapHandlers = /* @__PURE__ */ new Set(), createExecHandlers = (handlers) => ((...args) => {
937
+ };
938
+ const sourceMapCache = {};
939
+ const fileContentsCache = {};
940
+ const evaluatedModulesCache = /* @__PURE__ */ new Set();
941
+ const retrieveFileHandlers = /* @__PURE__ */ new Set();
942
+ const retrieveSourceMapHandlers = /* @__PURE__ */ new Set();
943
+ const createExecHandlers = (handlers) => ((...args) => {
898
944
  for (let handler of handlers) {
899
945
  let result = handler(...args);
900
946
  if (result) return result;
901
947
  }
902
948
  return null;
903
- }), retrieveFileFromHandlers = createExecHandlers(retrieveFileHandlers), retrieveSourceMapFromHandlers = createExecHandlers(retrieveSourceMapHandlers);
949
+ });
950
+ const retrieveFileFromHandlers = createExecHandlers(retrieveFileHandlers);
951
+ const retrieveSourceMapFromHandlers = createExecHandlers(retrieveSourceMapHandlers);
904
952
  let overridden = !1;
905
953
  const originalPrepare = Error.prepareStackTrace;
906
954
  function resetInterceptor(runner, options) {
@@ -945,8 +993,10 @@ function retrieveSourceMap(source) {
945
993
  let sourceMappingURL = retrieveSourceMapURL(source);
946
994
  if (!sourceMappingURL) return null;
947
995
  let sourceMapData;
948
- if (reSourceMap.test(sourceMappingURL)) sourceMapData = decodeBase64(sourceMappingURL.slice(sourceMappingURL.indexOf(",") + 1)), sourceMappingURL = source;
949
- else sourceMappingURL = supportRelativeURL(source, sourceMappingURL), sourceMapData = retrieveFile(sourceMappingURL);
996
+ if (reSourceMap.test(sourceMappingURL)) {
997
+ let rawData = sourceMappingURL.slice(sourceMappingURL.indexOf(",") + 1);
998
+ sourceMapData = decodeBase64(rawData), sourceMappingURL = source;
999
+ } else sourceMappingURL = supportRelativeURL(source, sourceMappingURL), sourceMapData = retrieveFile(sourceMappingURL);
950
1000
  return sourceMapData ? {
951
1001
  url: sourceMappingURL,
952
1002
  map: sourceMapData
@@ -1091,8 +1141,8 @@ var ModuleRunner = class {
1091
1141
  closed = !1;
1092
1142
  constructor(options, evaluator = new ESModulesEvaluator(), debug) {
1093
1143
  if (this.options = options, this.evaluator = evaluator, this.debug = debug, this.evaluatedModules = options.evaluatedModules ?? new EvaluatedModules(), this.transport = normalizeModuleRunnerTransport(options.transport), options.hmr !== !1) {
1094
- let optionsHmr = options.hmr ?? !0;
1095
- if (this.hmrClient = new HMRClient(optionsHmr === !0 || optionsHmr.logger === void 0 ? hmrLogger : optionsHmr.logger === !1 ? silentConsole : optionsHmr.logger, this.transport, ({ acceptedPath }) => this.import(acceptedPath)), !this.transport.connect) throw Error("HMR is not supported by this runner transport, but `hmr` option was set to true");
1144
+ let optionsHmr = options.hmr ?? !0, resolvedHmrLogger = optionsHmr === !0 || optionsHmr.logger === void 0 ? hmrLogger : optionsHmr.logger === !1 ? silentConsole : optionsHmr.logger;
1145
+ if (this.hmrClient = new HMRClient(resolvedHmrLogger, this.transport, ({ acceptedPath }) => this.import(acceptedPath)), !this.transport.connect) throw Error("HMR is not supported by this runner transport, but `hmr` option was set to true");
1096
1146
  this.transport.connect(createHMRHandlerForRunner(this));
1097
1147
  } else this.transport.connect?.();
1098
1148
  options.sourcemapInterceptor !== !1 && (this.resetSourceMapSupport = enableSourceMapSupport(this));
@@ -1203,8 +1253,8 @@ var ModuleRunner = class {
1203
1253
  if ("externalize" in fetchResult) {
1204
1254
  let { externalize } = fetchResult;
1205
1255
  this.debug?.("[module runner] externalizing", externalize);
1206
- let exports$1 = await this.evaluator.runExternalModule(externalize);
1207
- return mod.exports = exports$1, exports$1;
1256
+ let exports = await this.evaluator.runExternalModule(externalize);
1257
+ return mod.exports = exports, exports;
1208
1258
  }
1209
1259
  let { code, file } = fetchResult;
1210
1260
  if (code == null) {
@@ -1254,6 +1304,5 @@ function exportAll(exports, sourceModule) {
1254
1304
  } catch {}
1255
1305
  }
1256
1306
  }
1257
-
1258
1307
  //#endregion
1259
- export { ESModulesEvaluator, EvaluatedModules, ModuleRunner, createDefaultImportMeta, createNodeImportMeta, createWebSocketModuleRunnerTransport, normalizeModuleId, ssrDynamicImportKey, ssrExportAllKey, ssrExportNameKey, ssrImportKey, ssrImportMetaKey, ssrModuleExportsKey };
1308
+ export { ESModulesEvaluator, EvaluatedModules, ModuleRunner, createDefaultImportMeta, createNodeImportMeta, createWebSocketModuleRunnerTransport, normalizeModuleId, ssrDynamicImportKey, ssrExportAllKey, ssrExportNameKey, ssrImportKey, ssrImportMetaKey, ssrModuleExportsKey };
@@ -1,5 +1,4 @@
1
1
  import { WorkerEntrypoint } from "cloudflare:workers";
2
-
3
2
  //#region src/workers/vite-proxy-worker/index.ts
4
3
  var ViteProxyWorker = class extends WorkerEntrypoint {
5
4
  constructor(ctx, env) {
@@ -26,6 +25,5 @@ function tailEventsReviver(_, value) {
26
25
  if (value && typeof value === "object" && serializedDate in value && typeof value[serializedDate] === "string") return new Date(value[serializedDate]);
27
26
  return value;
28
27
  }
29
-
30
28
  //#endregion
31
- export { ViteProxyWorker as default };
29
+ export { ViteProxyWorker as default };