rsbuild-plugin-cloudflare 0.0.6 → 0.0.8

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.
@@ -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,7 +1304,7 @@ function exportAll(exports, sourceModule) {
1254
1304
  } catch {}
1255
1305
  }
1256
1306
  }
1257
-
1258
1307
  //#endregion
1259
1308
  export { ESModulesEvaluator, EvaluatedModules, ModuleRunner, createDefaultImportMeta, createNodeImportMeta, createWebSocketModuleRunnerTransport, normalizeModuleId, ssrDynamicImportKey, ssrExportAllKey, ssrExportNameKey, ssrImportKey, ssrImportMetaKey, ssrModuleExportsKey };
1309
+
1260
1310
  //# sourceMappingURL=module-runner.js.map