@cloudflare/vite-plugin 1.17.0 → 1.18.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.
@@ -0,0 +1,80 @@
1
+ //#region package.json
2
+ var package_default = {
3
+ name: "@cloudflare/vite-plugin",
4
+ version: "1.18.0",
5
+ description: "Cloudflare plugin for Vite",
6
+ keywords: [
7
+ "cloudflare",
8
+ "workers",
9
+ "cloudflare-workers",
10
+ "vite",
11
+ "vite-plugin"
12
+ ],
13
+ homepage: "https://github.com/cloudflare/workers-sdk/tree/main/packages/vite-plugin-cloudflare#readme",
14
+ bugs: { "url": "https://github.com/cloudflare/workers-sdk/issues" },
15
+ repository: {
16
+ "type": "git",
17
+ "url": "https://github.com/cloudflare/workers-sdk.git",
18
+ "directory": "packages/vite-plugin-cloudflare"
19
+ },
20
+ license: "MIT",
21
+ sideEffects: false,
22
+ type: "module",
23
+ exports: { ".": {
24
+ "types": "./dist/index.d.mts",
25
+ "import": "./dist/index.mjs"
26
+ } },
27
+ main: "./dist/index.mjs",
28
+ types: "./dist/index.d.mts",
29
+ files: ["dist"],
30
+ scripts: {
31
+ "build": "tsdown",
32
+ "check:lint": "eslint . --max-warnings=0",
33
+ "check:type": "tsc --build",
34
+ "dev": "tsdown --watch",
35
+ "test": "vitest run",
36
+ "test:ci": "pnpm test",
37
+ "test:e2e": "vitest run -c e2e/vitest.config.ts",
38
+ "test:watch": "vitest"
39
+ },
40
+ dependencies: {
41
+ "@cloudflare/unenv-preset": "workspace:*",
42
+ "@remix-run/node-fetch-server": "^0.8.0",
43
+ "defu": "^6.1.4",
44
+ "get-port": "^7.1.0",
45
+ "miniflare": "workspace:*",
46
+ "picocolors": "^1.1.1",
47
+ "tinyglobby": "^0.2.12",
48
+ "unenv": "2.0.0-rc.24",
49
+ "wrangler": "workspace:*",
50
+ "ws": "catalog:default"
51
+ },
52
+ devDependencies: {
53
+ "@cloudflare/containers-shared": "workspace:*",
54
+ "@cloudflare/mock-npm-registry": "workspace:*",
55
+ "@cloudflare/workers-shared": "workspace:*",
56
+ "@cloudflare/workers-tsconfig": "workspace:*",
57
+ "@cloudflare/workers-types": "catalog:default",
58
+ "@types/node": "catalog:vite-plugin",
59
+ "@types/semver": "^7.5.1",
60
+ "@types/ws": "^8.5.13",
61
+ "magic-string": "^0.30.12",
62
+ "mlly": "^1.7.4",
63
+ "semver": "^7.7.1",
64
+ "tree-kill": "^1.2.2",
65
+ "tsdown": "0.16.3",
66
+ "typescript": "catalog:default",
67
+ "vite": "catalog:vite-plugin",
68
+ "vitest": "catalog:default"
69
+ },
70
+ peerDependencies: {
71
+ "vite": "^6.1.0 || ^7.0.0",
72
+ "wrangler": "workspace:^"
73
+ },
74
+ publishConfig: { "access": "public" },
75
+ "workers-sdk": { "prerelease": true }
76
+ };
77
+
78
+ //#endregion
79
+ export { package_default as default };
80
+ //# sourceMappingURL=package-BTRs8FGs.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package-BTRs8FGs.mjs","names":[],"sources":["../package.json"],"sourcesContent":["{\n\t\"name\": \"@cloudflare/vite-plugin\",\n\t\"version\": \"1.18.0\",\n\t\"description\": \"Cloudflare plugin for Vite\",\n\t\"keywords\": [\n\t\t\"cloudflare\",\n\t\t\"workers\",\n\t\t\"cloudflare-workers\",\n\t\t\"vite\",\n\t\t\"vite-plugin\"\n\t],\n\t\"homepage\": \"https://github.com/cloudflare/workers-sdk/tree/main/packages/vite-plugin-cloudflare#readme\",\n\t\"bugs\": {\n\t\t\"url\": \"https://github.com/cloudflare/workers-sdk/issues\"\n\t},\n\t\"repository\": {\n\t\t\"type\": \"git\",\n\t\t\"url\": \"https://github.com/cloudflare/workers-sdk.git\",\n\t\t\"directory\": \"packages/vite-plugin-cloudflare\"\n\t},\n\t\"license\": \"MIT\",\n\t\"sideEffects\": false,\n\t\"type\": \"module\",\n\t\"exports\": {\n\t\t\".\": {\n\t\t\t\"types\": \"./dist/index.d.mts\",\n\t\t\t\"import\": \"./dist/index.mjs\"\n\t\t}\n\t},\n\t\"main\": \"./dist/index.mjs\",\n\t\"types\": \"./dist/index.d.mts\",\n\t\"files\": [\n\t\t\"dist\"\n\t],\n\t\"scripts\": {\n\t\t\"build\": \"tsdown\",\n\t\t\"check:lint\": \"eslint . --max-warnings=0\",\n\t\t\"check:type\": \"tsc --build\",\n\t\t\"dev\": \"tsdown --watch\",\n\t\t\"test\": \"vitest run\",\n\t\t\"test:ci\": \"pnpm test\",\n\t\t\"test:e2e\": \"vitest run -c e2e/vitest.config.ts\",\n\t\t\"test:watch\": \"vitest\"\n\t},\n\t\"dependencies\": {\n\t\t\"@cloudflare/unenv-preset\": \"workspace:*\",\n\t\t\"@remix-run/node-fetch-server\": \"^0.8.0\",\n\t\t\"defu\": \"^6.1.4\",\n\t\t\"get-port\": \"^7.1.0\",\n\t\t\"miniflare\": \"workspace:*\",\n\t\t\"picocolors\": \"^1.1.1\",\n\t\t\"tinyglobby\": \"^0.2.12\",\n\t\t\"unenv\": \"2.0.0-rc.24\",\n\t\t\"wrangler\": \"workspace:*\",\n\t\t\"ws\": \"catalog:default\"\n\t},\n\t\"devDependencies\": {\n\t\t\"@cloudflare/containers-shared\": \"workspace:*\",\n\t\t\"@cloudflare/mock-npm-registry\": \"workspace:*\",\n\t\t\"@cloudflare/workers-shared\": \"workspace:*\",\n\t\t\"@cloudflare/workers-tsconfig\": \"workspace:*\",\n\t\t\"@cloudflare/workers-types\": \"catalog:default\",\n\t\t\"@types/node\": \"catalog:vite-plugin\",\n\t\t\"@types/semver\": \"^7.5.1\",\n\t\t\"@types/ws\": \"^8.5.13\",\n\t\t\"magic-string\": \"^0.30.12\",\n\t\t\"mlly\": \"^1.7.4\",\n\t\t\"semver\": \"^7.7.1\",\n\t\t\"tree-kill\": \"^1.2.2\",\n\t\t\"tsdown\": \"0.16.3\",\n\t\t\"typescript\": \"catalog:default\",\n\t\t\"vite\": \"catalog:vite-plugin\",\n\t\t\"vitest\": \"catalog:default\"\n\t},\n\t\"peerDependencies\": {\n\t\t\"vite\": \"^6.1.0 || ^7.0.0\",\n\t\t\"wrangler\": \"workspace:^\"\n\t},\n\t\"publishConfig\": {\n\t\t\"access\": \"public\"\n\t},\n\t\"workers-sdk\": {\n\t\t\"prerelease\": true\n\t}\n}\n"],"mappings":";sBAAA;OACS;UACG;cACI;WACH;EACX;EACA;EACA;EACA;EACA;EACA;WACW;OACJ,EACP,OAAO,oDACP;aACa;EACb,QAAQ;EACR,OAAO;EACP,aAAa;EACb;UACU;cACI;OACP;UACG,EACV,KAAK;EACJ,SAAS;EACT,UAAU;EACV,EACD;OACO;QACC;QACA,CACR,OACA;UACU;EACV,SAAS;EACT,cAAc;EACd,cAAc;EACd,OAAO;EACP,QAAQ;EACR,WAAW;EACX,YAAY;EACZ,cAAc;EACd;eACe;EACf,4BAA4B;EAC5B,gCAAgC;EAChC,QAAQ;EACR,YAAY;EACZ,aAAa;EACb,cAAc;EACd,cAAc;EACd,SAAS;EACT,YAAY;EACZ,MAAM;EACN;kBACkB;EAClB,iCAAiC;EACjC,iCAAiC;EACjC,8BAA8B;EAC9B,gCAAgC;EAChC,6BAA6B;EAC7B,eAAe;EACf,iBAAiB;EACjB,aAAa;EACb,gBAAgB;EAChB,QAAQ;EACR,UAAU;EACV,aAAa;EACb,UAAU;EACV,cAAc;EACd,QAAQ;EACR,UAAU;EACV;mBACmB;EACnB,QAAQ;EACR,YAAY;EACZ;gBACgB,EAChB,UAAU,UACV;CACD,eAAe,EACd,cAAc,MACd;CACD"}
@@ -80,19 +80,12 @@ const DURABLE_OBJECT_KEYS = [
80
80
  const WORKFLOW_ENTRYPOINT_KEYS = ["run"];
81
81
 
82
82
  //#endregion
83
- //#region ../../node_modules/.pnpm/vite@7.0.0_@types+node@20.19.9_jiti@2.6.0_lightningcss@1.30.2_yaml@2.8.1/node_modules/vite/dist/node/module-runner.js
84
- /**
85
- * Prefix for resolved Ids that are not valid browser import specifiers
86
- */
87
- const VALID_ID_PREFIX = "/@id/", NULL_BYTE_PLACEHOLDER = "__x00__";
83
+ //#region ../../node_modules/.pnpm/vite@7.1.12_@types+node@20.19.9_jiti@2.6.0_lightningcss@1.30.2_yaml@2.8.1/node_modules/vite/dist/node/module-runner.js
88
84
  let SOURCEMAPPING_URL = "sourceMa";
89
85
  SOURCEMAPPING_URL += "ppingURL";
90
- const ERR_OUTDATED_OPTIMIZED_DEP = "ERR_OUTDATED_OPTIMIZED_DEP", isWindows = typeof process < "u" && process.platform === "win32";
91
- /**
92
- * Undo {@link wrapId}'s `/@id/` and null byte replacements.
93
- */
86
+ const isWindows = typeof process < "u" && process.platform === "win32";
94
87
  function unwrapId(id) {
95
- return id.startsWith(VALID_ID_PREFIX) ? id.slice(5).replace(NULL_BYTE_PLACEHOLDER, "\0") : id;
88
+ return id.startsWith("/@id/") ? id.slice(5).replace("__x00__", "\0") : id;
96
89
  }
97
90
  const windowsSlashRE = /\\/g;
98
91
  function slash(p) {
@@ -171,20 +164,20 @@ const isAbsolute = function(p) {
171
164
  }, dirname = function(p) {
172
165
  let segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
173
166
  return segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0]) && (segments[0] += "/"), segments.join("/") || (isAbsolute(p) ? "/" : ".");
174
- }, decodeBase64 = typeof atob < "u" ? atob : (str) => Buffer.from(str, "base64").toString("utf-8"), CHAR_FORWARD_SLASH = 47, CHAR_BACKWARD_SLASH = 92, percentRegEx = /%/g, backslashRegEx = /\\/g, newlineRegEx = /\n/g, carriageReturnRegEx = /\r/g, tabRegEx = /\t/g, questionRegex = /\?/g, hashRegex = /#/g;
167
+ }, 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;
175
168
  function encodePathChars(filepath) {
176
169
  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;
177
170
  }
178
171
  const posixDirname = dirname, posixResolve = resolve;
179
172
  function posixPathToFileHref(posixPath) {
180
173
  let resolved = posixResolve(posixPath), filePathLast = posixPath.charCodeAt(posixPath.length - 1);
181
- return (filePathLast === CHAR_FORWARD_SLASH || isWindows && filePathLast === CHAR_BACKWARD_SLASH) && 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;
174
+ 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;
182
175
  }
183
176
  function toWindowsPath(path) {
184
177
  return path.replace(/\//g, "\\");
185
178
  }
186
- const comma = 44, chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", intToChar = new Uint8Array(64), charToInt = new Uint8Array(128);
187
- for (let i = 0; i < 64; i++) {
179
+ var comma = 44, chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", intToChar = new Uint8Array(64), charToInt = new Uint8Array(128);
180
+ for (let i = 0; i < chars.length; i++) {
188
181
  let c = chars.charCodeAt(i);
189
182
  intToChar[i] = c, charToInt[c] = i;
190
183
  }
@@ -243,24 +236,7 @@ function sort(line) {
243
236
  function sortComparator(a, b) {
244
237
  return a[0] - b[0];
245
238
  }
246
- const COLUMN = 0, SOURCES_INDEX = 1, SOURCE_LINE = 2, SOURCE_COLUMN = 3, NAMES_INDEX = 4;
247
- let found = !1;
248
- /**
249
- * A binary search implementation that returns the index if a match is found.
250
- * If no match is found, then the left-index (the index associated with the item that comes just
251
- * before the desired index) is returned. To maintain proper sort order, a splice would happen at
252
- * the next index:
253
- *
254
- * ```js
255
- * const array = [1, 3];
256
- * const needle = 2;
257
- * const index = binarySearch(array, needle, (item, needle) => item - needle);
258
- *
259
- * assert.equal(index, 0);
260
- * array.splice(index + 1, 0, needle);
261
- * assert.deepEqual(array, [1, 2, 3]);
262
- * ```
263
- */
239
+ var COLUMN = 0, SOURCES_INDEX = 1, SOURCE_LINE = 2, SOURCE_COLUMN = 3, NAMES_INDEX = 4, found = !1;
264
240
  function binarySearch(haystack, needle, low, high) {
265
241
  for (; low <= high;) {
266
242
  let mid = low + (high - low >> 1), cmp = haystack[mid][COLUMN] - needle;
@@ -277,10 +253,6 @@ function lowerBound(haystack, needle, index) {
277
253
  for (let i = index - 1; i >= 0 && haystack[i][COLUMN] === needle; index = i--);
278
254
  return index;
279
255
  }
280
- /**
281
- * This overly complicated beast is just to record the last tested line/column and the resulting
282
- * index, allowing us to skip a few tests if mappings are monotonically increasing.
283
- */
284
256
  function memoizedBinarySearch(haystack, needle, state, key) {
285
257
  let { lastKey, lastNeedle, lastIndex } = state, low = 0, high = haystack.length - 1;
286
258
  if (key === lastKey) {
@@ -289,26 +261,14 @@ function memoizedBinarySearch(haystack, needle, state, key) {
289
261
  }
290
262
  return state.lastKey = key, state.lastNeedle = needle, state.lastIndex = binarySearch(haystack, needle, low, high);
291
263
  }
292
- const 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;
293
- /**
294
- * Typescript doesn't allow friend access to private fields, so this just casts the map into a type
295
- * with public access modifiers.
296
- */
264
+ 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;
297
265
  function cast(map) {
298
266
  return map;
299
267
  }
300
- /**
301
- * Returns the decoded (array of lines of segments) form of the SourceMap's mappings field.
302
- */
303
268
  function decodedMappings(map) {
304
269
  var _a;
305
270
  return (_a = cast(map))._decoded || (_a._decoded = decode(cast(map)._encoded));
306
271
  }
307
- /**
308
- * A higher-level API to find the source/line/column associated with a generated line/column
309
- * (think, from a stack trace). Line is 1-based, but column is 0-based, due to legacy behavior in
310
- * `source-map` library.
311
- */
312
272
  function originalPositionFor(map, needle) {
313
273
  let { line, column, bias } = needle;
314
274
  if (line--, line < 0) throw Error(LINE_GTR_ZERO);
@@ -376,40 +336,15 @@ var EvaluatedModuleNode = class {
376
336
  idToModuleMap = /* @__PURE__ */ new Map();
377
337
  fileToModulesMap = /* @__PURE__ */ new Map();
378
338
  urlToIdModuleMap = /* @__PURE__ */ new Map();
379
- /**
380
- * Returns the module node by the resolved module ID. Usually, module ID is
381
- * the file system path with query and/or hash. It can also be a virtual module.
382
- *
383
- * Module runner graph will have 1 to 1 mapping with the server module graph.
384
- * @param id Resolved module ID
385
- */
386
339
  getModuleById(id) {
387
340
  return this.idToModuleMap.get(id);
388
341
  }
389
- /**
390
- * Returns all modules related to the file system path. Different modules
391
- * might have different query parameters or hash, so it's possible to have
392
- * multiple modules for the same file.
393
- * @param file The file system path of the module
394
- */
395
342
  getModulesByFile(file) {
396
343
  return this.fileToModulesMap.get(file);
397
344
  }
398
- /**
399
- * Returns the module node by the URL that was used in the import statement.
400
- * Unlike module graph on the server, the URL is not resolved and is used as is.
401
- * @param url Server URL that was used in the import statement
402
- */
403
345
  getModuleByUrl(url) {
404
346
  return this.urlToIdModuleMap.get(unwrapId(url));
405
347
  }
406
- /**
407
- * Ensure that module is in the graph. If the module is already in the graph,
408
- * it will return the existing module node. Otherwise, it will create a new
409
- * module node and add it to the graph.
410
- * @param id Resolved module ID
411
- * @param url URL that was used in the import statement
412
- */
413
348
  ensureModule(id, url) {
414
349
  if (id = normalizeModuleId(id), this.idToModuleMap.has(id)) {
415
350
  let moduleNode$1 = this.idToModuleMap.get(id);
@@ -423,17 +358,14 @@ var EvaluatedModuleNode = class {
423
358
  invalidateModule(node) {
424
359
  node.evaluated = !1, node.meta = void 0, node.map = void 0, node.promise = void 0, node.exports = void 0, node.imports.clear();
425
360
  }
426
- /**
427
- * Extracts the inlined source map from the module code and returns the decoded
428
- * source map. If the source map is not inlined, it will return null.
429
- * @param id Resolved module ID
430
- */
431
361
  getModuleSourceMapById(id) {
432
362
  let mod = this.getModuleById(id);
433
363
  if (!mod) return null;
434
364
  if (mod.map) return mod.map;
435
365
  if (!mod.meta || !("code" in mod.meta)) return null;
436
- let mapString = MODULE_RUNNER_SOURCEMAPPING_REGEXP.exec(mod.meta.code)?.[1];
366
+ let pattern = `//# ${SOURCEMAPPING_URL}=data:application/json;base64,`, lastIndex = mod.meta.code.lastIndexOf(pattern);
367
+ if (lastIndex === -1) return null;
368
+ let mapString = MODULE_RUNNER_SOURCEMAPPING_REGEXP.exec(mod.meta.code.slice(lastIndex))?.[1];
437
369
  return mapString ? (mod.map = new DecodedMap(JSON.parse(decodeBase64(mapString)), mod.file), mod.map) : null;
438
370
  }
439
371
  clear() {
@@ -447,8 +379,7 @@ const prefixedBuiltins = new Set([
447
379
  "node:test/reporters"
448
380
  ]);
449
381
  function normalizeModuleId(file) {
450
- if (prefixedBuiltins.has(file)) return file;
451
- return slash(file).replace(/^\/@fs\//, isWindows ? "" : "/").replace(/^node:/, "").replace(/^\/+/, "/").replace(/^file:\//, "/");
382
+ return prefixedBuiltins.has(file) ? file : slash(file).replace(/^\/@fs\//, isWindows ? "" : "/").replace(/^node:/, "").replace(/^\/+/, "/").replace(/^file:\/+/, isWindows ? "" : "/");
452
383
  }
453
384
  var HMRContext = class {
454
385
  newListeners;
@@ -558,21 +489,16 @@ var HMRContext = class {
558
489
  await Promise.all(paths.map((path) => {
559
490
  let disposer = this.disposeMap.get(path);
560
491
  if (disposer) return disposer(this.dataMap.get(path));
561
- })), paths.forEach((path) => {
492
+ })), await Promise.all(paths.map((path) => {
562
493
  let fn = this.pruneMap.get(path);
563
- fn && fn(this.dataMap.get(path));
564
- });
494
+ if (fn) return fn(this.dataMap.get(path));
495
+ }));
565
496
  }
566
497
  warnFailedUpdate(err, path) {
567
498
  (!(err instanceof Error) || !err.message.includes("fetch")) && this.logger.error(err), this.logger.error(`Failed to reload ${path}. This could be due to syntax errors or importing non-existent modules. (see errors above)`);
568
499
  }
569
500
  updateQueue = [];
570
501
  pendingUpdateQueue = !1;
571
- /**
572
- * buffer multiple hot updates triggered by the same src change
573
- * so that they are invoked in the same order they were sent.
574
- * (otherwise the order may be inconsistent because of the http request round trip)
575
- */
576
502
  async queueUpdate(payload) {
577
503
  if (this.updateQueue.push(this.fetchUpdate(payload)), !this.pendingUpdateQueue) {
578
504
  this.pendingUpdateQueue = !0, await Promise.resolve(), this.pendingUpdateQueue = !1;
@@ -605,11 +531,6 @@ var HMRContext = class {
605
531
  };
606
532
  }
607
533
  };
608
- /**
609
- * Vite converts `import { } from 'foo'` to `const _ = __vite_ssr_import__('foo')`.
610
- * Top-level imports and dynamic imports work slightly differently in Node.js.
611
- * This function normalizes the differences so it matches prod behaviour.
612
- */
613
534
  function analyzeImportedModDifference(mod, rawId, moduleType, metadata) {
614
535
  if (!metadata?.isDynamicImport && metadata?.importedNames?.length) {
615
536
  let missingBindings = metadata.importedNames.filter((s) => !(s in mod));
@@ -625,9 +546,9 @@ const {${missingBindings.join(", ")}} = pkg;
625
546
  }
626
547
  }
627
548
  }
628
- let urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict", nanoid = (size = 21) => {
549
+ let nanoid = (size = 21) => {
629
550
  let id = "", i = size | 0;
630
- for (; i--;) id += urlAlphabet[Math.random() * 64 | 0];
551
+ for (; i--;) id += "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict"[Math.random() * 64 | 0];
631
552
  return id;
632
553
  };
633
554
  function reviveInvokeError(e) {
@@ -835,7 +756,7 @@ function createHMRHandlerForRunner(runner) {
835
756
  for (let url of clearEntrypointUrls) try {
836
757
  await runner.import(url);
837
758
  } catch (err) {
838
- err.code !== ERR_OUTDATED_OPTIMIZED_DEP && hmrClient.logger.error(`An error happened during full reload\n${err.message}\n${err.stack}`);
759
+ err.code !== "ERR_OUTDATED_OPTIMIZED_DEP" && hmrClient.logger.error(`An error happened during full reload\n${err.message}\n${err.stack}`);
839
760
  }
840
761
  break;
841
762
  }
@@ -862,12 +783,13 @@ function getModulesEntrypoints(runner, modules, visited = /* @__PURE__ */ new Se
862
783
  if (visited.has(moduleId)) continue;
863
784
  visited.add(moduleId);
864
785
  let module = runner.evaluatedModules.getModuleById(moduleId);
865
- if (!module) continue;
866
- if (!module.importers.size) {
867
- entrypoints.add(module.url);
868
- continue;
786
+ if (module) {
787
+ if (!module.importers.size) {
788
+ entrypoints.add(module.url);
789
+ continue;
790
+ }
791
+ for (let importer of module.importers) getModulesEntrypoints(runner, [importer], visited, entrypoints);
869
792
  }
870
- for (let importer of module.importers) getModulesEntrypoints(runner, [importer], visited, entrypoints);
871
793
  }
872
794
  return entrypoints;
873
795
  }
@@ -875,20 +797,20 @@ function findAllEntrypoints(runner, entrypoints = /* @__PURE__ */ new Set()) {
875
797
  for (let mod of runner.evaluatedModules.idToModuleMap.values()) mod.importers.size || entrypoints.add(mod.url);
876
798
  return entrypoints;
877
799
  }
878
- const sourceMapCache = {}, fileContentsCache = {}, evaluatedModulesCache = /* @__PURE__ */ new Set(), retrieveFileHandlers = /* @__PURE__ */ new Set(), retrieveSourceMapHandlers = /* @__PURE__ */ new Set(), createExecHandlers = (handlers) => (...args) => {
800
+ const sourceMapCache = {}, fileContentsCache = {}, evaluatedModulesCache = /* @__PURE__ */ new Set(), retrieveFileHandlers = /* @__PURE__ */ new Set(), retrieveSourceMapHandlers = /* @__PURE__ */ new Set(), createExecHandlers = (handlers) => ((...args) => {
879
801
  for (let handler of handlers) {
880
802
  let result = handler(...args);
881
803
  if (result) return result;
882
804
  }
883
805
  return null;
884
- }, retrieveFileFromHandlers = createExecHandlers(retrieveFileHandlers), retrieveSourceMapFromHandlers = createExecHandlers(retrieveSourceMapHandlers);
806
+ }), retrieveFileFromHandlers = createExecHandlers(retrieveFileHandlers), retrieveSourceMapFromHandlers = createExecHandlers(retrieveSourceMapHandlers);
885
807
  let overridden = !1;
886
808
  const originalPrepare = Error.prepareStackTrace;
887
809
  function resetInterceptor(runner, options) {
888
810
  evaluatedModulesCache.delete(runner.evaluatedModules), options.retrieveFile && retrieveFileHandlers.delete(options.retrieveFile), options.retrieveSourceMap && retrieveSourceMapHandlers.delete(options.retrieveSourceMap), evaluatedModulesCache.size === 0 && (Error.prepareStackTrace = originalPrepare, overridden = !1);
889
811
  }
890
812
  function interceptStackTrace(runner, options = {}) {
891
- return overridden || (Error.prepareStackTrace = prepareStackTrace, overridden = !0), evaluatedModulesCache.add(runner.evaluatedModules), options.retrieveFile && retrieveFileHandlers.add(options.retrieveFile), options.retrieveSourceMap && retrieveSourceMapHandlers.add(options.retrieveSourceMap), () => resetInterceptor(runner, options);
813
+ return overridden ||= (Error.prepareStackTrace = prepareStackTrace, !0), evaluatedModulesCache.add(runner.evaluatedModules), options.retrieveFile && retrieveFileHandlers.add(options.retrieveFile), options.retrieveSourceMap && retrieveSourceMapHandlers.add(options.retrieveSourceMap), () => resetInterceptor(runner, options);
892
814
  }
893
815
  function supportRelativeURL(file, url) {
894
816
  if (!file) return url;
@@ -990,12 +912,13 @@ function CallSiteToString() {
990
912
  }
991
913
  }
992
914
  let line = "", functionName = this.getFunctionName(), addSuffix = !0, isConstructor = this.isConstructor();
993
- if (!(this.isToplevel() || isConstructor)) {
915
+ if (this.isToplevel() || isConstructor) isConstructor ? line += `new ${functionName || "<anonymous>"}` : functionName ? line += functionName : (line += fileLocation, addSuffix = !1);
916
+ else {
994
917
  let typeName = this.getTypeName();
995
918
  typeName === "[object Object]" && (typeName = "null");
996
919
  let methodName = this.getMethodName();
997
920
  functionName ? (typeName && functionName.indexOf(typeName) !== 0 && (line += `${typeName}.`), line += functionName, methodName && functionName.indexOf(`.${methodName}`) !== functionName.length - methodName.length - 1 && (line += ` [as ${methodName}]`)) : line += `${typeName}.${methodName || "<anonymous>"}`;
998
- } else isConstructor ? line += `new ${functionName || "<anonymous>"}` : functionName ? line += functionName : (line += fileLocation, addSuffix = !1);
921
+ }
999
922
  return addSuffix && (line += ` (${fileLocation})`), line;
1000
923
  }
1001
924
  function cloneCallSite(frame) {
@@ -1014,8 +937,8 @@ function wrapCallSite(frame, state) {
1014
937
  }), frame.isNative()) return state.curPosition = null, frame;
1015
938
  let source = frame.getFileName() || frame.getScriptNameOrSourceURL();
1016
939
  if (source) {
1017
- let line = frame.getLineNumber(), column = frame.getColumnNumber() - 1, headerLength = 62;
1018
- line === 1 && column > headerLength && !frame.isEval() && (column -= headerLength);
940
+ let line = frame.getLineNumber(), column = frame.getColumnNumber() - 1;
941
+ line === 1 && column > 62 && !frame.isEval() && (column -= 62);
1019
942
  let position = mapSourcePosition({
1020
943
  name: null,
1021
944
  source,
@@ -1067,12 +990,42 @@ var ESModulesEvaluator = class {
1067
990
  runExternalModule(filepath) {
1068
991
  return import(filepath);
1069
992
  }
1070
- }, ModuleRunner = class {
993
+ };
994
+ const customizationHookNamespace = "vite-module-runner:import-meta-resolve/v1/", customizationHooksModule = `
995
+
996
+ export async function resolve(specifier, context, nextResolve) {
997
+ if (specifier.startsWith(${JSON.stringify(customizationHookNamespace)})) {
998
+ const data = specifier.slice(${JSON.stringify(customizationHookNamespace)}.length)
999
+ const [parsedSpecifier, parsedImporter] = JSON.parse(data)
1000
+ specifier = parsedSpecifier
1001
+ context.parentURL = parsedImporter
1002
+ }
1003
+
1004
+ return nextResolve(specifier, context)
1005
+ }
1006
+
1007
+ `;
1008
+ const envProxy = new Proxy({}, { get(_, p) {
1009
+ throw Error(`[module runner] Dynamic access of "import.meta.env" is not supported. Please, use "import.meta.env.${String(p)}" instead.`);
1010
+ } });
1011
+ function createDefaultImportMeta(modulePath) {
1012
+ let href = posixPathToFileHref(modulePath), filename = modulePath, dirname$1 = posixDirname(modulePath);
1013
+ return {
1014
+ filename: isWindows ? toWindowsPath(filename) : filename,
1015
+ dirname: isWindows ? toWindowsPath(dirname$1) : dirname$1,
1016
+ url: href,
1017
+ env: envProxy,
1018
+ resolve(_id, _parent) {
1019
+ throw Error("[module runner] \"import.meta.resolve\" is not supported.");
1020
+ },
1021
+ glob() {
1022
+ throw Error("[module runner] \"import.meta.glob\" is statically replaced during file transformation. Make sure to reference it by the full name.");
1023
+ }
1024
+ };
1025
+ }
1026
+ var ModuleRunner = class {
1071
1027
  evaluatedModules;
1072
1028
  hmrClient;
1073
- envProxy = new Proxy({}, { get(_, p) {
1074
- throw Error(`[module runner] Dynamic access of "import.meta.env" is not supported. Please, use "import.meta.env.${String(p)}" instead.`);
1075
- } });
1076
1029
  transport;
1077
1030
  resetSourceMapSupport;
1078
1031
  concurrentModuleNodePromises = /* @__PURE__ */ new Map();
@@ -1085,29 +1038,16 @@ var ESModulesEvaluator = class {
1085
1038
  } else this.transport.connect?.();
1086
1039
  options.sourcemapInterceptor !== !1 && (this.resetSourceMapSupport = enableSourceMapSupport(this));
1087
1040
  }
1088
- /**
1089
- * URL to execute. Accepts file path, server path or id relative to the root.
1090
- */
1091
1041
  async import(url) {
1092
1042
  let fetchedModule = await this.cachedModule(url);
1093
1043
  return await this.cachedRequest(url, fetchedModule);
1094
1044
  }
1095
- /**
1096
- * Clear all caches including HMR listeners.
1097
- */
1098
1045
  clearCache() {
1099
1046
  this.evaluatedModules.clear(), this.hmrClient?.clear();
1100
1047
  }
1101
- /**
1102
- * Clears all caches, removes all HMR listeners, and resets source map support.
1103
- * This method doesn't stop the HMR connection.
1104
- */
1105
1048
  async close() {
1106
1049
  this.resetSourceMapSupport?.(), this.clearCache(), this.hmrClient = void 0, this.closed = !0, await this.transport.disconnect?.();
1107
1050
  }
1108
- /**
1109
- * Returns `true` if the runtime has been closed by calling `close()` method.
1110
- */
1111
1051
  isClosed() {
1112
1052
  return this.closed;
1113
1053
  }
@@ -1134,8 +1074,7 @@ var ESModulesEvaluator = class {
1134
1074
  if (importee && importers.add(importee), (callstack.includes(moduleId) || this.isCircularModule(mod) || this.isCircularImport(importers, moduleId)) && mod.exports) return this.processImport(mod.exports, meta, metadata);
1135
1075
  let debugTimer;
1136
1076
  this.debug && (debugTimer = setTimeout(() => {
1137
- let getStack = () => `stack:\n${[...callstack, moduleId].reverse().map((p) => ` - ${p}`).join("\n")}`;
1138
- this.debug(`[module runner] module ${moduleId} takes over 2s to load.\n${getStack()}`);
1077
+ this.debug(`[module runner] module ${moduleId} takes over 2s to load.\n${(() => `stack:\n${[...callstack, moduleId].reverse().map((p) => ` - ${p}`).join("\n")}`)()}`);
1139
1078
  }, 2e3));
1140
1079
  try {
1141
1080
  if (mod.promise) return this.processImport(await mod.promise, meta, metadata);
@@ -1193,18 +1132,7 @@ var ESModulesEvaluator = class {
1193
1132
  let importer = callstack[callstack.length - 2];
1194
1133
  throw Error(`[module runner] Failed to load "${url}"${importer ? ` imported from ${importer}` : ""}`);
1195
1134
  }
1196
- let modulePath = cleanUrl(file || moduleId), href = posixPathToFileHref(modulePath), filename = modulePath, dirname$1 = posixDirname(modulePath), meta = {
1197
- filename: isWindows ? toWindowsPath(filename) : filename,
1198
- dirname: isWindows ? toWindowsPath(dirname$1) : dirname$1,
1199
- url: href,
1200
- env: this.envProxy,
1201
- resolve(_id, _parent) {
1202
- throw Error("[module runner] \"import.meta.resolve\" is not supported.");
1203
- },
1204
- glob() {
1205
- throw Error("[module runner] \"import.meta.glob\" is statically replaced during file transformation. Make sure to reference it by the full name.");
1206
- }
1207
- }, exports = Object.create(null);
1135
+ let createImportMeta = this.options.createImportMeta ?? createDefaultImportMeta, modulePath = cleanUrl(file || moduleId), href = posixPathToFileHref(modulePath), meta = await createImportMeta(modulePath), exports = Object.create(null);
1208
1136
  Object.defineProperty(exports, Symbol.toStringTag, {
1209
1137
  value: "Module",
1210
1138
  enumerable: !1,
@@ -1252,7 +1180,7 @@ function exportAll(exports, sourceModule) {
1252
1180
  //#region src/workers/runner-worker/module-runner.ts
1253
1181
  /**
1254
1182
  * Custom `ModuleRunner`.
1255
- * The `cachedModule` method is overriden to ensure compatibility with the Workers runtime.
1183
+ * The `cachedModule` method is overridden to ensure compatibility with the Workers runtime.
1256
1184
  */
1257
1185
  var CustomModuleRunner = class extends ModuleRunner {
1258
1186
  #env;
@@ -22,7 +22,7 @@ function tailEventsReplacer(_, value) {
22
22
  return value;
23
23
  }
24
24
  function tailEventsReviver(_, value) {
25
- if (value && typeof value === "object" && serializedDate in value) return new Date(value[serializedDate]);
25
+ if (value && typeof value === "object" && serializedDate in value && typeof value[serializedDate] === "string") return new Date(value[serializedDate]);
26
26
  return value;
27
27
  }
28
28
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudflare/vite-plugin",
3
- "version": "1.17.0",
3
+ "version": "1.18.0",
4
4
  "description": "Cloudflare plugin for Vite",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -41,28 +41,30 @@
41
41
  "unenv": "2.0.0-rc.24",
42
42
  "ws": "8.18.0",
43
43
  "@cloudflare/unenv-preset": "2.7.13",
44
- "wrangler": "4.53.0",
45
- "miniflare": "4.20251202.1"
44
+ "miniflare": "4.20251213.0",
45
+ "wrangler": "4.55.0"
46
46
  },
47
47
  "devDependencies": {
48
- "@cloudflare/workers-types": "^4.20251202.0",
48
+ "@cloudflare/workers-types": "^4.20251213.0",
49
49
  "@types/node": "^22.10.1",
50
+ "@types/semver": "^7.5.1",
50
51
  "@types/ws": "^8.5.13",
51
52
  "magic-string": "^0.30.12",
52
53
  "mlly": "^1.7.4",
54
+ "semver": "^7.7.1",
53
55
  "tree-kill": "^1.2.2",
54
56
  "tsdown": "0.16.3",
55
- "typescript": "^5.8.3",
56
- "vite": "7.0.0",
57
+ "typescript": "~5.8.3",
58
+ "vite": "7.1.12",
57
59
  "vitest": "~3.2.0",
58
- "@cloudflare/containers-shared": "0.4.0",
60
+ "@cloudflare/containers-shared": "0.5.0",
59
61
  "@cloudflare/mock-npm-registry": "0.0.0",
60
62
  "@cloudflare/workers-shared": "0.18.9",
61
63
  "@cloudflare/workers-tsconfig": "0.0.0"
62
64
  },
63
65
  "peerDependencies": {
64
66
  "vite": "^6.1.0 || ^7.0.0",
65
- "wrangler": "^4.53.0"
67
+ "wrangler": "^4.55.0"
66
68
  },
67
69
  "publishConfig": {
68
70
  "access": "public"
@@ -72,6 +74,7 @@
72
74
  },
73
75
  "scripts": {
74
76
  "build": "tsdown",
77
+ "check:lint": "eslint . --max-warnings=0",
75
78
  "check:type": "tsc --build",
76
79
  "dev": "tsdown --watch",
77
80
  "test": "vitest run",