@cloudflare/vite-plugin 1.22.0 → 1.23.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.
package/dist/index.mjs CHANGED
@@ -3,7 +3,7 @@ import assert from "node:assert";
3
3
  import { CoreHeaders, Log, LogLevel, Miniflare, Request as Request$1, Response as Response$1, coupleWebSocket, getDefaultDevRegistryPath, getNodeCompat, getWorkerRegistry, kUnsafeEphemeralUniqueKey } from "miniflare";
4
4
  import * as wrangler from "wrangler";
5
5
  import * as nodePath from "node:path";
6
- import path4, { relative, resolve } from "node:path";
6
+ import path3, { relative, resolve } from "node:path";
7
7
  import * as util$1 from "node:util";
8
8
  import { format, inspect } from "node:util";
9
9
  import * as vite from "vite";
@@ -1776,12 +1776,12 @@ var PluginContext = class {
1776
1776
  return this.#resolvedViteConfig;
1777
1777
  }
1778
1778
  isChildEnvironment(environmentName) {
1779
- if (this.resolvedPluginConfig.type !== "workers") return false;
1779
+ if (this.resolvedPluginConfig.type === "preview") return false;
1780
1780
  for (const childEnvironmentNames of this.resolvedPluginConfig.environmentNameToChildEnvironmentNamesMap.values()) if (childEnvironmentNames.includes(environmentName)) return true;
1781
1781
  return false;
1782
1782
  }
1783
1783
  #getWorker(environmentName) {
1784
- if (this.resolvedPluginConfig.type !== "workers") return;
1784
+ if (this.resolvedPluginConfig.type === "preview") return;
1785
1785
  const worker = this.resolvedPluginConfig.environmentNameToWorkerMap.get(environmentName);
1786
1786
  if (worker) return worker;
1787
1787
  for (const [parentEnvironmentName, childEnvironmentNames] of this.resolvedPluginConfig.environmentNameToChildEnvironmentNamesMap) if (childEnvironmentNames.includes(environmentName)) return this.resolvedPluginConfig.environmentNameToWorkerMap.get(parentEnvironmentName);
@@ -1790,11 +1790,8 @@ var PluginContext = class {
1790
1790
  return this.#getWorker(environmentName)?.config;
1791
1791
  }
1792
1792
  get allWorkerConfigs() {
1793
- switch (this.resolvedPluginConfig.type) {
1794
- case "workers": return Array.from(this.resolvedPluginConfig.environmentNameToWorkerMap.values()).map((worker) => worker.config);
1795
- case "preview": return this.resolvedPluginConfig.workers;
1796
- default: return [];
1797
- }
1793
+ if (this.resolvedPluginConfig.type === "preview") return this.resolvedPluginConfig.workers;
1794
+ return Array.from(this.resolvedPluginConfig.environmentNameToWorkerMap.values()).map((worker) => worker.config);
1798
1795
  }
1799
1796
  get entryWorkerConfig() {
1800
1797
  if (this.resolvedPluginConfig.type !== "workers") return;
@@ -1928,10 +1925,10 @@ var ENVIRONMENT_TAG_PREFIX = "cf:environment=";
1928
1925
  var PATH_TO_DEPLOY_CONFIG = ".wrangler/deploy/config.json";
1929
1926
 
1930
1927
  //#endregion
1931
- //#region ../workers-utils/dist/chunk-4N6XW2IM.mjs
1928
+ //#region ../workers-utils/dist/chunk-4233U5MA.mjs
1932
1929
  function getLocalWorkerdCompatibilityDate({ projectPath = process.cwd() } = {}) {
1933
1930
  try {
1934
- const miniflareEntry = module$1.createRequire(projectPath).resolve("miniflare");
1931
+ const miniflareEntry = module$1.createRequire(path3.join(projectPath, "package.json")).resolve("miniflare");
1935
1932
  const workerdDate = module$1.createRequire(miniflareEntry)("workerd").compatibilityDate;
1936
1933
  return {
1937
1934
  date: toSafeCompatibilityDate(new Date(workerdDate)),
@@ -2226,7 +2223,7 @@ __name(constructWranglerConfig, "constructWranglerConfig");
2226
2223
 
2227
2224
  //#endregion
2228
2225
  //#region ../workers-utils/dist/chunk-AT3LIX2I.mjs
2229
- var UserError$1 = class extends Error {
2226
+ var UserError = class extends Error {
2230
2227
  static {
2231
2228
  __name(this, "UserError");
2232
2229
  }
@@ -2237,7 +2234,7 @@ var UserError$1 = class extends Error {
2237
2234
  this.telemetryMessage = options?.telemetryMessage === true ? message : options?.telemetryMessage;
2238
2235
  }
2239
2236
  };
2240
- var DeprecationError = class extends UserError$1 {
2237
+ var DeprecationError = class extends UserError {
2241
2238
  static {
2242
2239
  __name(this, "DeprecationError");
2243
2240
  }
@@ -2246,7 +2243,7 @@ var DeprecationError = class extends UserError$1 {
2246
2243
  ${message}`, options);
2247
2244
  }
2248
2245
  };
2249
- var FatalError = class extends UserError$1 {
2246
+ var FatalError = class extends UserError {
2250
2247
  constructor(message, code, options) {
2251
2248
  super(message, options);
2252
2249
  this.code = code;
@@ -2255,7 +2252,7 @@ var FatalError = class extends UserError$1 {
2255
2252
  __name(this, "FatalError");
2256
2253
  }
2257
2254
  };
2258
- var CommandLineArgsError = class extends UserError$1 {
2255
+ var CommandLineArgsError = class extends UserError {
2259
2256
  static {
2260
2257
  __name(this, "CommandLineArgsError");
2261
2258
  }
@@ -2981,10 +2978,10 @@ function parseTree(text, errors = [], options = ParseOptions.DEFAULT) {
2981
2978
  return result;
2982
2979
  }
2983
2980
  __name(parseTree, "parseTree");
2984
- function findNodeAtLocation(root, path4$1) {
2981
+ function findNodeAtLocation(root, path4) {
2985
2982
  if (!root) return;
2986
2983
  let node = root;
2987
- for (let segment of path4$1) if (typeof segment === "string") {
2984
+ for (let segment of path4) if (typeof segment === "string") {
2988
2985
  if (node.type !== "object" || !Array.isArray(node.children)) return;
2989
2986
  let found = false;
2990
2987
  for (const propertyNode of node.children) if (Array.isArray(propertyNode.children) && propertyNode.children[0].value === segment && propertyNode.children.length === 2) {
@@ -3211,13 +3208,13 @@ function getNodeType(value) {
3211
3208
  }
3212
3209
  __name(getNodeType, "getNodeType");
3213
3210
  function setProperty(text, originalPath, value, options) {
3214
- const path4$1 = originalPath.slice();
3211
+ const path4 = originalPath.slice();
3215
3212
  const root = parseTree(text, []);
3216
3213
  let parent = void 0;
3217
3214
  let lastSegment = void 0;
3218
- while (path4$1.length > 0) {
3219
- lastSegment = path4$1.pop();
3220
- parent = findNodeAtLocation(root, path4$1);
3215
+ while (path4.length > 0) {
3216
+ lastSegment = path4.pop();
3217
+ parent = findNodeAtLocation(root, path4);
3221
3218
  if (parent === void 0 && value !== void 0) if (typeof lastSegment === "string") value = { [lastSegment]: value };
3222
3219
  else value = [value];
3223
3220
  else break;
@@ -3459,8 +3456,8 @@ function format2(documentText, range, options) {
3459
3456
  return format$1(documentText, range, options);
3460
3457
  }
3461
3458
  __name(format2, "format");
3462
- function modify(text, path4$1, value, options) {
3463
- return setProperty(text, path4$1, value, options);
3459
+ function modify(text, path4, value, options) {
3460
+ return setProperty(text, path4, value, options);
3464
3461
  }
3465
3462
  __name(modify, "modify");
3466
3463
  function applyEdits(text, edits) {
@@ -4198,7 +4195,7 @@ var dist_default = {
4198
4195
  TomlDate,
4199
4196
  TomlError
4200
4197
  };
4201
- var ParseError = class extends UserError$1 {
4198
+ var ParseError = class extends UserError {
4202
4199
  static {
4203
4200
  __name(this, "ParseError");
4204
4201
  }
@@ -4507,15 +4504,15 @@ function locatePathSync(paths, { cwd = process2.cwd(), type = "file", allowSymli
4507
4504
  cwd = toPath(cwd);
4508
4505
  const statFunction = allowSymlinks ? fs.statSync : fs.lstatSync;
4509
4506
  for (const path_ of paths) try {
4510
- if (matchType(type, statFunction(path4.resolve(cwd, path_)))) return path_;
4507
+ if (matchType(type, statFunction(path3.resolve(cwd, path_)))) return path_;
4511
4508
  } catch {}
4512
4509
  }
4513
4510
  __name(locatePathSync, "locatePathSync");
4514
4511
  var toPath2 = /* @__PURE__ */ __name((urlOrPath) => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath, "toPath");
4515
4512
  var findUpStop = Symbol("findUpStop");
4516
4513
  function findUpMultipleSync(name, options = {}) {
4517
- let directory = path4.resolve(toPath2(options.cwd) || "");
4518
- const { root } = path4.parse(directory);
4514
+ let directory = path3.resolve(toPath2(options.cwd) || "");
4515
+ const { root } = path3.parse(directory);
4519
4516
  const stopAt = options.stopAt || root;
4520
4517
  const limit = options.limit || Number.POSITIVE_INFINITY;
4521
4518
  const paths = [name].flat();
@@ -4532,9 +4529,9 @@ function findUpMultipleSync(name, options = {}) {
4532
4529
  cwd: directory
4533
4530
  });
4534
4531
  if (foundPath === findUpStop) break;
4535
- if (foundPath) matches.push(path4.resolve(directory, foundPath));
4532
+ if (foundPath) matches.push(path3.resolve(directory, foundPath));
4536
4533
  if (directory === stopAt || matches.length >= limit) break;
4537
- directory = path4.dirname(directory);
4534
+ directory = path3.dirname(directory);
4538
4535
  }
4539
4536
  return matches;
4540
4537
  }
@@ -4587,7 +4584,7 @@ function resolveWranglerConfigPath({ config, script }, options) {
4587
4584
  deployConfigPath: void 0,
4588
4585
  redirected: false
4589
4586
  };
4590
- return findWranglerConfig$1(script !== void 0 ? path4.dirname(script) : process.cwd(), options);
4587
+ return findWranglerConfig$1(script !== void 0 ? path3.dirname(script) : process.cwd(), options);
4591
4588
  }
4592
4589
  __name(resolveWranglerConfigPath, "resolveWranglerConfigPath");
4593
4590
  function findWranglerConfig$1(referencePath = process.cwd(), { useRedirectIfAvailable = false } = {}) {
@@ -4618,26 +4615,26 @@ function findRedirectedWranglerConfig(cwd, userConfigPath) {
4618
4615
  const deployConfigFile = readFileSync$1(deployConfigPath);
4619
4616
  try {
4620
4617
  const deployConfig = parseJSONC(deployConfigFile, deployConfigPath);
4621
- redirectedConfigPath = deployConfig.configPath && path4.resolve(path4.dirname(deployConfigPath), deployConfig.configPath);
4618
+ redirectedConfigPath = deployConfig.configPath && path3.resolve(path3.dirname(deployConfigPath), deployConfig.configPath);
4622
4619
  } catch (e) {
4623
- throw new UserError$1(`Failed to parse the deploy configuration file at ${path4.relative(".", deployConfigPath)}`, { cause: e });
4620
+ throw new UserError(`Failed to parse the deploy configuration file at ${path3.relative(".", deployConfigPath)}`, { cause: e });
4624
4621
  }
4625
- if (!redirectedConfigPath) throw new UserError$1(esm_default`
4626
- A deploy configuration file was found at "${path4.relative(".", deployConfigPath)}".
4622
+ if (!redirectedConfigPath) throw new UserError(esm_default`
4623
+ A deploy configuration file was found at "${path3.relative(".", deployConfigPath)}".
4627
4624
  But this is not valid - the required "configPath" property was not found.
4628
4625
  Instead this file contains:
4629
4626
  \`\`\`
4630
4627
  ${deployConfigFile}
4631
4628
  \`\`\`
4632
4629
  `);
4633
- if (!existsSync(redirectedConfigPath)) throw new UserError$1(esm_default`
4634
- There is a deploy configuration at "${path4.relative(".", deployConfigPath)}".
4635
- But the redirected configuration path it points to, "${path4.relative(".", redirectedConfigPath)}", does not exist.
4630
+ if (!existsSync(redirectedConfigPath)) throw new UserError(esm_default`
4631
+ There is a deploy configuration at "${path3.relative(".", deployConfigPath)}".
4632
+ But the redirected configuration path it points to, "${path3.relative(".", redirectedConfigPath)}", does not exist.
4636
4633
  `);
4637
4634
  if (userConfigPath) {
4638
- if (path4.join(path4.dirname(userConfigPath), PATH_TO_DEPLOY_CONFIG) !== deployConfigPath) throw new UserError$1(esm_default`
4639
- Found both a user configuration file at "${path4.relative(".", userConfigPath)}"
4640
- and a deploy configuration file at "${path4.relative(".", deployConfigPath)}".
4635
+ if (path3.join(path3.dirname(userConfigPath), PATH_TO_DEPLOY_CONFIG) !== deployConfigPath) throw new UserError(esm_default`
4636
+ Found both a user configuration file at "${path3.relative(".", userConfigPath)}"
4637
+ and a deploy configuration file at "${path3.relative(".", deployConfigPath)}".
4641
4638
  But these do not share the same base path so it is not clear which should be used.
4642
4639
  `);
4643
4640
  }
@@ -4696,7 +4693,7 @@ var require_XDGAppPaths = __commonJS({ "../../node_modules/.pnpm/xdg-app-paths@8
4696
4693
  }
4697
4694
  __name(typeOf, "typeOf");
4698
4695
  function Adapt(adapter_) {
4699
- var meta = adapter_.meta, path5 = adapter_.path, xdg = adapter_.xdg;
4696
+ var meta = adapter_.meta, path4 = adapter_.path, xdg = adapter_.xdg;
4700
4697
  return { XDGAppPaths: new (/* @__PURE__ */ function() {
4701
4698
  function XDGAppPaths_2(options_) {
4702
4699
  if (options_ === void 0) options_ = {};
@@ -4714,7 +4711,7 @@ var require_XDGAppPaths = __commonJS({ "../../node_modules/.pnpm/xdg-app-paths@8
4714
4711
  meta.pkgMainFilename(),
4715
4712
  meta.mainFilename()
4716
4713
  ];
4717
- var name = path5.parse(((_c = namePriorityList.find(function(e) {
4714
+ var name = path4.parse(((_c = namePriorityList.find(function(e) {
4718
4715
  return isString2(e);
4719
4716
  })) !== null && _c !== void 0 ? _c : "$eval") + suffix).name;
4720
4717
  XDGAppPaths.$name = /* @__PURE__ */ __name(function $name() {
@@ -4734,28 +4731,28 @@ var require_XDGAppPaths = __commonJS({ "../../node_modules/.pnpm/xdg-app-paths@8
4734
4731
  }
4735
4732
  __name(finalPathSegment, "finalPathSegment");
4736
4733
  XDGAppPaths.cache = /* @__PURE__ */ __name(function cache$2(dirOptions) {
4737
- return path5.join(xdg.cache(), finalPathSegment(dirOptions));
4734
+ return path4.join(xdg.cache(), finalPathSegment(dirOptions));
4738
4735
  }, "cache");
4739
4736
  XDGAppPaths.config = /* @__PURE__ */ __name(function config(dirOptions) {
4740
- return path5.join(xdg.config(), finalPathSegment(dirOptions));
4737
+ return path4.join(xdg.config(), finalPathSegment(dirOptions));
4741
4738
  }, "config");
4742
4739
  XDGAppPaths.data = /* @__PURE__ */ __name(function data$1(dirOptions) {
4743
- return path5.join(xdg.data(), finalPathSegment(dirOptions));
4740
+ return path4.join(xdg.data(), finalPathSegment(dirOptions));
4744
4741
  }, "data");
4745
4742
  XDGAppPaths.runtime = /* @__PURE__ */ __name(function runtime(dirOptions) {
4746
- return xdg.runtime() ? path5.join(xdg.runtime(), finalPathSegment(dirOptions)) : void 0;
4743
+ return xdg.runtime() ? path4.join(xdg.runtime(), finalPathSegment(dirOptions)) : void 0;
4747
4744
  }, "runtime");
4748
4745
  XDGAppPaths.state = /* @__PURE__ */ __name(function state(dirOptions) {
4749
- return path5.join(xdg.state(), finalPathSegment(dirOptions));
4746
+ return path4.join(xdg.state(), finalPathSegment(dirOptions));
4750
4747
  }, "state");
4751
4748
  XDGAppPaths.configDirs = /* @__PURE__ */ __name(function configDirs(dirOptions) {
4752
4749
  return xdg.configDirs().map(function(s) {
4753
- return path5.join(s, finalPathSegment(dirOptions));
4750
+ return path4.join(s, finalPathSegment(dirOptions));
4754
4751
  });
4755
4752
  }, "configDirs");
4756
4753
  XDGAppPaths.dataDirs = /* @__PURE__ */ __name(function dataDirs(dirOptions) {
4757
4754
  return xdg.dataDirs().map(function(s) {
4758
- return path5.join(s, finalPathSegment(dirOptions));
4755
+ return path4.join(s, finalPathSegment(dirOptions));
4759
4756
  });
4760
4757
  }, "dataDirs");
4761
4758
  return XDGAppPaths;
@@ -4775,7 +4772,7 @@ var require_XDG = __commonJS({ "../../node_modules/.pnpm/xdg-portable@10.6.0/nod
4775
4772
  exports$1.__esModule = true;
4776
4773
  exports$1.Adapt = void 0;
4777
4774
  function Adapt(adapter_) {
4778
- var env$1 = adapter_.env, osPaths = adapter_.osPaths, path5 = adapter_.path;
4775
+ var env$1 = adapter_.env, osPaths = adapter_.osPaths, path4 = adapter_.path;
4779
4776
  var isMacOS = /^darwin$/i.test(adapter_.process.platform);
4780
4777
  var isWinOS = /^win/i.test(adapter_.process.platform);
4781
4778
  function baseDir() {
@@ -4783,7 +4780,7 @@ var require_XDG = __commonJS({ "../../node_modules/.pnpm/xdg-portable@10.6.0/nod
4783
4780
  }
4784
4781
  __name(baseDir, "baseDir");
4785
4782
  function valOrPath(val, pathSegments) {
4786
- return val || path5.join.apply(path5, pathSegments);
4783
+ return val || path4.join.apply(path4, pathSegments);
4787
4784
  }
4788
4785
  __name(valOrPath, "valOrPath");
4789
4786
  var linux = /* @__PURE__ */ __name(function() {
@@ -4897,11 +4894,11 @@ var require_XDG = __commonJS({ "../../node_modules/.pnpm/xdg-portable@10.6.0/nod
4897
4894
  XDG.state = extension.state;
4898
4895
  XDG.configDirs = /* @__PURE__ */ __name(function configDirs() {
4899
4896
  var pathList = env$1.get("XDG_CONFIG_DIRS");
4900
- return __spreadArray([extension.config()], pathList ? pathList.split(path5.delimiter) : []);
4897
+ return __spreadArray([extension.config()], pathList ? pathList.split(path4.delimiter) : []);
4901
4898
  }, "configDirs");
4902
4899
  XDG.dataDirs = /* @__PURE__ */ __name(function dataDirs() {
4903
4900
  var pathList = env$1.get("XDG_DATA_DIRS");
4904
- return __spreadArray([extension.data()], pathList ? pathList.split(path5.delimiter) : []);
4901
+ return __spreadArray([extension.data()], pathList ? pathList.split(path4.delimiter) : []);
4905
4902
  }, "dataDirs");
4906
4903
  return XDG;
4907
4904
  }
@@ -4924,7 +4921,7 @@ var require_OSPaths = __commonJS({ "../../node_modules/.pnpm/os-paths@7.4.0/node
4924
4921
  }
4925
4922
  __name(isEmpty, "isEmpty");
4926
4923
  function Adapt(adapter_) {
4927
- var env$1 = adapter_.env, os2 = adapter_.os, path5 = adapter_.path;
4924
+ var env$1 = adapter_.env, os2 = adapter_.os, path4 = adapter_.path;
4928
4925
  var isWinOS = /^win/i.test(adapter_.process.platform);
4929
4926
  function normalizePath$1(path_) {
4930
4927
  return path_ ? adapter_.path.normalize(adapter_.path.join(path_, ".")) : void 0;
@@ -4936,7 +4933,7 @@ var require_OSPaths = __commonJS({ "../../node_modules/.pnpm/os-paths@7.4.0/node
4936
4933
  typeof os2.homedir === "function" ? os2.homedir() : void 0,
4937
4934
  env$1.get("USERPROFILE"),
4938
4935
  env$1.get("HOME"),
4939
- env$1.get("HOMEDRIVE") || env$1.get("HOMEPATH") ? path5.join(env$1.get("HOMEDRIVE") || "", env$1.get("HOMEPATH") || "") : void 0
4936
+ env$1.get("HOMEDRIVE") || env$1.get("HOMEPATH") ? path4.join(env$1.get("HOMEDRIVE") || "", env$1.get("HOMEPATH") || "") : void 0
4940
4937
  ].find(function(v) {
4941
4938
  return !isEmpty(v);
4942
4939
  }));
@@ -4947,7 +4944,7 @@ var require_OSPaths = __commonJS({ "../../node_modules/.pnpm/os-paths@7.4.0/node
4947
4944
  __name(home, "home");
4948
4945
  function temp() {
4949
4946
  function joinPathToBase(base, segments) {
4950
- return base ? path5.join.apply(path5, __spreadArray([base], segments)) : void 0;
4947
+ return base ? path4.join.apply(path4, __spreadArray([base], segments)) : void 0;
4951
4948
  }
4952
4949
  __name(joinPathToBase, "joinPathToBase");
4953
4950
  function posix$1() {
@@ -5052,14 +5049,14 @@ var require_node = __commonJS({ "../../node_modules/.pnpm/os-paths@7.4.0/node_mo
5052
5049
  exports$1.__esModule = true;
5053
5050
  exports$1.adapter = void 0;
5054
5051
  var os2 = __importStar$1(__require("os"));
5055
- var path5 = __importStar$1(__require("path"));
5052
+ var path4 = __importStar$1(__require("path"));
5056
5053
  exports$1.adapter = {
5057
5054
  atImportPermissions: { env: true },
5058
5055
  env: { get: /* @__PURE__ */ __name(function(s) {
5059
5056
  return process.env[s];
5060
5057
  }, "get") },
5061
5058
  os: os2,
5062
- path: path5,
5059
+ path: path4,
5063
5060
  process
5064
5061
  };
5065
5062
  } });
@@ -5103,7 +5100,7 @@ var require_node2 = __commonJS({ "../../node_modules/.pnpm/xdg-portable@10.6.0/n
5103
5100
  };
5104
5101
  exports$1.__esModule = true;
5105
5102
  exports$1.adapter = void 0;
5106
- var path5 = __importStar$1(__require("path"));
5103
+ var path4 = __importStar$1(__require("path"));
5107
5104
  var os_paths_1 = __importDefault$2(require_mod_cjs());
5108
5105
  exports$1.adapter = {
5109
5106
  atImportPermissions: { env: true },
@@ -5111,7 +5108,7 @@ var require_node2 = __commonJS({ "../../node_modules/.pnpm/xdg-portable@10.6.0/n
5111
5108
  return process.env[s];
5112
5109
  }, "get") },
5113
5110
  osPaths: os_paths_1["default"],
5114
- path: path5,
5111
+ path: path4,
5115
5112
  process
5116
5113
  };
5117
5114
  } });
@@ -5155,7 +5152,7 @@ var require_node3 = __commonJS({ "../../node_modules/.pnpm/xdg-app-paths@8.3.0/n
5155
5152
  };
5156
5153
  exports$1.__esModule = true;
5157
5154
  exports$1.adapter = void 0;
5158
- var path5 = __importStar$1(__require("path"));
5155
+ var path4 = __importStar$1(__require("path"));
5159
5156
  var xdg_portable_1 = __importDefault$2(require_mod_cjs2());
5160
5157
  exports$1.adapter = {
5161
5158
  atImportPermissions: {
@@ -5171,7 +5168,7 @@ var require_node3 = __commonJS({ "../../node_modules/.pnpm/xdg-app-paths@8.3.0/n
5171
5168
  return process.pkg ? process.execPath : void 0;
5172
5169
  }, "pkgMainFilename")
5173
5170
  },
5174
- path: path5,
5171
+ path: path4,
5175
5172
  process,
5176
5173
  xdg: xdg_portable_1["default"]
5177
5174
  };
@@ -5284,174 +5281,6 @@ var PatchConfigError = class extends Error {
5284
5281
  __name(this, "PatchConfigError");
5285
5282
  }
5286
5283
  };
5287
- var ApplicationRollout$1;
5288
- ((ApplicationRollout2) => {
5289
- ((kind2) => {
5290
- kind2["FULL_AUTO"] = "full_auto";
5291
- kind2["FULL_MANUAL"] = "full_manual";
5292
- kind2["DURABLE_OBJECTS_AUTO"] = "durable_objects_auto";
5293
- })(ApplicationRollout2.kind || (ApplicationRollout2.kind = {}));
5294
- ((strategy2) => {
5295
- strategy2["ROLLING"] = "rolling";
5296
- })(ApplicationRollout2.strategy || (ApplicationRollout2.strategy = {}));
5297
- ((status2) => {
5298
- status2["PENDING"] = "pending";
5299
- status2["PROGRESSING"] = "progressing";
5300
- status2["COMPLETED"] = "completed";
5301
- status2["REVERTED"] = "reverted";
5302
- status2["REPLACED"] = "replaced";
5303
- })(ApplicationRollout2.status || (ApplicationRollout2.status = {}));
5304
- })(ApplicationRollout$1 || (ApplicationRollout$1 = {}));
5305
- var BadRequestWithCodeError$1;
5306
- ((BadRequestWithCodeError2) => {
5307
- ((error2) => {
5308
- error2["VALIDATE_INPUT"] = "VALIDATE_INPUT";
5309
- })(BadRequestWithCodeError2.error || (BadRequestWithCodeError2.error = {}));
5310
- })(BadRequestWithCodeError$1 || (BadRequestWithCodeError$1 = {}));
5311
- var CreateApplicationRolloutRequest$1;
5312
- ((CreateApplicationRolloutRequest2) => {
5313
- ((strategy2) => {
5314
- strategy2["ROLLING"] = "rolling";
5315
- })(CreateApplicationRolloutRequest2.strategy || (CreateApplicationRolloutRequest2.strategy = {}));
5316
- ((step_percentage2) => {
5317
- step_percentage2[step_percentage2["_5"] = 5] = "_5";
5318
- step_percentage2[step_percentage2["_10"] = 10] = "_10";
5319
- step_percentage2[step_percentage2["_20"] = 20] = "_20";
5320
- step_percentage2[step_percentage2["_25"] = 25] = "_25";
5321
- step_percentage2[step_percentage2["_50"] = 50] = "_50";
5322
- step_percentage2[step_percentage2["_100"] = 100] = "_100";
5323
- })(CreateApplicationRolloutRequest2.step_percentage || (CreateApplicationRolloutRequest2.step_percentage = {}));
5324
- ((kind2) => {
5325
- kind2["FULL_AUTO"] = "full_auto";
5326
- kind2["FULL_MANUAL"] = "full_manual";
5327
- })(CreateApplicationRolloutRequest2.kind || (CreateApplicationRolloutRequest2.kind = {}));
5328
- })(CreateApplicationRolloutRequest$1 || (CreateApplicationRolloutRequest$1 = {}));
5329
- var DeploymentNotFoundError$1;
5330
- ((DeploymentNotFoundError2) => {
5331
- ((error2) => {
5332
- error2["DEPLOYMENT_NOT_FOUND"] = "DEPLOYMENT_NOT_FOUND";
5333
- })(DeploymentNotFoundError2.error || (DeploymentNotFoundError2.error = {}));
5334
- })(DeploymentNotFoundError$1 || (DeploymentNotFoundError$1 = {}));
5335
- var ImageRegistryAlreadyExistsError$1;
5336
- ((ImageRegistryAlreadyExistsError2) => {
5337
- ((error2) => {
5338
- error2["IMAGE_REGISTRY_ALREADY_EXISTS"] = "IMAGE_REGISTRY_ALREADY_EXISTS";
5339
- })(ImageRegistryAlreadyExistsError2.error || (ImageRegistryAlreadyExistsError2.error = {}));
5340
- })(ImageRegistryAlreadyExistsError$1 || (ImageRegistryAlreadyExistsError$1 = {}));
5341
- var ImageRegistryIsPublic$1;
5342
- ((ImageRegistryIsPublic2) => {
5343
- ((error2) => {
5344
- error2["IMAGE_REGISTRY_IS_PUBLIC"] = "IMAGE_REGISTRY_IS_PUBLIC";
5345
- })(ImageRegistryIsPublic2.error || (ImageRegistryIsPublic2.error = {}));
5346
- })(ImageRegistryIsPublic$1 || (ImageRegistryIsPublic$1 = {}));
5347
- var ImageRegistryNotAllowedError$1;
5348
- ((ImageRegistryNotAllowedError2) => {
5349
- ((error2) => {
5350
- error2["IMAGE_REGISTRY_NOT_ALLOWED"] = "IMAGE_REGISTRY_NOT_ALLOWED";
5351
- })(ImageRegistryNotAllowedError2.error || (ImageRegistryNotAllowedError2.error = {}));
5352
- })(ImageRegistryNotAllowedError$1 || (ImageRegistryNotAllowedError$1 = {}));
5353
- var ImageRegistryNotFoundError$1;
5354
- ((ImageRegistryNotFoundError2) => {
5355
- ((error2) => {
5356
- error2["IMAGE_REGISTRY_NOT_FOUND"] = "IMAGE_REGISTRY_NOT_FOUND";
5357
- })(ImageRegistryNotFoundError2.error || (ImageRegistryNotFoundError2.error = {}));
5358
- })(ImageRegistryNotFoundError$1 || (ImageRegistryNotFoundError$1 = {}));
5359
- var ImageRegistryProtocolAlreadyExists$1;
5360
- ((ImageRegistryProtocolAlreadyExists2) => {
5361
- ((error2) => {
5362
- error2["IMAGE_REGISTRY_PROTOCOL_ALREADY_EXISTS"] = "IMAGE_REGISTRY_PROTOCOL_ALREADY_EXISTS";
5363
- })(ImageRegistryProtocolAlreadyExists2.error || (ImageRegistryProtocolAlreadyExists2.error = {}));
5364
- })(ImageRegistryProtocolAlreadyExists$1 || (ImageRegistryProtocolAlreadyExists$1 = {}));
5365
- var ImageRegistryProtocolIsReferencedError$1;
5366
- ((ImageRegistryProtocolIsReferencedError2) => {
5367
- ((error2) => {
5368
- error2["IMAGE_REGISTRY_PROTO_IS_REFERENCED"] = "IMAGE_REGISTRY_PROTO_IS_REFERENCED";
5369
- })(ImageRegistryProtocolIsReferencedError2.error || (ImageRegistryProtocolIsReferencedError2.error = {}));
5370
- })(ImageRegistryProtocolIsReferencedError$1 || (ImageRegistryProtocolIsReferencedError$1 = {}));
5371
- var ImageRegistryProtocolNotFound$1;
5372
- ((ImageRegistryProtocolNotFound2) => {
5373
- ((error2) => {
5374
- error2["IMAGE_REGISTRY_PROTOCOL_NOT_FOUND"] = "IMAGE_REGISTRY_PROTOCOL_NOT_FOUND";
5375
- })(ImageRegistryProtocolNotFound2.error || (ImageRegistryProtocolNotFound2.error = {}));
5376
- })(ImageRegistryProtocolNotFound$1 || (ImageRegistryProtocolNotFound$1 = {}));
5377
- var ProvisionerConfiguration$1;
5378
- ((ProvisionerConfiguration2) => {
5379
- ((type2) => {
5380
- type2["NONE"] = "none";
5381
- type2["CLOUDINIT"] = "cloudinit";
5382
- })(ProvisionerConfiguration2.type || (ProvisionerConfiguration2.type = {}));
5383
- })(ProvisionerConfiguration$1 || (ProvisionerConfiguration$1 = {}));
5384
- var RolloutStep$1;
5385
- ((RolloutStep2) => {
5386
- ((status2) => {
5387
- status2["PENDING"] = "pending";
5388
- status2["PROGRESSING"] = "progressing";
5389
- status2["REVERTING"] = "reverting";
5390
- status2["COMPLETED"] = "completed";
5391
- status2["REVERTED"] = "reverted";
5392
- })(RolloutStep2.status || (RolloutStep2.status = {}));
5393
- })(RolloutStep$1 || (RolloutStep$1 = {}));
5394
- var SecretNameAlreadyExists$1;
5395
- ((SecretNameAlreadyExists2) => {
5396
- ((error2) => {
5397
- error2["SECRET_NAME_ALREADY_EXISTS"] = "SECRET_NAME_ALREADY_EXISTS";
5398
- })(SecretNameAlreadyExists2.error || (SecretNameAlreadyExists2.error = {}));
5399
- })(SecretNameAlreadyExists$1 || (SecretNameAlreadyExists$1 = {}));
5400
- var SecretNotFound$1;
5401
- ((SecretNotFound2) => {
5402
- ((error2) => {
5403
- error2["SECRET_NAME_NOT_FOUND"] = "SECRET_NAME_NOT_FOUND";
5404
- })(SecretNotFound2.error || (SecretNotFound2.error = {}));
5405
- })(SecretNotFound$1 || (SecretNotFound$1 = {}));
5406
- var SSHPublicKeyNotFoundError$1;
5407
- ((SSHPublicKeyNotFoundError2) => {
5408
- ((error2) => {
5409
- error2["SSH_PUBLIC_KEY_NOT_FOUND"] = "SSH_PUBLIC_KEY_NOT_FOUND";
5410
- })(SSHPublicKeyNotFoundError2.error || (SSHPublicKeyNotFoundError2.error = {}));
5411
- })(SSHPublicKeyNotFoundError$1 || (SSHPublicKeyNotFoundError$1 = {}));
5412
- var UpdateApplicationRolloutRequest$1;
5413
- ((UpdateApplicationRolloutRequest2) => {
5414
- ((action2) => {
5415
- action2["NEXT"] = "next";
5416
- action2["PREVIOUS"] = "previous";
5417
- action2["REVERT"] = "revert";
5418
- })(UpdateApplicationRolloutRequest2.action || (UpdateApplicationRolloutRequest2.action = {}));
5419
- })(UpdateApplicationRolloutRequest$1 || (UpdateApplicationRolloutRequest$1 = {}));
5420
- var UserError2 = class extends Error {
5421
- static {
5422
- __name(this, "UserError");
5423
- }
5424
- telemetryMessage;
5425
- constructor(message, options) {
5426
- super(message, options);
5427
- Object.setPrototypeOf(this, new.target.prototype);
5428
- this.telemetryMessage = options?.telemetryMessage === true ? message : options?.telemetryMessage;
5429
- }
5430
- };
5431
- function isDir$1(inputPath) {
5432
- return statSync(inputPath).isDirectory();
5433
- }
5434
- __name(isDir$1, "isDir");
5435
- var isDockerfile$1 = /* @__PURE__ */ __name((image, configPath) => {
5436
- const baseDir = configPath ? path4.dirname(configPath) : process.cwd();
5437
- const maybeDockerfile = path4.resolve(baseDir, image);
5438
- if (existsSync(maybeDockerfile)) {
5439
- if (isDir$1(maybeDockerfile)) throw new UserError2(`${image} is a directory, you should specify a path to the Dockerfile`);
5440
- return true;
5441
- }
5442
- const errorPrefix = `The image "${image}" does not appear to be a valid path to a Dockerfile, or a valid image registry path:
5443
- `;
5444
- try {
5445
- new URL(`https://${image}`);
5446
- } catch (e) {
5447
- if (e instanceof Error) throw new UserError2(errorPrefix + e.message);
5448
- throw e;
5449
- }
5450
- const imageParts = image.split("/");
5451
- if (!imageParts[imageParts.length - 1]?.includes(":")) throw new UserError2(errorPrefix + `If this is an image registry path, it needs to include at least a tag ':' (e.g: docker.io/httpd:1)`);
5452
- if (image.includes("://")) throw new UserError2(errorPrefix + `Image reference should not include the protocol part (e.g: docker.io/httpd:1, not https://docker.io/httpd:1)`);
5453
- return false;
5454
- }, "isDockerfile");
5455
5284
  var MAX_WORKFLOW_NAME_LENGTH = 64;
5456
5285
  var ALLOWED_WORKFLOW_NAME_REGEX = new RegExp("^[a-zA-Z0-9_][a-zA-Z0-9-_]*$");
5457
5286
  function isValidWorkflowName(name) {
@@ -5465,9 +5294,9 @@ __export(mod_esm_exports, { default: () => mod_esm_default });
5465
5294
  var import_mod_cjs = __toESM(require_mod_cjs3(), 1);
5466
5295
  __reExport(mod_esm_exports, __toESM(require_mod_cjs3(), 1));
5467
5296
  var mod_esm_default = import_mod_cjs.default;
5468
- function isDirectory(configPath) {
5297
+ function isDirectory(path4) {
5469
5298
  try {
5470
- return fs.statSync(configPath).isDirectory();
5299
+ return fs.statSync(path4).isDirectory();
5471
5300
  } catch {
5472
5301
  return false;
5473
5302
  }
@@ -5475,7 +5304,7 @@ function isDirectory(configPath) {
5475
5304
  __name(isDirectory, "isDirectory");
5476
5305
  function getGlobalWranglerConfigPath() {
5477
5306
  const configDir = mod_esm_default(".wrangler").config();
5478
- const legacyConfigDir = path4.join(os.homedir(), ".wrangler");
5307
+ const legacyConfigDir = path3.join(os.homedir(), ".wrangler");
5479
5308
  if (isDirectory(legacyConfigDir)) return legacyConfigDir;
5480
5309
  else return configDir;
5481
5310
  }
@@ -5486,7 +5315,7 @@ function getBooleanEnvironmentVariableFactory(options) {
5486
5315
  switch (process.env[options.variableName]?.toLowerCase()) {
5487
5316
  case "true": return true;
5488
5317
  case "false": return false;
5489
- default: throw new UserError$1(`Expected ${options.variableName} to be "true" or "false", but got ${JSON.stringify(process.env[options.variableName])}`);
5318
+ default: throw new UserError(`Expected ${options.variableName} to be "true" or "false", but got ${JSON.stringify(process.env[options.variableName])}`);
5490
5319
  }
5491
5320
  };
5492
5321
  }
@@ -5512,7 +5341,7 @@ function getProcessEnv(variableName, choices) {
5512
5341
  }
5513
5342
  __name(getProcessEnv, "getProcessEnv");
5514
5343
  function assertOneOf(choices, value) {
5515
- if (Array.isArray(choices) && !choices.includes(value)) throw new UserError$1(`Expected ${JSON.stringify(value)} to be one of ${JSON.stringify(choices)}`);
5344
+ if (Array.isArray(choices) && !choices.includes(value)) throw new UserError(`Expected ${JSON.stringify(value)} to be one of ${JSON.stringify(choices)}`);
5516
5345
  }
5517
5346
  __name(assertOneOf, "assertOneOf");
5518
5347
  var getC3CommandFromEnv = getEnvironmentVariableFactory({
@@ -5532,7 +5361,7 @@ var getCloudflareComplianceRegionFromEnv = getEnvironmentVariableFactory({
5532
5361
  });
5533
5362
  var getCloudflareComplianceRegion = /* @__PURE__ */ __name((complianceConfig) => {
5534
5363
  const complianceRegionFromEnv = getCloudflareComplianceRegionFromEnv();
5535
- if (complianceRegionFromEnv !== void 0 && complianceConfig?.compliance_region !== void 0 && complianceRegionFromEnv !== complianceConfig.compliance_region) throw new UserError$1(dedent`
5364
+ if (complianceRegionFromEnv !== void 0 && complianceConfig?.compliance_region !== void 0 && complianceRegionFromEnv !== complianceConfig.compliance_region) throw new UserError(dedent`
5536
5365
  The compliance region has been set to different values in two places:
5537
5366
  - \`CLOUDFLARE_COMPLIANCE_REGION\` environment variable: \`${complianceRegionFromEnv}\`
5538
5367
  - \`compliance_region\` configuration property: \`${complianceConfig.compliance_region}\`
@@ -5571,7 +5400,7 @@ var getBuildPlatformFromEnv = getEnvironmentVariableFactory({ variableName: "WRA
5571
5400
  var getRegistryPath = getEnvironmentVariableFactory({
5572
5401
  variableName: "WRANGLER_REGISTRY_PATH",
5573
5402
  defaultValue() {
5574
- return path4.join(getGlobalWranglerConfigPath(), "registry");
5403
+ return path3.join(getGlobalWranglerConfigPath(), "registry");
5575
5404
  }
5576
5405
  });
5577
5406
  var getD1ExtraLocationChoices = getEnvironmentVariableFactory({ variableName: "WRANGLER_D1_EXTRA_LOCATION_CHOICES" });
@@ -5604,7 +5433,7 @@ var getWranglerHideBanner = getBooleanEnvironmentVariableFactory({
5604
5433
  });
5605
5434
  var getCloudflareEnv = getEnvironmentVariableFactory({ variableName: "CLOUDFLARE_ENV" });
5606
5435
  var getOpenNextDeployFromEnv = getEnvironmentVariableFactory({ variableName: "OPEN_NEXT_DEPLOY" });
5607
- var getLocalExplorerFromEnv = getBooleanEnvironmentVariableFactory({
5436
+ var getLocalExplorerEnabledFromEnv = getBooleanEnvironmentVariableFactory({
5608
5437
  variableName: "X_LOCAL_EXPLORER",
5609
5438
  defaultValue: false
5610
5439
  });
@@ -5695,9 +5524,9 @@ Please add "${field}" to "env.${envName}".`);
5695
5524
  return rawEnv[field] ?? defaultValue;
5696
5525
  }
5697
5526
  __name(notInheritable, "notInheritable");
5698
- function unwindPropertyPath(root, path5) {
5527
+ function unwindPropertyPath(root, path4) {
5699
5528
  let container = root;
5700
- const parts = path5.split(".");
5529
+ const parts = path4.split(".");
5701
5530
  for (let i$1 = 0; i$1 < parts.length - 1; i$1++) {
5702
5531
  if (!hasProperty(container, parts[i$1])) return;
5703
5532
  container = container[parts[i$1]];
@@ -5910,7 +5739,7 @@ function isPagesConfig(rawConfig) {
5910
5739
  }
5911
5740
  __name(isPagesConfig, "isPagesConfig");
5912
5741
  function normalizeAndValidateConfig(rawConfig, configPath, userConfigPath, args, preserveOriginalMain = false) {
5913
- const diagnostics = new Diagnostics(`Processing ${configPath ? path4.relative(process.cwd(), configPath) : "wrangler"} configuration:`);
5742
+ const diagnostics = new Diagnostics(`Processing ${configPath ? path3.relative(process.cwd(), configPath) : "wrangler"} configuration:`);
5914
5743
  validateOptionalProperty(diagnostics, "", "legacy_env", rawConfig.legacy_env, "boolean");
5915
5744
  validateOptionalProperty(diagnostics, "", "send_metrics", rawConfig.send_metrics, "boolean");
5916
5745
  validateOptionalProperty(diagnostics, "", "keep_vars", rawConfig.keep_vars, "boolean");
@@ -6001,7 +5830,7 @@ function applyPythonConfig(config, args) {
6001
5830
  type: "PythonModule",
6002
5831
  globs: ["**/*.py"]
6003
5832
  });
6004
- if (!config.compatibility_flags.includes("python_workers")) throw new UserError$1("The `python_workers` compatibility flag is required to use Python.");
5833
+ if (!config.compatibility_flags.includes("python_workers")) throw new UserError("The `python_workers` compatibility flag is required to use Python.");
6005
5834
  }
6006
5835
  }
6007
5836
  __name(applyPythonConfig, "applyPythonConfig");
@@ -6014,34 +5843,34 @@ function normalizeAndValidateBuild(diagnostics, rawEnv, rawBuild, configPath) {
6014
5843
  else validateOptionalProperty(diagnostics, "build", "watch_dir", watch_dir, "string");
6015
5844
  return {
6016
5845
  command,
6017
- watch_dir: command && configPath ? Array.isArray(watch_dir) ? watch_dir.map((dir) => path4.relative(process.cwd(), path4.join(path4.dirname(configPath), `${dir}`))) : path4.relative(process.cwd(), path4.join(path4.dirname(configPath), `${watch_dir}`)) : watch_dir,
5846
+ watch_dir: command && configPath ? Array.isArray(watch_dir) ? watch_dir.map((dir) => path3.relative(process.cwd(), path3.join(path3.dirname(configPath), `${dir}`))) : path3.relative(process.cwd(), path3.join(path3.dirname(configPath), `${watch_dir}`)) : watch_dir,
6018
5847
  cwd
6019
5848
  };
6020
5849
  }
6021
5850
  __name(normalizeAndValidateBuild, "normalizeAndValidateBuild");
6022
5851
  function normalizeAndValidateMainField(configPath, rawMain) {
6023
- const configDir = path4.dirname(configPath ?? "wrangler.toml");
5852
+ const configDir = path3.dirname(configPath ?? "wrangler.toml");
6024
5853
  if (rawMain !== void 0) if (typeof rawMain === "string") {
6025
- const directory = path4.resolve(configDir);
6026
- return path4.resolve(directory, rawMain);
5854
+ const directory = path3.resolve(configDir);
5855
+ return path3.resolve(directory, rawMain);
6027
5856
  } else return rawMain;
6028
5857
  else return;
6029
5858
  }
6030
5859
  __name(normalizeAndValidateMainField, "normalizeAndValidateMainField");
6031
5860
  function normalizeAndValidateBaseDirField(configPath, rawDir) {
6032
- const configDir = path4.dirname(configPath ?? "wrangler.toml");
5861
+ const configDir = path3.dirname(configPath ?? "wrangler.toml");
6033
5862
  if (rawDir !== void 0) if (typeof rawDir === "string") {
6034
- const directory = path4.resolve(configDir);
6035
- return path4.resolve(directory, rawDir);
5863
+ const directory = path3.resolve(configDir);
5864
+ return path3.resolve(directory, rawDir);
6036
5865
  } else return rawDir;
6037
5866
  else return;
6038
5867
  }
6039
5868
  __name(normalizeAndValidateBaseDirField, "normalizeAndValidateBaseDirField");
6040
5869
  function normalizeAndValidatePagesBuildOutputDir(configPath, rawPagesDir) {
6041
- const configDir = path4.dirname(configPath ?? "wrangler.toml");
5870
+ const configDir = path3.dirname(configPath ?? "wrangler.toml");
6042
5871
  if (rawPagesDir !== void 0) if (typeof rawPagesDir === "string") {
6043
- const directory = path4.resolve(configDir);
6044
- return path4.resolve(directory, rawPagesDir);
5872
+ const directory = path3.resolve(configDir);
5873
+ return path3.resolve(directory, rawPagesDir);
6045
5874
  } else return rawPagesDir;
6046
5875
  else return;
6047
5876
  }
@@ -6094,7 +5923,7 @@ function normalizeAndValidateSite(diagnostics, configPath, rawConfig, mainEntryP
6094
5923
  validateOptionalProperty(diagnostics, "site", "entry-point", rawConfig.site["entry-point"], "string");
6095
5924
  deprecated(diagnostics, rawConfig, `site.entry-point`, `Delete the \`site.entry-point\` field, then add the top level \`main\` field to your configuration file:
6096
5925
  \`\`\`
6097
- main = "${path4.join(String(rawConfig.site["entry-point"]) || "workers-site", path4.extname(String(rawConfig.site["entry-point"]) || "workers-site") ? "" : "index.js")}"
5926
+ main = "${path3.join(String(rawConfig.site["entry-point"]) || "workers-site", path3.extname(String(rawConfig.site["entry-point"]) || "workers-site") ? "" : "index.js")}"
6098
5927
  \`\`\``, false, void 0, "warning");
6099
5928
  let siteEntryPoint = rawConfig.site["entry-point"];
6100
5929
  if (!mainEntryPoint && !siteEntryPoint) {
@@ -6107,7 +5936,7 @@ main = "workers-site/index.js"
6107
5936
  } else if (mainEntryPoint && siteEntryPoint) diagnostics.errors.push(`Don't define both the \`main\` and \`site.entry-point\` fields in your configuration.
6108
5937
  They serve the same purpose: to point to the entry-point of your worker.
6109
5938
  Delete the deprecated \`site.entry-point\` field from your config.`);
6110
- if (configPath && siteEntryPoint) siteEntryPoint = path4.relative(process.cwd(), path4.join(path4.dirname(configPath), siteEntryPoint));
5939
+ if (configPath && siteEntryPoint) siteEntryPoint = path3.relative(process.cwd(), path3.join(path3.dirname(configPath), siteEntryPoint));
6111
5940
  return {
6112
5941
  bucket,
6113
5942
  "entry-point": siteEntryPoint,
@@ -6139,7 +5968,7 @@ function normalizeAndValidateModulePaths(diagnostics, configPath, field, rawMapp
6139
5968
  if (rawMapping === void 0) return;
6140
5969
  const mapping = {};
6141
5970
  for (const [name, filePath] of Object.entries(rawMapping)) if (isString$2(diagnostics, `${field}['${name}']`, filePath, void 0)) {
6142
- if (configPath) mapping[name] = configPath ? path4.relative(process.cwd(), path4.join(path4.dirname(configPath), filePath)) : filePath;
5971
+ if (configPath) mapping[name] = configPath ? path3.relative(process.cwd(), path3.join(path3.dirname(configPath), filePath)) : filePath;
6143
5972
  }
6144
5973
  return mapping;
6145
5974
  }
@@ -6363,12 +6192,13 @@ function normalizeAndValidateEnvironment(diagnostics, configPath, rawEnv, isDisp
6363
6192
  python_modules: inheritable(diagnostics, topLevelEnv, rawEnv, "python_modules", validatePythonModules, { exclude: ["**/*.pyc"] })
6364
6193
  };
6365
6194
  warnIfDurableObjectsHaveNoMigrations(diagnostics, environment.durable_objects, environment.migrations, configPath);
6195
+ if (envName !== "top level") validateAdditionalProperties(diagnostics, "env." + envName, Object.keys(rawEnv), Object.keys(environment));
6366
6196
  return environment;
6367
6197
  }
6368
6198
  __name(normalizeAndValidateEnvironment, "normalizeAndValidateEnvironment");
6369
6199
  function validateAndNormalizeTsconfig(diagnostics, topLevelEnv, rawEnv, configPath) {
6370
6200
  const tsconfig = inheritable(diagnostics, topLevelEnv, rawEnv, "tsconfig", isString$2, void 0);
6371
- return configPath && tsconfig ? path4.relative(process.cwd(), path4.join(path4.dirname(configPath), tsconfig)) : tsconfig;
6201
+ return configPath && tsconfig ? path3.relative(process.cwd(), path3.join(path3.dirname(configPath), tsconfig)) : tsconfig;
6372
6202
  }
6373
6203
  __name(validateAndNormalizeTsconfig, "validateAndNormalizeTsconfig");
6374
6204
  var validateAndNormalizeRules = /* @__PURE__ */ __name((diagnostics, topLevelEnv, rawEnv, envName) => {
@@ -6808,10 +6638,10 @@ function validateContainerApp(envName, topLevelName, configPath) {
6808
6638
  let resolvedImage = containerAppOptional.image ?? containerAppOptional.configuration?.image;
6809
6639
  let resolvedBuildContextPath = void 0;
6810
6640
  try {
6811
- if (isDockerfile$1(resolvedImage, configPath)) {
6812
- const baseDir = configPath ? path4.dirname(configPath) : process.cwd();
6813
- resolvedImage = path4.resolve(baseDir, resolvedImage);
6814
- resolvedBuildContextPath = containerAppOptional.image_build_context ? path4.resolve(baseDir, containerAppOptional.image_build_context) : path4.dirname(resolvedImage);
6641
+ if (isDockerfile(resolvedImage, configPath)) {
6642
+ const baseDir = configPath ? path3.dirname(configPath) : process.cwd();
6643
+ resolvedImage = path3.resolve(baseDir, resolvedImage);
6644
+ resolvedBuildContextPath = containerAppOptional.image_build_context ? path3.resolve(baseDir, containerAppOptional.image_build_context) : path3.dirname(resolvedImage);
6815
6645
  }
6816
6646
  } catch (err) {
6817
6647
  if (err instanceof Error && err.message) diagnostics.errors.push(err.message);
@@ -7544,7 +7374,10 @@ var validateRateLimitBinding = /* @__PURE__ */ __name((diagnostics, field, value
7544
7374
  return isValid$1;
7545
7375
  }, "validateRateLimitBinding");
7546
7376
  function normalizeAndValidateLimits(diagnostics, topLevelEnv, rawEnv) {
7547
- if (rawEnv.limits) validateRequiredProperty(diagnostics, "limits", "cpu_ms", rawEnv.limits.cpu_ms, "number");
7377
+ if (rawEnv.limits) {
7378
+ validateOptionalProperty(diagnostics, "limits", "cpu_ms", rawEnv.limits.cpu_ms, "number");
7379
+ validateOptionalProperty(diagnostics, "limits", "subrequests", rawEnv.limits.subrequests, "number");
7380
+ }
7548
7381
  return inheritable(diagnostics, topLevelEnv, rawEnv, "limits", () => true, void 0);
7549
7382
  }
7550
7383
  __name(normalizeAndValidateLimits, "normalizeAndValidateLimits");
@@ -7659,7 +7492,7 @@ function warnIfDurableObjectsHaveNoMigrations(diagnostics, durableObjects, migra
7659
7492
  \`\`\`
7660
7493
  ${formatConfigSnippet({ migrations: [{
7661
7494
  tag: "v1",
7662
- new_classes: durableObjectClassnames
7495
+ new_sqlite_classes: durableObjectClassnames
7663
7496
  }] }, configPath)}
7664
7497
  \`\`\`
7665
7498
 
@@ -7688,6 +7521,27 @@ function isRemoteValid(targetObject, fieldPath, diagnostics) {
7688
7521
  return true;
7689
7522
  }
7690
7523
  __name(isRemoteValid, "isRemoteValid");
7524
+ function isDockerfile(imagePath, configPath) {
7525
+ const baseDir = configPath ? path3.dirname(configPath) : process.cwd();
7526
+ const maybeDockerfile = path3.resolve(baseDir, imagePath);
7527
+ if (fs.existsSync(maybeDockerfile)) {
7528
+ if (isDirectory(maybeDockerfile)) throw new UserError(`${imagePath} is a directory, you should specify a path to the Dockerfile`);
7529
+ return true;
7530
+ }
7531
+ const errorPrefix = `The image "${imagePath}" does not appear to be a valid path to a Dockerfile, or a valid image registry path:
7532
+ `;
7533
+ try {
7534
+ new URL(`https://${imagePath}`);
7535
+ } catch (e) {
7536
+ if (e instanceof Error) throw new UserError(errorPrefix + e.message);
7537
+ throw e;
7538
+ }
7539
+ const imageParts = imagePath.split("/");
7540
+ if (!imageParts[imageParts.length - 1]?.includes(":")) throw new UserError(errorPrefix + `If this is an image registry path, it needs to include at least a tag ':' (e.g: docker.io/httpd:1)`);
7541
+ if (imagePath.includes("://")) throw new UserError(errorPrefix + `Image reference should not include the protocol part (e.g: docker.io/httpd:1, not https://docker.io/httpd:1)`);
7542
+ return false;
7543
+ }
7544
+ __name(isDockerfile, "isDockerfile");
7691
7545
  var supportedPagesConfigFields = [
7692
7546
  "pages_build_output_dir",
7693
7547
  "name",
@@ -7816,10 +7670,14 @@ const defuArrayFn = createDefu((object, key, currentValue) => {
7816
7670
  function getDeployConfigPath(root) {
7817
7671
  return nodePath.resolve(root, ".wrangler", "deploy", "config.json");
7818
7672
  }
7819
- function getWorkerConfigs(root) {
7673
+ function getWorkerConfigs(root, isPrerender) {
7820
7674
  const deployConfigPath = getDeployConfigPath(root);
7821
7675
  const deployConfig = JSON.parse(fs$1.readFileSync(deployConfigPath, "utf-8"));
7822
- return [{ configPath: deployConfig.configPath }, ...deployConfig.auxiliaryWorkers].map(({ configPath }) => {
7676
+ return [
7677
+ ...isPrerender && deployConfig.prerenderWorkerConfigPath ? [{ configPath: deployConfig.prerenderWorkerConfigPath }] : [],
7678
+ { configPath: deployConfig.configPath },
7679
+ ...deployConfig.auxiliaryWorkers
7680
+ ].map(({ configPath }) => {
7823
7681
  const resolvedConfigPath = nodePath.resolve(nodePath.dirname(deployConfigPath), configPath);
7824
7682
  return wrangler.unstable_readConfig({ config: resolvedConfigPath });
7825
7683
  });
@@ -7834,25 +7692,30 @@ function writeDeployConfig(resolvedPluginConfig, resolvedViteConfig) {
7834
7692
  if (resolvedPluginConfig.type === "assets-only") {
7835
7693
  const clientOutputDirectory = resolvedViteConfig.environments.client?.build.outDir;
7836
7694
  assert(clientOutputDirectory, "Unexpected error: client environment output directory is undefined");
7695
+ const prerenderOutputDirectory = resolvedPluginConfig.prerenderWorkerEnvironmentName ? resolvedViteConfig.environments[resolvedPluginConfig.prerenderWorkerEnvironmentName]?.build.outDir : void 0;
7837
7696
  const deployConfig = {
7838
7697
  configPath: getRelativePathToWorkerConfig(deployConfigDirectory, resolvedViteConfig.root, clientOutputDirectory),
7839
- auxiliaryWorkers: []
7698
+ auxiliaryWorkers: [],
7699
+ prerenderWorkerConfigPath: prerenderOutputDirectory ? getRelativePathToWorkerConfig(deployConfigDirectory, resolvedViteConfig.root, prerenderOutputDirectory) : void 0
7840
7700
  };
7841
7701
  fs$1.writeFileSync(deployConfigPath, JSON.stringify(deployConfig));
7842
7702
  } else {
7843
7703
  let entryWorkerConfigPath;
7704
+ let prerenderWorkerConfigPath;
7844
7705
  const auxiliaryWorkers = [];
7845
7706
  for (const environmentName of resolvedPluginConfig.environmentNameToWorkerMap.keys()) {
7846
7707
  const outputDirectory = resolvedViteConfig.environments[environmentName]?.build.outDir;
7847
7708
  assert(outputDirectory, `Unexpected error: ${environmentName} environment output directory is undefined`);
7848
7709
  const configPath = getRelativePathToWorkerConfig(deployConfigDirectory, resolvedViteConfig.root, outputDirectory);
7849
7710
  if (environmentName === resolvedPluginConfig.entryWorkerEnvironmentName) entryWorkerConfigPath = configPath;
7711
+ else if (environmentName === resolvedPluginConfig.prerenderWorkerEnvironmentName) prerenderWorkerConfigPath = configPath;
7850
7712
  else auxiliaryWorkers.push({ configPath });
7851
7713
  }
7852
7714
  assert(entryWorkerConfigPath, `Unexpected error: entryWorkerConfigPath is undefined`);
7853
7715
  const deployConfig = {
7854
7716
  configPath: entryWorkerConfigPath,
7855
- auxiliaryWorkers
7717
+ auxiliaryWorkers,
7718
+ prerenderWorkerConfigPath
7856
7719
  };
7857
7720
  fs$1.writeFileSync(deployConfigPath, JSON.stringify(deployConfig));
7858
7721
  }
@@ -13228,7 +13091,7 @@ function read(jsonPath, { base, specifier }) {
13228
13091
  /** @type {string | undefined} */
13229
13092
  let string;
13230
13093
  try {
13231
- string = fs.readFileSync(path4.toNamespacedPath(jsonPath), "utf8");
13094
+ string = fs.readFileSync(path3.toNamespacedPath(jsonPath), "utf8");
13232
13095
  } catch (error) {
13233
13096
  const exception = error;
13234
13097
  if (exception.code !== "ENOENT") throw exception;
@@ -13434,7 +13297,7 @@ function emitLegacyIndexDeprecation(url, packageJsonUrl, base, main) {
13434
13297
  const packagePath = fileURLToPath(new URL$1(".", packageJsonUrl));
13435
13298
  const basePath = fileURLToPath(base);
13436
13299
  if (!main) process2.emitWarning(`No "main" or "exports" field defined in the package.json for ${packagePath} resolving the main entry point "${urlPath.slice(packagePath.length)}", imported from ${basePath}.\nDefault "index" lookups for the main are deprecated for ES modules.`, "DeprecationWarning", "DEP0151");
13437
- else if (path4.resolve(packagePath, main) !== urlPath) process2.emitWarning(`Package ${packagePath} has a "main" field set to "${main}", excluding the full filename and extension to the resolved file at "${urlPath.slice(packagePath.length)}", imported from ${basePath}.\n Automatic extension resolution of the "main" field is deprecated for ES modules.`, "DeprecationWarning", "DEP0151");
13300
+ else if (path3.resolve(packagePath, main) !== urlPath) process2.emitWarning(`Package ${packagePath} has a "main" field set to "${main}", excluding the full filename and extension to the resolved file at "${urlPath.slice(packagePath.length)}", imported from ${basePath}.\n Automatic extension resolution of the "main" field is deprecated for ES modules.`, "DeprecationWarning", "DEP0151");
13438
13301
  }
13439
13302
  /**
13440
13303
  * @param {string} path
@@ -13541,7 +13404,7 @@ function finalizeResolution(resolved, base, preserveSymlinks) {
13541
13404
  {
13542
13405
  const real = realpathSync(filePath);
13543
13406
  const { search, hash } = resolved;
13544
- resolved = pathToFileURL(real + (filePath.endsWith(path4.sep) ? "/" : ""));
13407
+ resolved = pathToFileURL(real + (filePath.endsWith(path3.sep) ? "/" : ""));
13545
13408
  resolved.search = search;
13546
13409
  resolved.hash = hash;
13547
13410
  }
@@ -14037,6 +13900,148 @@ function resolvePathSync(id, options) {
14037
13900
  return fileURLToPath$1(resolveSync(id, options));
14038
13901
  }
14039
13902
 
13903
+ //#endregion
13904
+ //#region src/shared.ts
13905
+ const UNKNOWN_HOST = "http://localhost";
13906
+ const INIT_PATH = "/__vite_plugin_cloudflare_init__";
13907
+ const GET_EXPORT_TYPES_PATH = "/__vite_plugin_cloudflare_get_export_types__";
13908
+ const WORKER_ENTRY_PATH_HEADER = "__VITE_WORKER_ENTRY_PATH__";
13909
+ const IS_ENTRY_WORKER_HEADER = "__VITE_IS_ENTRY_WORKER__";
13910
+ const ENVIRONMENT_NAME_HEADER = "__VITE_ENVIRONMENT_NAME__";
13911
+ const IS_PARENT_ENVIRONMENT_HEADER = "__VITE_IS_PARENT_ENVIRONMENT__";
13912
+ const virtualPrefix = "virtual:cloudflare/";
13913
+ const VIRTUAL_WORKER_ENTRY = `${virtualPrefix}worker-entry`;
13914
+ const VIRTUAL_EXPORT_TYPES = `${virtualPrefix}export-types`;
13915
+
13916
+ //#endregion
13917
+ //#region src/plugins/virtual-modules.ts
13918
+ const VIRTUAL_USER_ENTRY = `${virtualPrefix}user-entry`;
13919
+ const VIRTUAL_CLIENT_FALLBACK_ENTRY = `${virtualPrefix}client-fallback-entry`;
13920
+ const VIRTUAL_NODEJS_GLOBAL_INJECT_PREFIX = `${virtualPrefix}nodejs-global-inject/`;
13921
+ const virtualCloudflareResolveRE = /^virtual:cloudflare\//;
13922
+ const virtualCloudflareLoadRE = /^\0virtual:cloudflare\//;
13923
+ /**
13924
+ * Plugin to provide virtual modules
13925
+ */
13926
+ const virtualModulesPlugin = createPlugin("virtual-modules", (ctx) => {
13927
+ return {
13928
+ applyToEnvironment(environment) {
13929
+ return !ctx.isChildEnvironment(environment.name) && ctx.getWorkerConfig(environment.name) !== void 0;
13930
+ },
13931
+ resolveId: {
13932
+ filter: { id: virtualCloudflareResolveRE },
13933
+ async handler(source) {
13934
+ if (!virtualCloudflareResolveRE.test(source)) return;
13935
+ if (source === VIRTUAL_USER_ENTRY) {
13936
+ const workerConfig = ctx.getWorkerConfig(this.environment.name);
13937
+ assert(workerConfig, "Expected `workerConfig` to be defined");
13938
+ const main = await this.resolve(workerConfig.main);
13939
+ if (!main) throw new Error(`Failed to resolve main entry file "${workerConfig.main}" for environment "${this.environment.name}"`);
13940
+ return main;
13941
+ }
13942
+ return `\0${source}`;
13943
+ }
13944
+ },
13945
+ load: {
13946
+ filter: { id: virtualCloudflareLoadRE },
13947
+ handler(id) {
13948
+ if (id === `\0${VIRTUAL_WORKER_ENTRY}`) {
13949
+ const nodeJsCompat = ctx.getNodeJsCompat(this.environment.name);
13950
+ return `
13951
+ ${nodeJsCompat ? nodeJsCompat.injectGlobalCode() : ""}
13952
+ import { getExportTypes } from "${VIRTUAL_EXPORT_TYPES}";
13953
+ import * as mod from "${VIRTUAL_USER_ENTRY}";
13954
+ export * from "${VIRTUAL_USER_ENTRY}";
13955
+ export default mod.default ?? {};
13956
+ if (import.meta.hot) {
13957
+ import.meta.hot.accept((module) => {
13958
+ const exportTypes = getExportTypes(module);
13959
+ import.meta.hot.send("vite-plugin-cloudflare:worker-export-types", exportTypes);
13960
+ });
13961
+ }
13962
+ `;
13963
+ }
13964
+ if (id === `\0${VIRTUAL_EXPORT_TYPES}`) return `
13965
+ import {
13966
+ WorkerEntrypoint,
13967
+ DurableObject,
13968
+ WorkflowEntrypoint,
13969
+ } from "cloudflare:workers";
13970
+
13971
+ const baseClasses = new Map([
13972
+ ["WorkerEntrypoint", WorkerEntrypoint],
13973
+ ["DurableObject", DurableObject],
13974
+ ["WorkflowEntrypoint", WorkflowEntrypoint],
13975
+ ]);
13976
+
13977
+ export function getExportTypes(module) {
13978
+ const exportTypes = {};
13979
+
13980
+ for (const [key, value] of Object.entries(module)) {
13981
+ if (key === "default") {
13982
+ continue;
13983
+ }
13984
+
13985
+ let exportType;
13986
+
13987
+ if (typeof value === "function") {
13988
+ for (const [type, baseClass] of baseClasses) {
13989
+ if (baseClass.prototype.isPrototypeOf(value.prototype)) {
13990
+ exportType = type;
13991
+ break;
13992
+ }
13993
+ }
13994
+
13995
+ if (!exportType) {
13996
+ exportType = "DurableObject";
13997
+ }
13998
+ } else if (typeof value === "object" && value !== null) {
13999
+ exportType = "WorkerEntrypoint";
14000
+ }
14001
+
14002
+ exportTypes[key] = exportType;
14003
+ }
14004
+
14005
+ return exportTypes;
14006
+ }
14007
+ `;
14008
+ if (id.startsWith(`\0${VIRTUAL_NODEJS_GLOBAL_INJECT_PREFIX}`)) {
14009
+ const nodeJsCompat = ctx.getNodeJsCompat(this.environment.name);
14010
+ assertHasNodeJsCompat(nodeJsCompat);
14011
+ return nodeJsCompat.getGlobalVirtualModule(id.slice(1));
14012
+ }
14013
+ }
14014
+ }
14015
+ };
14016
+ });
14017
+ const virtualClientFallbackResolveRE = /^virtual:cloudflare\/client-fallback-entry$/;
14018
+ const virtualClientFallbackLoadRE = /^\0virtual:cloudflare\/client-fallback-entry$/;
14019
+ /**
14020
+ * Plugin to provide a virtual fallback entry file for the `client` environment.
14021
+ * This is used as the entry file for the client build when only the `public` directory is present.
14022
+ */
14023
+ const virtualClientFallbackPlugin = createPlugin("virtual-client-fallback", () => {
14024
+ return {
14025
+ applyToEnvironment(environment) {
14026
+ return environment.name === "client";
14027
+ },
14028
+ resolveId: {
14029
+ filter: { id: virtualClientFallbackResolveRE },
14030
+ handler(source) {
14031
+ if (!virtualClientFallbackResolveRE.test(source)) return;
14032
+ return `\0${VIRTUAL_CLIENT_FALLBACK_ENTRY}`;
14033
+ }
14034
+ },
14035
+ load: {
14036
+ filter: { id: virtualClientFallbackLoadRE },
14037
+ handler(id) {
14038
+ if (!virtualClientFallbackLoadRE.test(id)) return;
14039
+ return "";
14040
+ }
14041
+ }
14042
+ };
14043
+ });
14044
+
14040
14045
  //#endregion
14041
14046
  //#region src/nodejs-compat.ts
14042
14047
  var NodeJsCompat = class {
@@ -14084,7 +14089,6 @@ var NodeJsCompat = class {
14084
14089
  #getInjects() {
14085
14090
  const injectsByModule = /* @__PURE__ */ new Map();
14086
14091
  const virtualModulePathToSpecifier = /* @__PURE__ */ new Map();
14087
- const virtualModulePrefix = `\0_nodejs_global_inject-`;
14088
14092
  for (const [injectedName, moduleSpecifier] of Object.entries(this.#env.inject)) {
14089
14093
  const [module$2, exportName, importName] = Array.isArray(moduleSpecifier) ? [
14090
14094
  moduleSpecifier[0],
@@ -14097,7 +14101,7 @@ var NodeJsCompat = class {
14097
14101
  ];
14098
14102
  if (!injectsByModule.has(module$2)) {
14099
14103
  injectsByModule.set(module$2, []);
14100
- virtualModulePathToSpecifier.set(`${virtualModulePrefix}${module$2.replaceAll("/", "-")}`, module$2);
14104
+ virtualModulePathToSpecifier.set(`${VIRTUAL_NODEJS_GLOBAL_INJECT_PREFIX}${module$2}`, module$2);
14101
14105
  }
14102
14106
  const injects = injectsByModule.get(module$2);
14103
14107
  assert(injects, `expected injects for "${module$2}" to be defined`);
@@ -14171,6 +14175,7 @@ function hasNodeJsAls(workerConfig) {
14171
14175
  function isNodeAlsModule(modulePath) {
14172
14176
  return /^(?:node:)?async_hooks$/.test(modulePath);
14173
14177
  }
14178
+ const nodeBuiltinsRE = /* @__PURE__ */ new RegExp(`^(${nonPrefixedNodeModules.join("|")}|node:.+)$`);
14174
14179
  function assertHasNodeJsCompat(nodeJsCompat) {
14175
14180
  assert(nodeJsCompat, `expected nodeJsCompat to be defined`);
14176
14181
  }
@@ -14482,7 +14487,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
14482
14487
  const shared = {
14483
14488
  persistState: pluginConfig.persistState ?? true,
14484
14489
  inspectorPort: pluginConfig.inspectorPort,
14485
- experimental: pluginConfig.experimental ?? {}
14490
+ experimental: { headersAndRedirectsDevModeSupport: pluginConfig.experimental?.headersAndRedirectsDevModeSupport }
14486
14491
  };
14487
14492
  const root = userConfig.root ? nodePath.resolve(userConfig.root) : process.cwd();
14488
14493
  const prefixedEnv = vite.loadEnv(viteEnv.mode, root, ["CLOUDFLARE_", "WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_"]);
@@ -14491,34 +14496,57 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
14491
14496
  ...shared,
14492
14497
  remoteBindings: pluginConfig.remoteBindings ?? true,
14493
14498
  type: "preview",
14494
- workers: getWorkerConfigs(root)
14499
+ workers: getWorkerConfigs(root, !!process.env.CLOUDFLARE_VITE_BUILD)
14495
14500
  };
14496
14501
  const configPaths = /* @__PURE__ */ new Set();
14497
14502
  const cloudflareEnv = prefixedEnv.CLOUDFLARE_ENV;
14503
+ const validateAndAddEnvironmentName = createEnvironmentNameValidator();
14498
14504
  const entryWorkerResolvedConfig = resolveWorkerConfig({
14499
14505
  root,
14500
14506
  configPath: getValidatedWranglerConfigPath(root, pluginConfig.configPath),
14501
- env: prefixedEnv.CLOUDFLARE_ENV,
14507
+ env: cloudflareEnv,
14502
14508
  configCustomizer: pluginConfig.config,
14503
14509
  visitedConfigPaths: configPaths
14504
14510
  });
14511
+ const environmentNameToWorkerMap = /* @__PURE__ */ new Map();
14512
+ const environmentNameToChildEnvironmentNamesMap = /* @__PURE__ */ new Map();
14513
+ const prerenderWorkerConfig = pluginConfig.experimental?.prerenderWorker;
14514
+ let prerenderWorkerEnvironmentName;
14515
+ if (prerenderWorkerConfig && viteEnv.command === "build") {
14516
+ const workerResolvedConfig = resolveWorkerConfig({
14517
+ root,
14518
+ configPath: getValidatedWranglerConfigPath(root, prerenderWorkerConfig.configPath, true),
14519
+ env: cloudflareEnv,
14520
+ configCustomizer: "config" in prerenderWorkerConfig ? prerenderWorkerConfig.config : void 0,
14521
+ entryWorkerConfig: entryWorkerResolvedConfig.config,
14522
+ visitedConfigPaths: configPaths
14523
+ });
14524
+ prerenderWorkerEnvironmentName = prerenderWorkerConfig.viteEnvironment?.name ?? workerNameToEnvironmentName(workerResolvedConfig.config.topLevelName);
14525
+ validateAndAddEnvironmentName(prerenderWorkerEnvironmentName);
14526
+ environmentNameToWorkerMap.set(prerenderWorkerEnvironmentName, resolveWorker(workerResolvedConfig.config));
14527
+ const prerenderWorkerChildEnvironments = prerenderWorkerConfig.viteEnvironment?.childEnvironments;
14528
+ if (prerenderWorkerChildEnvironments) {
14529
+ for (const childName of prerenderWorkerChildEnvironments) validateAndAddEnvironmentName(childName);
14530
+ environmentNameToChildEnvironmentNamesMap.set(prerenderWorkerEnvironmentName, prerenderWorkerChildEnvironments);
14531
+ }
14532
+ }
14505
14533
  if (entryWorkerResolvedConfig.type === "assets-only") return {
14506
14534
  ...shared,
14507
14535
  type: "assets-only",
14508
14536
  cloudflareEnv,
14509
14537
  config: entryWorkerResolvedConfig.config,
14538
+ environmentNameToWorkerMap,
14539
+ environmentNameToChildEnvironmentNamesMap,
14540
+ prerenderWorkerEnvironmentName,
14510
14541
  configPaths,
14511
14542
  remoteBindings: pluginConfig.remoteBindings ?? true,
14512
14543
  rawConfigs: { entryWorker: entryWorkerResolvedConfig }
14513
14544
  };
14514
- const entryWorkerConfig = entryWorkerResolvedConfig.config;
14515
- const entryWorkerEnvironmentName = pluginConfig.viteEnvironment?.name ?? workerNameToEnvironmentName(entryWorkerConfig.topLevelName);
14516
- const validateAndAddEnvironmentName = createEnvironmentNameValidator();
14517
- validateAndAddEnvironmentName(entryWorkerEnvironmentName);
14518
14545
  let staticRouting;
14519
- if (Array.isArray(entryWorkerConfig.assets?.run_worker_first)) staticRouting = parseStaticRouting(entryWorkerConfig.assets.run_worker_first);
14520
- const environmentNameToWorkerMap = new Map([[entryWorkerEnvironmentName, resolveWorker(entryWorkerConfig)]]);
14521
- const environmentNameToChildEnvironmentNamesMap = /* @__PURE__ */ new Map();
14546
+ if (Array.isArray(entryWorkerResolvedConfig.config.assets?.run_worker_first)) staticRouting = parseStaticRouting(entryWorkerResolvedConfig.config.assets.run_worker_first);
14547
+ const entryWorkerEnvironmentName = pluginConfig.viteEnvironment?.name ?? workerNameToEnvironmentName(entryWorkerResolvedConfig.config.topLevelName);
14548
+ validateAndAddEnvironmentName(entryWorkerEnvironmentName);
14549
+ environmentNameToWorkerMap.set(entryWorkerEnvironmentName, resolveWorker(entryWorkerResolvedConfig.config));
14522
14550
  const entryWorkerChildEnvironments = pluginConfig.viteEnvironment?.childEnvironments;
14523
14551
  if (entryWorkerChildEnvironments) {
14524
14552
  for (const childName of entryWorkerChildEnvironments) validateAndAddEnvironmentName(childName);
@@ -14531,7 +14559,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
14531
14559
  configPath: getValidatedWranglerConfigPath(root, auxiliaryWorker.configPath, true),
14532
14560
  env: cloudflareEnv,
14533
14561
  configCustomizer: "config" in auxiliaryWorker ? auxiliaryWorker.config : void 0,
14534
- entryWorkerConfig,
14562
+ entryWorkerConfig: entryWorkerResolvedConfig.config,
14535
14563
  visitedConfigPaths: configPaths
14536
14564
  });
14537
14565
  auxiliaryWorkersResolvedConfigs.push(workerResolvedConfig);
@@ -14551,6 +14579,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
14551
14579
  configPaths,
14552
14580
  environmentNameToWorkerMap,
14553
14581
  environmentNameToChildEnvironmentNamesMap,
14582
+ prerenderWorkerEnvironmentName,
14554
14583
  entryWorkerEnvironmentName,
14555
14584
  staticRouting,
14556
14585
  remoteBindings: pluginConfig.remoteBindings ?? true,
@@ -15590,16 +15619,19 @@ const additionalModulesPlugin = createPlugin("additional-modules", (ctx) => {
15590
15619
  applyToEnvironment(environment) {
15591
15620
  return ctx.getWorkerConfig(environment.name) !== void 0;
15592
15621
  },
15593
- async resolveId(source, importer, options) {
15594
- const additionalModuleType = matchAdditionalModule(source);
15595
- if (!additionalModuleType) return;
15596
- const resolved = await this.resolve(cleanUrl(source), importer, options);
15597
- if (!resolved) throw new Error(`Import "${source}" not found. Does the file exist?`);
15598
- additionalModulePaths.add(resolved.id);
15599
- return {
15600
- external: true,
15601
- id: createModuleReference(additionalModuleType, resolved.id)
15602
- };
15622
+ resolveId: {
15623
+ filter: { id: moduleRuleFilters },
15624
+ async handler(source, importer, options) {
15625
+ const additionalModuleType = matchAdditionalModule(source);
15626
+ if (!additionalModuleType) return;
15627
+ const resolved = await this.resolve(cleanUrl(source), importer, options);
15628
+ if (!resolved) throw new Error(`Import "${source}" not found. Does the file exist?`);
15629
+ additionalModulePaths.add(resolved.id);
15630
+ return {
15631
+ external: true,
15632
+ id: createModuleReference(additionalModuleType, resolved.id)
15633
+ };
15634
+ }
15603
15635
  },
15604
15636
  hotUpdate(options) {
15605
15637
  if (additionalModulePaths.has(options.file)) {
@@ -15607,34 +15639,37 @@ const additionalModulesPlugin = createPlugin("additional-modules", (ctx) => {
15607
15639
  return [];
15608
15640
  }
15609
15641
  },
15610
- async renderChunk(code, chunk) {
15611
- const matches = code.matchAll(additionalModuleGlobalRE);
15612
- let magicString;
15613
- for (const match of matches) {
15614
- magicString ??= new MagicString(code);
15615
- const [full, _, modulePath] = match;
15616
- assert(modulePath, `Unexpected error: module path not found in reference ${full}.`);
15617
- let source;
15618
- try {
15619
- source = await fsp.readFile(modulePath);
15620
- } catch {
15621
- throw new Error(`Import "${modulePath}" not found. Does the file exist?`);
15642
+ renderChunk: {
15643
+ filter: { code: { include: additionalModuleRE } },
15644
+ async handler(code, chunk) {
15645
+ const matches = code.matchAll(additionalModuleGlobalRE);
15646
+ let magicString;
15647
+ for (const match of matches) {
15648
+ magicString ??= new MagicString(code);
15649
+ const [full, _, modulePath] = match;
15650
+ assert(modulePath, `Unexpected error: module path not found in reference ${full}.`);
15651
+ let source;
15652
+ try {
15653
+ source = await fsp.readFile(modulePath);
15654
+ } catch {
15655
+ throw new Error(`Import "${modulePath}" not found. Does the file exist?`);
15656
+ }
15657
+ const referenceId = this.emitFile({
15658
+ type: "asset",
15659
+ name: nodePath.basename(modulePath),
15660
+ originalFileName: modulePath,
15661
+ source
15662
+ });
15663
+ const emittedFileName = this.getFileName(referenceId);
15664
+ const relativePath = vite.normalizePath(nodePath.relative(nodePath.dirname(chunk.fileName), emittedFileName));
15665
+ const importPath = relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
15666
+ magicString.update(match.index, match.index + full.length, importPath);
15622
15667
  }
15623
- const referenceId = this.emitFile({
15624
- type: "asset",
15625
- name: nodePath.basename(modulePath),
15626
- originalFileName: modulePath,
15627
- source
15628
- });
15629
- const emittedFileName = this.getFileName(referenceId);
15630
- const relativePath = vite.normalizePath(nodePath.relative(nodePath.dirname(chunk.fileName), emittedFileName));
15631
- const importPath = relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
15632
- magicString.update(match.index, match.index + full.length, importPath);
15633
- }
15634
- if (magicString) return {
15635
- code: magicString.toString(),
15636
- map: this.environment.config.build.sourcemap ? magicString.generateMap({ hires: "boundary" }) : null
15637
- };
15668
+ if (magicString) return {
15669
+ code: magicString.toString(),
15670
+ map: this.environment.config.build.sourcemap ? magicString.generateMap({ hires: "boundary" }) : null
15671
+ };
15672
+ }
15638
15673
  }
15639
15674
  };
15640
15675
  });
@@ -15648,23 +15683,20 @@ const additionalModuleGlobalRE = new RegExp(ADDITIONAL_MODULE_PATTERN, "g");
15648
15683
  const moduleRules = [
15649
15684
  {
15650
15685
  type: "CompiledWasm",
15651
- extensions: [".wasm", ".wasm?module"]
15686
+ pattern: /\.wasm(\?module)?$/
15652
15687
  },
15653
15688
  {
15654
15689
  type: "Data",
15655
- extensions: [".bin"]
15690
+ pattern: /\.bin$/
15656
15691
  },
15657
15692
  {
15658
15693
  type: "Text",
15659
- extensions: [
15660
- ".txt",
15661
- ".html",
15662
- ".sql"
15663
- ]
15694
+ pattern: /\.(txt|html|sql)$/
15664
15695
  }
15665
15696
  ];
15697
+ const moduleRuleFilters = moduleRules.map((rule) => rule.pattern);
15666
15698
  function matchAdditionalModule(source) {
15667
- for (const rule of moduleRules) for (const extension of rule.extensions) if (source.endsWith(extension)) return rule.type;
15699
+ for (const rule of moduleRules) if (rule.pattern.test(source)) return rule.type;
15668
15700
  return null;
15669
15701
  }
15670
15702
  function createModuleReference(type, id) {
@@ -21353,126 +21385,9 @@ var require_picocolors = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnp
21353
21385
  module.exports.createColors = createColors;
21354
21386
  }) });
21355
21387
 
21356
- //#endregion
21357
- //#region src/shared.ts
21358
- var import_picocolors$4 = /* @__PURE__ */ __toESM$1(require_picocolors(), 1);
21359
- const UNKNOWN_HOST = "http://localhost";
21360
- const INIT_PATH = "/__vite_plugin_cloudflare_init__";
21361
- const GET_EXPORT_TYPES_PATH = "/__vite_plugin_cloudflare_get_export_types__";
21362
- const WORKER_ENTRY_PATH_HEADER = "__VITE_WORKER_ENTRY_PATH__";
21363
- const IS_ENTRY_WORKER_HEADER = "__VITE_IS_ENTRY_WORKER__";
21364
- const ENVIRONMENT_NAME_HEADER = "__VITE_ENVIRONMENT_NAME__";
21365
- const IS_PARENT_ENVIRONMENT_HEADER = "__VITE_IS_PARENT_ENVIRONMENT__";
21366
- const virtualPrefix = "virtual:cloudflare/";
21367
- const VIRTUAL_WORKER_ENTRY = `${virtualPrefix}worker-entry`;
21368
- const VIRTUAL_EXPORT_TYPES = `${virtualPrefix}export-types`;
21369
-
21370
- //#endregion
21371
- //#region src/plugins/virtual-modules.ts
21372
- const VIRTUAL_USER_ENTRY = `${virtualPrefix}user-entry`;
21373
- const VIRTUAL_CLIENT_FALLBACK_ENTRY = `${virtualPrefix}client-fallback-entry`;
21374
- /**
21375
- * Plugin to provide virtual modules
21376
- */
21377
- const virtualModulesPlugin = createPlugin("virtual-modules", (ctx) => {
21378
- return {
21379
- applyToEnvironment(environment) {
21380
- return !ctx.isChildEnvironment(environment.name) && ctx.getWorkerConfig(environment.name) !== void 0;
21381
- },
21382
- async resolveId(source) {
21383
- if (source === VIRTUAL_WORKER_ENTRY || source === VIRTUAL_EXPORT_TYPES) return `\0${source}`;
21384
- if (source === VIRTUAL_USER_ENTRY) {
21385
- const workerConfig = ctx.getWorkerConfig(this.environment.name);
21386
- assert(workerConfig, "Expected `workerConfig` to be defined");
21387
- const main = await this.resolve(workerConfig.main);
21388
- if (!main) throw new Error(`Failed to resolve main entry file "${workerConfig.main}" for environment "${this.environment.name}"`);
21389
- return main;
21390
- }
21391
- },
21392
- load(id) {
21393
- if (id === `\0${VIRTUAL_WORKER_ENTRY}`) {
21394
- const nodeJsCompat = ctx.getNodeJsCompat(this.environment.name);
21395
- return `
21396
- ${nodeJsCompat ? nodeJsCompat.injectGlobalCode() : ""}
21397
- import { getExportTypes } from "${VIRTUAL_EXPORT_TYPES}";
21398
- import * as mod from "${VIRTUAL_USER_ENTRY}";
21399
- export * from "${VIRTUAL_USER_ENTRY}";
21400
- export default mod.default ?? {};
21401
- if (import.meta.hot) {
21402
- import.meta.hot.accept((module) => {
21403
- const exportTypes = getExportTypes(module);
21404
- import.meta.hot.send("vite-plugin-cloudflare:worker-export-types", exportTypes);
21405
- });
21406
- }
21407
- `;
21408
- }
21409
- if (id === `\0${VIRTUAL_EXPORT_TYPES}`) return `
21410
- import {
21411
- WorkerEntrypoint,
21412
- DurableObject,
21413
- WorkflowEntrypoint,
21414
- } from "cloudflare:workers";
21415
-
21416
- const baseClasses = new Map([
21417
- ["WorkerEntrypoint", WorkerEntrypoint],
21418
- ["DurableObject", DurableObject],
21419
- ["WorkflowEntrypoint", WorkflowEntrypoint],
21420
- ]);
21421
-
21422
- export function getExportTypes(module) {
21423
- const exportTypes = {};
21424
-
21425
- for (const [key, value] of Object.entries(module)) {
21426
- if (key === "default") {
21427
- continue;
21428
- }
21429
-
21430
- let exportType;
21431
-
21432
- if (typeof value === "function") {
21433
- for (const [type, baseClass] of baseClasses) {
21434
- if (baseClass.prototype.isPrototypeOf(value.prototype)) {
21435
- exportType = type;
21436
- break;
21437
- }
21438
- }
21439
-
21440
- if (!exportType) {
21441
- exportType = "DurableObject";
21442
- }
21443
- } else if (typeof value === "object" && value !== null) {
21444
- exportType = "WorkerEntrypoint";
21445
- }
21446
-
21447
- exportTypes[key] = exportType;
21448
- }
21449
-
21450
- return exportTypes;
21451
- }
21452
- `;
21453
- }
21454
- };
21455
- });
21456
- /**
21457
- * Plugin to provide a virtual fallback entry file for the `client` environment.
21458
- * This is used as the entry file for the client build when only the `public` directory is present.
21459
- */
21460
- const virtualClientFallbackPlugin = createPlugin("virtual-client-fallback", () => {
21461
- return {
21462
- applyToEnvironment(environment) {
21463
- return environment.name === "client";
21464
- },
21465
- resolveId(source) {
21466
- if (source === VIRTUAL_CLIENT_FALLBACK_ENTRY) return `\0${VIRTUAL_CLIENT_FALLBACK_ENTRY}`;
21467
- },
21468
- load(id) {
21469
- if (id === `\0${VIRTUAL_CLIENT_FALLBACK_ENTRY}`) return ``;
21470
- }
21471
- };
21472
- });
21473
-
21474
21388
  //#endregion
21475
21389
  //#region src/build.ts
21390
+ var import_picocolors$4 = /* @__PURE__ */ __toESM$1(require_picocolors(), 1);
21476
21391
  const CLIENT_FALLBACK_ENTRY_NAME = "__cloudflare_fallback_entry__";
21477
21392
  function createBuildApp(resolvedPluginConfig) {
21478
21393
  return async (builder) => {
@@ -21480,24 +21395,24 @@ function createBuildApp(resolvedPluginConfig) {
21480
21395
  assert(clientEnvironment, `No "client" environment`);
21481
21396
  const defaultHtmlPath = nodePath.resolve(builder.config.root, "index.html");
21482
21397
  const hasClientEntry = clientEnvironment.config.build.rollupOptions.input || fs$1.existsSync(defaultHtmlPath);
21483
- if (resolvedPluginConfig.type === "assets-only") {
21484
- if (hasClientEntry) await builder.build(clientEnvironment);
21485
- else if (getHasPublicAssets(builder.config)) await fallbackBuild(builder, clientEnvironment);
21486
- return;
21487
- }
21488
21398
  const workerEnvironments = [...resolvedPluginConfig.environmentNameToWorkerMap.keys()].map((environmentName) => {
21489
21399
  const environment = builder.environments[environmentName];
21490
21400
  assert(environment, `"${environmentName}" environment not found`);
21491
21401
  return environment;
21492
21402
  });
21493
21403
  await Promise.all(workerEnvironments.map((environment) => builder.build(environment)));
21404
+ if (resolvedPluginConfig.type === "assets-only") {
21405
+ if (hasClientEntry) await builder.build(clientEnvironment);
21406
+ else if (getHasPublicAssets(builder.config) || resolvedPluginConfig.prerenderWorkerEnvironmentName) await fallbackBuild(builder, clientEnvironment);
21407
+ return;
21408
+ }
21494
21409
  const { entryWorkerEnvironmentName } = resolvedPluginConfig;
21495
21410
  const entryWorkerEnvironment = builder.environments[entryWorkerEnvironmentName];
21496
21411
  assert(entryWorkerEnvironment, `No "${entryWorkerEnvironmentName}" environment`);
21497
21412
  const entryWorkerBuildDirectory = nodePath.resolve(builder.config.root, entryWorkerEnvironment.config.build.outDir);
21498
21413
  const importedAssetPaths = getImportedAssetPaths(loadViteManifest(entryWorkerBuildDirectory));
21499
21414
  if (hasClientEntry) await builder.build(clientEnvironment);
21500
- else if (importedAssetPaths.size || getHasPublicAssets(builder.config)) await fallbackBuild(builder, clientEnvironment);
21415
+ else if (importedAssetPaths.size || getHasPublicAssets(builder.config) || resolvedPluginConfig.prerenderWorkerEnvironmentName) await fallbackBuild(builder, clientEnvironment);
21501
21416
  else {
21502
21417
  if (!satisfiesViteVersion("7.0.0")) removeAssetsField(entryWorkerBuildDirectory);
21503
21418
  return;
@@ -21839,7 +21754,7 @@ const configPlugin = createPlugin("config", (ctx) => {
21839
21754
  },
21840
21755
  configResolved(resolvedViteConfig) {
21841
21756
  ctx.setResolvedViteConfig(resolvedViteConfig);
21842
- if (ctx.resolvedPluginConfig.type === "workers") validateWorkerEnvironmentOptions(ctx.resolvedPluginConfig, ctx.resolvedViteConfig);
21757
+ if (ctx.resolvedPluginConfig.type !== "preview") validateWorkerEnvironmentOptions(ctx.resolvedPluginConfig, ctx.resolvedViteConfig);
21843
21758
  },
21844
21759
  buildStart() {
21845
21760
  ctx.setHasShownWorkerConfigWarnings(false);
@@ -21879,21 +21794,22 @@ const configPlugin = createPlugin("config", (ctx) => {
21879
21794
  * Generates the environment configuration for all Worker environments.
21880
21795
  */
21881
21796
  function getEnvironmentsConfig(ctx, userConfig, mode) {
21882
- if (ctx.resolvedPluginConfig.type !== "workers") return;
21883
- const workersConfig = ctx.resolvedPluginConfig;
21797
+ assertIsNotPreview(ctx);
21798
+ if (!ctx.resolvedPluginConfig.environmentNameToWorkerMap.size) return;
21884
21799
  return {
21885
- ...Object.fromEntries([...workersConfig.environmentNameToWorkerMap].flatMap(([environmentName, worker]) => {
21886
- const childEnvironmentNames = workersConfig.environmentNameToChildEnvironmentNamesMap.get(environmentName) ?? [];
21800
+ ...Object.fromEntries([...ctx.resolvedPluginConfig.environmentNameToWorkerMap].flatMap(([environmentName, worker]) => {
21801
+ const childEnvironmentNames = ctx.resolvedPluginConfig.environmentNameToChildEnvironmentNamesMap.get(environmentName) ?? [];
21887
21802
  const sharedOptions = {
21888
21803
  workerConfig: worker.config,
21889
21804
  userConfig,
21890
21805
  mode,
21891
21806
  hasNodeJsCompat: ctx.getNodeJsCompat(environmentName) !== void 0
21892
21807
  };
21808
+ const isEntryWorker = environmentName === ctx.resolvedPluginConfig.prerenderWorkerEnvironmentName || ctx.resolvedPluginConfig.type === "workers" && environmentName === ctx.resolvedPluginConfig.entryWorkerEnvironmentName;
21893
21809
  return [[environmentName, createCloudflareEnvironmentOptions({
21894
21810
  ...sharedOptions,
21895
21811
  environmentName,
21896
- isEntryWorker: environmentName === workersConfig.entryWorkerEnvironmentName,
21812
+ isEntryWorker,
21897
21813
  isParentEnvironment: true
21898
21814
  })], ...childEnvironmentNames.map((childEnvironmentName) => [childEnvironmentName, createCloudflareEnvironmentOptions({
21899
21815
  ...sharedOptions,
@@ -22804,23 +22720,6 @@ var ImageRegistriesService = class {
22804
22720
  }
22805
22721
  };
22806
22722
 
22807
- //#endregion
22808
- //#region ../containers-shared/src/error.ts
22809
- /**
22810
- * Base class for errors where the user has done something wrong. These are not
22811
- * reported to Sentry. API errors are intentionally *not* `UserError`s, and are
22812
- * reported to Sentry. This will help us understand which API errors need better
22813
- * messaging.
22814
- */
22815
- var UserError = class extends Error {
22816
- telemetryMessage;
22817
- constructor(message, options) {
22818
- super(message, options);
22819
- Object.setPrototypeOf(this, new.target.prototype);
22820
- this.telemetryMessage = options?.telemetryMessage === true ? message : options?.telemetryMessage;
22821
- }
22822
- };
22823
-
22824
22723
  //#endregion
22825
22724
  //#region ../containers-shared/src/build.ts
22826
22725
  async function constructBuildCommand(options, logger) {
@@ -23040,29 +22939,6 @@ const verifyDockerInstalled = async (dockerPath, isDev = true) => {
23040
22939
  if (!await isDockerRunning(dockerPath)) throw new UserError(`The Docker CLI could not be launched. Please ensure that the Docker CLI is installed and the daemon is running.
23041
22940
  Other container tooling that is compatible with the Docker CLI and engine may work, but is not yet guaranteed to do so. You can specify an executable with the environment variable WRANGLER_DOCKER_BIN and a socket with DOCKER_HOST.${isDev ? "\nTo suppress this error if you do not intend on triggering any container instances, set dev.enable_containers to false in your Wrangler config or passing in --enable-containers=false." : ""}`);
23042
22941
  };
23043
- function isDir(inputPath) {
23044
- return statSync(inputPath).isDirectory();
23045
- }
23046
- /** returns true if it is a dockerfile, false if it is a registry link, throws if neither */
23047
- const isDockerfile = (image, configPath) => {
23048
- const baseDir = configPath ? path4.dirname(configPath) : process.cwd();
23049
- const maybeDockerfile = path4.resolve(baseDir, image);
23050
- if (existsSync(maybeDockerfile)) {
23051
- if (isDir(maybeDockerfile)) throw new UserError(`${image} is a directory, you should specify a path to the Dockerfile`);
23052
- return true;
23053
- }
23054
- const errorPrefix = `The image "${image}" does not appear to be a valid path to a Dockerfile, or a valid image registry path:\n`;
23055
- try {
23056
- new URL(`https://${image}`);
23057
- } catch (e) {
23058
- if (e instanceof Error) throw new UserError(errorPrefix + e.message);
23059
- throw e;
23060
- }
23061
- const imageParts = image.split("/");
23062
- if (!imageParts[imageParts.length - 1]?.includes(":")) throw new UserError(errorPrefix + `If this is an image registry path, it needs to include at least a tag ':' (e.g: docker.io/httpd:1)`);
23063
- if (image.includes("://")) throw new UserError(errorPrefix + `Image reference should not include the protocol part (e.g: docker.io/httpd:1, not https://docker.io/httpd:1)`);
23064
- return false;
23065
- };
23066
22942
  /**
23067
22943
  * Kills and removes any containers which come from the given image tag
23068
22944
  */
@@ -23316,7 +23192,7 @@ function getContainerOptions(options) {
23316
23192
  return containersConfig.map((container) => {
23317
23193
  if (isDockerfile(container.image, configPath)) return {
23318
23194
  dockerfile: container.image,
23319
- image_build_context: container.image_build_context ?? path4.dirname(container.image),
23195
+ image_build_context: container.image_build_context ?? path3.dirname(container.image),
23320
23196
  image_vars: container.image_vars,
23321
23197
  class_name: container.class_name,
23322
23198
  image_tag: getDevContainerImageName(container.class_name, containerBuildId)
@@ -26110,7 +25986,7 @@ async function getDevMiniflareOptions(ctx, viteDevServer) {
26110
25986
  inspectorPort: inputInspectorPort === false ? void 0 : inputInspectorPort,
26111
25987
  unsafeDevRegistryPath: getDefaultDevRegistryPath(),
26112
25988
  unsafeTriggerHandlers: true,
26113
- unsafeLocalExplorer: getLocalExplorerFromEnv(),
25989
+ unsafeLocalExplorer: getLocalExplorerEnabledFromEnv(),
26114
25990
  handleStructuredLogs: getStructuredLogsLogger(logger),
26115
25991
  defaultPersistRoot: getPersistenceRoot(resolvedViteConfig.root, resolvedPluginConfig.persistState),
26116
25992
  workers: [
@@ -26213,7 +26089,7 @@ async function getPreviewMiniflareOptions(ctx, vitePreviewServer) {
26213
26089
  inspectorPort: inputInspectorPort === false ? void 0 : inputInspectorPort,
26214
26090
  unsafeDevRegistryPath: getDefaultDevRegistryPath(),
26215
26091
  unsafeTriggerHandlers: true,
26216
- unsafeLocalExplorer: getLocalExplorerFromEnv(),
26092
+ unsafeLocalExplorer: getLocalExplorerEnabledFromEnv(),
26217
26093
  handleStructuredLogs: getStructuredLogsLogger(logger),
26218
26094
  defaultPersistRoot: getPersistenceRoot(resolvedViteConfig.root, resolvedPluginConfig.persistState),
26219
26095
  workers
@@ -26428,39 +26304,50 @@ const nodeJsCompatPlugin = createPlugin("nodejs-compat", (ctx) => {
26428
26304
  const nodeJsCompat = ctx.getNodeJsCompat(name);
26429
26305
  if (nodeJsCompat) return {
26430
26306
  resolve: { builtins: [...nodeJsCompat.externals] },
26431
- optimizeDeps: { exclude: [
26432
- ...nonPrefixedNodeModules,
26433
- ...nonPrefixedNodeModules.map((module$2) => `node:${module$2}`),
26434
- ...[
26435
- "node:sea",
26436
- "node:sqlite",
26437
- "node:test",
26438
- "node:test/reporters"
26439
- ]
26440
- ] }
26307
+ ...isRolldown ? { build: { rolldownOptions: { plugins: [vite.esmExternalRequirePlugin({
26308
+ external: [...nodeJsCompat.externals],
26309
+ skipDuplicateCheck: true
26310
+ })] } } } : {},
26311
+ optimizeDeps: {
26312
+ exclude: [
26313
+ ...nonPrefixedNodeModules,
26314
+ ...nonPrefixedNodeModules.map((module$2) => `node:${module$2}`),
26315
+ ...[
26316
+ "node:sea",
26317
+ "node:sqlite",
26318
+ "node:test",
26319
+ "node:test/reporters"
26320
+ ]
26321
+ ],
26322
+ ...isRolldown ? { rolldownOptions: { plugins: [vite.esmExternalRequirePlugin({
26323
+ external: [nodeBuiltinsRE],
26324
+ skipDuplicateCheck: true
26325
+ })] } } : {}
26326
+ }
26441
26327
  };
26442
26328
  },
26443
26329
  applyToEnvironment(environment) {
26444
26330
  return ctx.getNodeJsCompat(environment.name) !== void 0;
26445
26331
  },
26446
26332
  enforce: "pre",
26447
- async resolveId(source, importer, options) {
26448
- const nodeJsCompat = ctx.getNodeJsCompat(this.environment.name);
26449
- assertHasNodeJsCompat(nodeJsCompat);
26450
- if (nodeJsCompat.isGlobalVirtualModule(source)) return source;
26451
- const result = nodeJsCompat.resolveNodeJsImport(source);
26452
- if (!result) return this.resolve(source, importer, options);
26453
- if (this.environment.mode === "dev") {
26454
- assert(this.environment.depsOptimizer, "depsOptimizer is required in dev mode");
26455
- const { id } = this.environment.depsOptimizer.registerMissingImport(result.unresolved, result.resolved);
26456
- return this.resolve(id, importer, options);
26457
- }
26458
- return this.resolve(result.resolved, importer, options);
26459
- },
26460
- load(id) {
26461
- const nodeJsCompat = ctx.getNodeJsCompat(this.environment.name);
26462
- assertHasNodeJsCompat(nodeJsCompat);
26463
- return nodeJsCompat.getGlobalVirtualModule(id);
26333
+ resolveId: {
26334
+ filter: { id: [
26335
+ nodeBuiltinsRE,
26336
+ /^unenv\//,
26337
+ /^@cloudflare\/unenv-preset\//
26338
+ ] },
26339
+ async handler(source, importer, options) {
26340
+ const nodeJsCompat = ctx.getNodeJsCompat(this.environment.name);
26341
+ assertHasNodeJsCompat(nodeJsCompat);
26342
+ const result = nodeJsCompat.resolveNodeJsImport(source);
26343
+ if (!result) return;
26344
+ if (this.environment.mode === "dev") {
26345
+ assert(this.environment.depsOptimizer, "depsOptimizer is required in dev mode");
26346
+ const { id } = this.environment.depsOptimizer.registerMissingImport(result.unresolved, result.resolved);
26347
+ return this.resolve(id, importer, options);
26348
+ }
26349
+ return this.resolve(result.resolved, importer, options);
26350
+ }
26464
26351
  },
26465
26352
  async configureServer(viteDevServer) {
26466
26353
  await Promise.all(Object.values(viteDevServer.environments).flatMap(async (environment) => {
@@ -26489,18 +26376,16 @@ const nodeJsCompatWarningsPlugin = createPlugin("nodejs-compat-warnings", (ctx)
26489
26376
  for (const nodeJsCompatWarnings of nodeJsCompatWarningsMap.values()) nodeJsCompatWarnings.renderWarnings();
26490
26377
  };
26491
26378
  function resolveId(environmentName, source, importer) {
26379
+ if (!nodeBuiltinsRE.test(source)) return;
26492
26380
  const workerConfig = ctx.getWorkerConfig(environmentName);
26493
26381
  const nodeJsCompat = ctx.getNodeJsCompat(environmentName);
26494
26382
  if (workerConfig && !nodeJsCompat) {
26495
26383
  if (hasNodeJsAls(workerConfig) && isNodeAlsModule(source)) return;
26496
- const nodeJsCompatWarnings = nodeJsCompatWarningsMap.get(workerConfig);
26497
- if (source.startsWith("node:") || nonPrefixedNodeModules.includes(source)) {
26498
- nodeJsCompatWarnings?.registerImport(source, importer);
26499
- return {
26500
- id: source,
26501
- external: true
26502
- };
26503
- }
26384
+ nodeJsCompatWarningsMap.get(workerConfig)?.registerImport(source, importer);
26385
+ return {
26386
+ id: source,
26387
+ external: true
26388
+ };
26504
26389
  }
26505
26390
  }
26506
26391
  return {
@@ -26510,13 +26395,16 @@ const nodeJsCompatWarningsPlugin = createPlugin("nodejs-compat-warnings", (ctx)
26510
26395
  const nodeJsCompat = ctx.getNodeJsCompat(environmentName);
26511
26396
  if (workerConfig && !nodeJsCompat) return { optimizeDeps: { ...isRolldown ? { rolldownOptions: { plugins: [{
26512
26397
  name: "vite-plugin-cloudflare:nodejs-compat-warnings-resolver",
26513
- resolveId(source, importer) {
26514
- return resolveId(environmentName, source, importer);
26398
+ resolveId: {
26399
+ filter: { id: nodeBuiltinsRE },
26400
+ handler(source, importer) {
26401
+ return resolveId(environmentName, source, importer);
26402
+ }
26515
26403
  }
26516
26404
  }] } } : { esbuildOptions: { plugins: [{
26517
26405
  name: "vite-plugin-cloudflare:nodejs-compat-warnings-resolver",
26518
26406
  setup(build$8) {
26519
- build$8.onResolve({ filter: /* @__PURE__ */ new RegExp(`^(${nonPrefixedNodeModules.join("|")}|node:.+)$`) }, ({ path: path$1, importer }) => {
26407
+ build$8.onResolve({ filter: nodeBuiltinsRE }, ({ path: path$1, importer }) => {
26520
26408
  if (hasNodeJsAls(workerConfig) && isNodeAlsModule(path$1)) return;
26521
26409
  nodeJsCompatWarningsMap.get(workerConfig)?.registerImport(path$1, importer);
26522
26410
  return {
@@ -26537,8 +26425,11 @@ const nodeJsCompatWarningsPlugin = createPlugin("nodejs-compat-warnings", (ctx)
26537
26425
  applyToEnvironment(environment) {
26538
26426
  return ctx.getWorkerConfig(environment.name) !== void 0 && !ctx.getNodeJsCompat(environment.name);
26539
26427
  },
26540
- async resolveId(source, importer) {
26541
- return resolveId(this.environment.name, source, importer);
26428
+ resolveId: {
26429
+ filter: { id: nodeBuiltinsRE },
26430
+ handler(source, importer) {
26431
+ return resolveId(this.environment.name, source, importer);
26432
+ }
26542
26433
  }
26543
26434
  };
26544
26435
  });
@@ -26554,27 +26445,27 @@ const outputConfigPlugin = createPlugin("output-config", (ctx) => {
26554
26445
  assertIsNotPreview(ctx);
26555
26446
  if (ctx.isChildEnvironment(this.environment.name)) return;
26556
26447
  let outputConfig;
26557
- if (ctx.resolvedPluginConfig.type === "workers") {
26558
- const inputConfig = ctx.getWorkerConfig(this.environment.name);
26559
- if (!inputConfig) return;
26448
+ const inputWorkerConfig = ctx.getWorkerConfig(this.environment.name);
26449
+ if (inputWorkerConfig) {
26560
26450
  const entryChunk = Object.values(bundle).find((chunk) => chunk.type === "chunk" && chunk.isEntry && chunk.name === MAIN_ENTRY_NAME);
26561
26451
  assert(entryChunk, `Expected entry chunk with name "${MAIN_ENTRY_NAME}"`);
26562
- const isEntryWorker = this.environment.name === ctx.resolvedPluginConfig.entryWorkerEnvironmentName;
26452
+ const isPrerenderWorker = this.environment.name === ctx.resolvedPluginConfig.prerenderWorkerEnvironmentName;
26453
+ const isEntryWorker = ctx.resolvedPluginConfig.type === "workers" && this.environment.name === ctx.resolvedPluginConfig.entryWorkerEnvironmentName;
26563
26454
  outputConfig = {
26564
- ...inputConfig,
26455
+ ...inputWorkerConfig,
26565
26456
  main: entryChunk.fileName,
26566
26457
  no_bundle: true,
26567
26458
  rules: [{
26568
26459
  type: "ESModule",
26569
26460
  globs: ["**/*.js", "**/*.mjs"]
26570
26461
  }],
26571
- assets: isEntryWorker ? {
26572
- ...inputConfig.assets,
26462
+ assets: isEntryWorker || isPrerenderWorker ? {
26463
+ ...inputWorkerConfig.assets,
26573
26464
  directory: getAssetsDirectory(this.environment.config.build.outDir, ctx.resolvedViteConfig)
26574
26465
  } : void 0
26575
26466
  };
26576
- if (inputConfig.configPath) {
26577
- const localDevVars = getLocalDevVarsForPreview(inputConfig.configPath, ctx.resolvedPluginConfig.cloudflareEnv);
26467
+ if (inputWorkerConfig.configPath) {
26468
+ const localDevVars = getLocalDevVarsForPreview(inputWorkerConfig.configPath, ctx.resolvedPluginConfig.cloudflareEnv);
26578
26469
  if (localDevVars) this.emitFile({
26579
26470
  type: "asset",
26580
26471
  fileName: ".dev.vars",
@@ -26582,19 +26473,21 @@ const outputConfigPlugin = createPlugin("output-config", (ctx) => {
26582
26473
  });
26583
26474
  }
26584
26475
  } else if (this.environment.name === "client") {
26585
- const inputConfig = ctx.resolvedPluginConfig.config;
26586
- outputConfig = {
26587
- ...inputConfig,
26588
- assets: {
26589
- ...inputConfig.assets,
26590
- directory: "."
26591
- }
26592
- };
26593
26476
  this.emitFile({
26594
26477
  type: "asset",
26595
26478
  fileName: ".assetsignore",
26596
26479
  source: `${["wrangler.json", ".dev.vars"].join("\n")}\n`
26597
26480
  });
26481
+ if (ctx.resolvedPluginConfig.type === "assets-only") {
26482
+ const inputAssetsOnlyConfig = ctx.resolvedPluginConfig.config;
26483
+ outputConfig = {
26484
+ ...inputAssetsOnlyConfig,
26485
+ assets: {
26486
+ ...inputAssetsOnlyConfig.assets,
26487
+ directory: "."
26488
+ }
26489
+ };
26490
+ }
26598
26491
  }
26599
26492
  if (!outputConfig) return;
26600
26493
  if (outputConfig.unsafe && Object.keys(outputConfig.unsafe).length === 0) outputConfig.unsafe = void 0;
@@ -26742,6 +26635,7 @@ const triggerHandlersPlugin = createPlugin("trigger-handlers", (ctx) => {
26742
26635
 
26743
26636
  //#endregion
26744
26637
  //#region src/plugins/wasm.ts
26638
+ const wasmInitRE = /\.wasm\?init$/;
26745
26639
  /**
26746
26640
  * Plugin to support the `.wasm?init` extension
26747
26641
  */
@@ -26751,14 +26645,17 @@ const wasmHelperPlugin = createPlugin("wasm-helper", (ctx) => {
26751
26645
  applyToEnvironment(environment) {
26752
26646
  return ctx.getWorkerConfig(environment.name) !== void 0;
26753
26647
  },
26754
- load(id) {
26755
- if (!id.endsWith(".wasm?init")) return;
26756
- return `
26648
+ load: {
26649
+ filter: { id: wasmInitRE },
26650
+ handler(id) {
26651
+ if (!wasmInitRE.test(id)) return;
26652
+ return `
26757
26653
  import wasm from "${cleanUrl(id)}";
26758
26654
  export default function(opts = {}) {
26759
26655
  return WebAssembly.instantiate(wasm, opts);
26760
26656
  }
26761
26657
  `;
26658
+ }
26762
26659
  }
26763
26660
  };
26764
26661
  });
@@ -26785,6 +26682,7 @@ function cloudflare(pluginConfig = {}) {
26785
26682
  sharedDuringBuild: true,
26786
26683
  config(userConfig, env$1) {
26787
26684
  ctx.setResolvedPluginConfig(resolvePluginConfig(pluginConfig, userConfig, env$1));
26685
+ if (env$1.command === "build") process.env.CLOUDFLARE_VITE_BUILD = "true";
26788
26686
  },
26789
26687
  async configureServer(viteDevServer) {
26790
26688
  const restartServer = viteDevServer.restart.bind(viteDevServer);