@cloudflare/vite-plugin 1.5.1 → 1.6.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.
Files changed (2) hide show
  1. package/dist/index.js +365 -233
  2. package/package.json +6 -6
package/dist/index.js CHANGED
@@ -248,17 +248,17 @@ var require_ignore = __commonJS({
248
248
  var throwError = (message, Ctor) => {
249
249
  throw new Ctor(message);
250
250
  };
251
- var checkPath = (path10, originalPath, doThrow) => {
252
- if (!isString(path10)) {
251
+ var checkPath = (path11, originalPath, doThrow) => {
252
+ if (!isString(path11)) {
253
253
  return doThrow(
254
254
  `path must be a string, but got \`${originalPath}\``,
255
255
  TypeError
256
256
  );
257
257
  }
258
- if (!path10) {
258
+ if (!path11) {
259
259
  return doThrow(`path must not be empty`, TypeError);
260
260
  }
261
- if (checkPath.isNotRelative(path10)) {
261
+ if (checkPath.isNotRelative(path11)) {
262
262
  const r2 = "`path.relative()`d";
263
263
  return doThrow(
264
264
  `path should be a ${r2} string, but got "${originalPath}"`,
@@ -267,7 +267,7 @@ var require_ignore = __commonJS({
267
267
  }
268
268
  return true;
269
269
  };
270
- var isNotRelative = (path10) => REGEX_TEST_INVALID_PATH.test(path10);
270
+ var isNotRelative = (path11) => REGEX_TEST_INVALID_PATH.test(path11);
271
271
  checkPath.isNotRelative = isNotRelative;
272
272
  checkPath.convert = (p) => p;
273
273
  var Ignore = class {
@@ -326,7 +326,7 @@ var require_ignore = __commonJS({
326
326
  // setting `checkUnignored` to `false` could reduce additional
327
327
  // path matching.
328
328
  // @returns {TestResult} true if a file is ignored
329
- _testOne(path10, checkUnignored) {
329
+ _testOne(path11, checkUnignored) {
330
330
  let ignored = false;
331
331
  let unignored = false;
332
332
  this._rules.forEach((rule) => {
@@ -334,7 +334,7 @@ var require_ignore = __commonJS({
334
334
  if (unignored === negative && ignored !== unignored || negative && !ignored && !unignored && !checkUnignored) {
335
335
  return;
336
336
  }
337
- const matched = rule.regex.test(path10);
337
+ const matched = rule.regex.test(path11);
338
338
  if (matched) {
339
339
  ignored = !negative;
340
340
  unignored = negative;
@@ -347,24 +347,24 @@ var require_ignore = __commonJS({
347
347
  }
348
348
  // @returns {TestResult}
349
349
  _test(originalPath, cache2, checkUnignored, slices) {
350
- const path10 = originalPath && checkPath.convert(originalPath);
350
+ const path11 = originalPath && checkPath.convert(originalPath);
351
351
  checkPath(
352
- path10,
352
+ path11,
353
353
  originalPath,
354
354
  this._allowRelativePaths ? RETURN_FALSE : throwError
355
355
  );
356
- return this._t(path10, cache2, checkUnignored, slices);
356
+ return this._t(path11, cache2, checkUnignored, slices);
357
357
  }
358
- _t(path10, cache2, checkUnignored, slices) {
359
- if (path10 in cache2) {
360
- return cache2[path10];
358
+ _t(path11, cache2, checkUnignored, slices) {
359
+ if (path11 in cache2) {
360
+ return cache2[path11];
361
361
  }
362
362
  if (!slices) {
363
- slices = path10.split(SLASH);
363
+ slices = path11.split(SLASH);
364
364
  }
365
365
  slices.pop();
366
366
  if (!slices.length) {
367
- return cache2[path10] = this._testOne(path10, checkUnignored);
367
+ return cache2[path11] = this._testOne(path11, checkUnignored);
368
368
  }
369
369
  const parent = this._t(
370
370
  slices.join(SLASH) + SLASH,
@@ -372,24 +372,24 @@ var require_ignore = __commonJS({
372
372
  checkUnignored,
373
373
  slices
374
374
  );
375
- return cache2[path10] = parent.ignored ? parent : this._testOne(path10, checkUnignored);
375
+ return cache2[path11] = parent.ignored ? parent : this._testOne(path11, checkUnignored);
376
376
  }
377
- ignores(path10) {
378
- return this._test(path10, this._ignoreCache, false).ignored;
377
+ ignores(path11) {
378
+ return this._test(path11, this._ignoreCache, false).ignored;
379
379
  }
380
380
  createFilter() {
381
- return (path10) => !this.ignores(path10);
381
+ return (path11) => !this.ignores(path11);
382
382
  }
383
383
  filter(paths) {
384
384
  return makeArray(paths).filter(this.createFilter());
385
385
  }
386
386
  // @returns {TestResult}
387
- test(path10) {
388
- return this._test(path10, this._testCache, true);
387
+ test(path11) {
388
+ return this._test(path11, this._testCache, true);
389
389
  }
390
390
  };
391
391
  var factory = (options) => new Ignore(options);
392
- var isPathValid = (path10) => checkPath(path10 && checkPath.convert(path10), path10, RETURN_FALSE);
392
+ var isPathValid = (path11) => checkPath(path11 && checkPath.convert(path11), path11, RETURN_FALSE);
393
393
  factory.isPathValid = isPathValid;
394
394
  factory.default = factory;
395
395
  module.exports = factory;
@@ -400,7 +400,7 @@ var require_ignore = __commonJS({
400
400
  const makePosix = (str) => /^\\\\\?\\/.test(str) || /["<>|\u0000-\u001F]+/u.test(str) ? str : str.replace(/\\/g, "/");
401
401
  checkPath.convert = makePosix;
402
402
  const REGIX_IS_WINDOWS_PATH_ABSOLUTE = /^[a-z]:\//i;
403
- checkPath.isNotRelative = (path10) => REGIX_IS_WINDOWS_PATH_ABSOLUTE.test(path10) || isNotRelative(path10);
403
+ checkPath.isNotRelative = (path11) => REGIX_IS_WINDOWS_PATH_ABSOLUTE.test(path11) || isNotRelative(path11);
404
404
  }
405
405
  }
406
406
  });
@@ -443,11 +443,11 @@ var require_Mime = __commonJS({
443
443
  }
444
444
  }
445
445
  };
446
- Mime.prototype.getType = function(path10) {
447
- path10 = String(path10);
448
- let last = path10.replace(/^.*[/\\]/, "").toLowerCase();
446
+ Mime.prototype.getType = function(path11) {
447
+ path11 = String(path11);
448
+ let last = path11.replace(/^.*[/\\]/, "").toLowerCase();
449
449
  let ext = last.replace(/^.*\./, "").toLowerCase();
450
- let hasPath = last.length < path10.length;
450
+ let hasPath = last.length < path11.length;
451
451
  let hasDot = ext.length < last.length - 1;
452
452
  return (hasDot || !hasPath) && this._types[ext] || null;
453
453
  };
@@ -485,10 +485,10 @@ var require_mime = __commonJS({
485
485
  });
486
486
 
487
487
  // src/index.ts
488
- import assert10 from "node:assert";
489
- import * as fs5 from "node:fs";
488
+ import assert11 from "node:assert";
489
+ import * as fs6 from "node:fs";
490
490
  import * as fsp2 from "node:fs/promises";
491
- import * as path9 from "node:path";
491
+ import * as path10 from "node:path";
492
492
  import { createRequest, sendResponse } from "@mjackson/node-fetch-server";
493
493
  import replace from "@rollup/plugin-replace";
494
494
 
@@ -503,8 +503,8 @@ for (let i = 0; i < chars.length; i++) {
503
503
  intToChar[i] = c;
504
504
  charToInt[c] = i;
505
505
  }
506
- function encodeInteger(builder, num, relative6) {
507
- let delta = num - relative6;
506
+ function encodeInteger(builder, num, relative7) {
507
+ let delta = num - relative7;
508
508
  delta = delta < 0 ? -delta << 1 | 1 : delta << 1;
509
509
  do {
510
510
  let clamped = delta & 31;
@@ -1558,7 +1558,7 @@ var MagicString = class _MagicString {
1558
1558
 
1559
1559
  // src/index.ts
1560
1560
  import { Miniflare } from "miniflare";
1561
- import colors3 from "picocolors";
1561
+ import colors4 from "picocolors";
1562
1562
  import * as vite7 from "vite";
1563
1563
 
1564
1564
  // src/constants.ts
@@ -1728,11 +1728,11 @@ ${invalidHeaderRulesList}`
1728
1728
  }
1729
1729
 
1730
1730
  // ../workers-shared/utils/configuration/validateURL.ts
1731
- var extractPathname = (path10 = "/", includeSearch, includeHash) => {
1732
- if (!path10.startsWith("/")) {
1733
- path10 = `/${path10}`;
1731
+ var extractPathname = (path11 = "/", includeSearch, includeHash) => {
1732
+ if (!path11.startsWith("/")) {
1733
+ path11 = `/${path11}`;
1734
1734
  }
1735
- const url = new URL(`//${path10}`, "relative://");
1735
+ const url = new URL(`//${path11}`, "relative://");
1736
1736
  return `${url.pathname}${includeSearch ? url.search : ""}${includeHash ? url.hash : ""}`;
1737
1737
  };
1738
1738
  var URL_REGEX = /^https:\/\/+(?<host>[^/]+)\/?(?<path>.*)/;
@@ -1765,8 +1765,8 @@ var validateUrl = (token, onlyRelative = false, disallowPorts = false, includeSe
1765
1765
  if (!token.startsWith("/") && onlyRelative) {
1766
1766
  token = `/${token}`;
1767
1767
  }
1768
- const path10 = PATH_REGEX.exec(token);
1769
- if (path10) {
1768
+ const path11 = PATH_REGEX.exec(token);
1769
+ if (path11) {
1770
1770
  try {
1771
1771
  return [extractPathname(token, includeSearch, includeHash), void 0];
1772
1772
  } catch {
@@ -1827,7 +1827,7 @@ function parseHeaders(input, {
1827
1827
  });
1828
1828
  }
1829
1829
  }
1830
- const [path10, pathError] = validateUrl(line, false, true);
1830
+ const [path11, pathError] = validateUrl(line, false, true);
1831
1831
  if (pathError) {
1832
1832
  invalid.push({
1833
1833
  line,
@@ -1838,7 +1838,7 @@ function parseHeaders(input, {
1838
1838
  continue;
1839
1839
  }
1840
1840
  rule = {
1841
- path: path10,
1841
+ path: path11,
1842
1842
  line,
1843
1843
  headers: {},
1844
1844
  unsetHeaders: []
@@ -2413,8 +2413,8 @@ function getErrorMap() {
2413
2413
  return overrideErrorMap;
2414
2414
  }
2415
2415
  var makeIssue = (params) => {
2416
- const { data: data2, path: path10, errorMaps, issueData } = params;
2417
- const fullPath = [...path10, ...issueData.path || []];
2416
+ const { data: data2, path: path11, errorMaps, issueData } = params;
2417
+ const fullPath = [...path11, ...issueData.path || []];
2418
2418
  const fullIssue = {
2419
2419
  ...issueData,
2420
2420
  path: fullPath
@@ -2513,11 +2513,11 @@ var errorUtil;
2513
2513
  errorUtil2.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
2514
2514
  })(errorUtil || (errorUtil = {}));
2515
2515
  var ParseInputLazyPath = class {
2516
- constructor(parent, value, path10, key) {
2516
+ constructor(parent, value, path11, key) {
2517
2517
  this._cachedPath = [];
2518
2518
  this.parent = parent;
2519
2519
  this.data = value;
2520
- this._path = path10;
2520
+ this._path = path11;
2521
2521
  this._key = key;
2522
2522
  }
2523
2523
  get path() {
@@ -5912,14 +5912,147 @@ function getHeadersConfigPath(config) {
5912
5912
  return path.join(config.publicDir, HEADERS_FILENAME);
5913
5913
  }
5914
5914
 
5915
+ // src/build.ts
5916
+ import assert from "node:assert";
5917
+ import * as fs from "node:fs";
5918
+ import * as path2 from "node:path";
5919
+ import colors from "picocolors";
5920
+ function createBuildApp(resolvedPluginConfig) {
5921
+ return async (builder) => {
5922
+ const clientEnvironment = builder.environments.client;
5923
+ assert(clientEnvironment, `No "client" environment`);
5924
+ const defaultHtmlPath = path2.resolve(builder.config.root, "index.html");
5925
+ const hasClientEntry = clientEnvironment.config.build.rollupOptions.input || fs.existsSync(defaultHtmlPath);
5926
+ if (resolvedPluginConfig.type === "assets-only") {
5927
+ if (hasClientEntry) {
5928
+ await builder.build(clientEnvironment);
5929
+ } else if (getHasPublicAssets(builder.config)) {
5930
+ await fallbackBuild(builder, clientEnvironment);
5931
+ }
5932
+ return;
5933
+ }
5934
+ const workerEnvironments = Object.keys(resolvedPluginConfig.workers).map(
5935
+ (environmentName) => {
5936
+ const environment = builder.environments[environmentName];
5937
+ assert(environment, `"${environmentName}" environment not found`);
5938
+ return environment;
5939
+ }
5940
+ );
5941
+ await Promise.all(
5942
+ workerEnvironments.map((environment) => builder.build(environment))
5943
+ );
5944
+ const { entryWorkerEnvironmentName } = resolvedPluginConfig;
5945
+ const entryWorkerEnvironment = builder.environments[entryWorkerEnvironmentName];
5946
+ assert(
5947
+ entryWorkerEnvironment,
5948
+ `No "${entryWorkerEnvironmentName}" environment`
5949
+ );
5950
+ const entryWorkerBuildDirectory = path2.resolve(
5951
+ builder.config.root,
5952
+ entryWorkerEnvironment.config.build.outDir
5953
+ );
5954
+ const entryWorkerManifest = loadViteManifest(entryWorkerBuildDirectory);
5955
+ const importedAssetPaths = getImportedAssetPaths(entryWorkerManifest);
5956
+ if (hasClientEntry) {
5957
+ await builder.build(clientEnvironment);
5958
+ } else if (importedAssetPaths.size || getHasPublicAssets(builder.config)) {
5959
+ await fallbackBuild(builder, clientEnvironment);
5960
+ } else {
5961
+ const entryWorkerConfigPath = path2.join(
5962
+ entryWorkerBuildDirectory,
5963
+ "wrangler.json"
5964
+ );
5965
+ const workerConfig = JSON.parse(
5966
+ fs.readFileSync(entryWorkerConfigPath, "utf-8")
5967
+ );
5968
+ workerConfig.assets = void 0;
5969
+ fs.writeFileSync(entryWorkerConfigPath, JSON.stringify(workerConfig));
5970
+ return;
5971
+ }
5972
+ const clientBuildDirectory = path2.resolve(
5973
+ builder.config.root,
5974
+ clientEnvironment.config.build.outDir
5975
+ );
5976
+ const movedAssetPaths = [];
5977
+ for (const assetPath of importedAssetPaths) {
5978
+ const src = path2.join(entryWorkerBuildDirectory, assetPath);
5979
+ const dest = path2.join(clientBuildDirectory, assetPath);
5980
+ if (!fs.existsSync(src)) {
5981
+ continue;
5982
+ }
5983
+ if (fs.existsSync(dest)) {
5984
+ fs.unlinkSync(src);
5985
+ } else {
5986
+ const destDir = path2.dirname(dest);
5987
+ fs.mkdirSync(destDir, { recursive: true });
5988
+ fs.renameSync(src, dest);
5989
+ movedAssetPaths.push(dest);
5990
+ }
5991
+ }
5992
+ if (movedAssetPaths.length) {
5993
+ builder.config.logger.info(
5994
+ [
5995
+ `${colors.green("\u2713")} ${movedAssetPaths.length} asset${movedAssetPaths.length > 1 ? "s" : ""} moved from "${entryWorkerEnvironmentName}" to "client" build output.`,
5996
+ ...movedAssetPaths.map(
5997
+ (assetPath) => colors.dim(path2.relative(builder.config.root, assetPath))
5998
+ )
5999
+ ].join("\n")
6000
+ );
6001
+ }
6002
+ };
6003
+ }
6004
+ function getHasPublicAssets({ publicDir }) {
6005
+ let hasPublicAssets = false;
6006
+ if (publicDir) {
6007
+ try {
6008
+ const files = fs.readdirSync(publicDir);
6009
+ if (files.length) {
6010
+ hasPublicAssets = true;
6011
+ }
6012
+ } catch (error) {
6013
+ }
6014
+ }
6015
+ return hasPublicAssets;
6016
+ }
6017
+ async function fallbackBuild(builder, environment) {
6018
+ const fallbackEntryName = "__cloudflare_fallback_entry__";
6019
+ environment.config.build.rollupOptions = {
6020
+ input: "virtual:__cloudflare_fallback_entry__",
6021
+ logLevel: "silent",
6022
+ output: {
6023
+ entryFileNames: fallbackEntryName
6024
+ }
6025
+ };
6026
+ await builder.build(environment);
6027
+ const fallbackEntryPath = path2.resolve(
6028
+ builder.config.root,
6029
+ environment.config.build.outDir,
6030
+ fallbackEntryName
6031
+ );
6032
+ fs.unlinkSync(fallbackEntryPath);
6033
+ }
6034
+ function loadViteManifest(directory) {
6035
+ const contents = fs.readFileSync(
6036
+ path2.resolve(directory, ".vite", "manifest.json"),
6037
+ "utf-8"
6038
+ );
6039
+ return JSON.parse(contents);
6040
+ }
6041
+ function getImportedAssetPaths(viteManifest) {
6042
+ const assetPaths = Object.values(viteManifest).flatMap(
6043
+ (chunk) => chunk.assets ?? []
6044
+ );
6045
+ return new Set(assetPaths);
6046
+ }
6047
+
5915
6048
  // src/cloudflare-environment.ts
5916
- import assert3 from "node:assert";
6049
+ import assert4 from "node:assert";
5917
6050
  import * as vite3 from "vite";
5918
6051
 
5919
6052
  // src/node-js-compat.ts
5920
- import assert2 from "node:assert";
6053
+ import assert3 from "node:assert";
5921
6054
  import { builtinModules as builtinModules2 } from "node:module";
5922
- import path3 from "node:path";
6055
+ import path4 from "node:path";
5923
6056
  import { cloudflare } from "@cloudflare/unenv-preset";
5924
6057
  import { getNodeCompat } from "miniflare";
5925
6058
 
@@ -11452,7 +11585,7 @@ Parser.acorn = {
11452
11585
 
11453
11586
  // ../../node_modules/.pnpm/mlly@1.7.4/node_modules/mlly/dist/index.mjs
11454
11587
  import { builtinModules, createRequire } from "node:module";
11455
- import fs, { realpathSync, statSync, promises } from "node:fs";
11588
+ import fs2, { realpathSync, statSync, promises } from "node:fs";
11456
11589
 
11457
11590
  // ../../node_modules/.pnpm/ufo@1.5.4/node_modules/ufo/dist/index.mjs
11458
11591
  var r = String.fromCharCode;
@@ -11471,17 +11604,17 @@ function withTrailingSlash(input = "", respectQueryAndFragment) {
11471
11604
  if (hasTrailingSlash(input, true)) {
11472
11605
  return input || "/";
11473
11606
  }
11474
- let path10 = input;
11607
+ let path11 = input;
11475
11608
  let fragment = "";
11476
11609
  const fragmentIndex = input.indexOf("#");
11477
11610
  if (fragmentIndex >= 0) {
11478
- path10 = input.slice(0, fragmentIndex);
11611
+ path11 = input.slice(0, fragmentIndex);
11479
11612
  fragment = input.slice(fragmentIndex);
11480
- if (!path10) {
11613
+ if (!path11) {
11481
11614
  return fragment;
11482
11615
  }
11483
11616
  }
11484
- const [s0, ...s] = path10.split("?");
11617
+ const [s0, ...s] = path11.split("?");
11485
11618
  return s0 + "/" + (s.length > 0 ? `?${s.join("?")}` : "") + fragment;
11486
11619
  }
11487
11620
  function isNonEmptyURL(url) {
@@ -11509,14 +11642,14 @@ var isAbsolute = function(p) {
11509
11642
 
11510
11643
  // ../../node_modules/.pnpm/mlly@1.7.4/node_modules/mlly/dist/index.mjs
11511
11644
  import { fileURLToPath as fileURLToPath$1, URL as URL$1, pathToFileURL as pathToFileURL$1 } from "node:url";
11512
- import assert from "node:assert";
11645
+ import assert2 from "node:assert";
11513
11646
  import process$1 from "node:process";
11514
- import path2, { dirname as dirname2 } from "node:path";
11647
+ import path3, { dirname as dirname3 } from "node:path";
11515
11648
  import v8 from "node:v8";
11516
11649
  import { format as format2, inspect } from "node:util";
11517
11650
  var BUILTIN_MODULES = new Set(builtinModules);
11518
- function normalizeSlash(path10) {
11519
- return path10.replace(/\\/g, "/");
11651
+ function normalizeSlash(path11) {
11652
+ return path11.replace(/\\/g, "/");
11520
11653
  }
11521
11654
  var own$1 = {}.hasOwnProperty;
11522
11655
  var classRegExp = /^([A-Z][a-z\d]*)+$/;
@@ -11547,7 +11680,7 @@ codes.ERR_INVALID_ARG_TYPE = createError(
11547
11680
  * @param {unknown} actual
11548
11681
  */
11549
11682
  (name, expected, actual) => {
11550
- assert(typeof name === "string", "'name' must be a string");
11683
+ assert2(typeof name === "string", "'name' must be a string");
11551
11684
  if (!Array.isArray(expected)) {
11552
11685
  expected = [expected];
11553
11686
  }
@@ -11563,14 +11696,14 @@ codes.ERR_INVALID_ARG_TYPE = createError(
11563
11696
  const instances = [];
11564
11697
  const other = [];
11565
11698
  for (const value of expected) {
11566
- assert(
11699
+ assert2(
11567
11700
  typeof value === "string",
11568
11701
  "All expected entries have to be of type string"
11569
11702
  );
11570
11703
  if (kTypes.has(value)) {
11571
11704
  types2.push(value.toLowerCase());
11572
11705
  } else if (classRegExp.exec(value) === null) {
11573
- assert(
11706
+ assert2(
11574
11707
  value !== "object",
11575
11708
  'The value "object" should be written as "Object"'
11576
11709
  );
@@ -11629,8 +11762,8 @@ codes.ERR_INVALID_PACKAGE_CONFIG = createError(
11629
11762
  * @param {string} [base]
11630
11763
  * @param {string} [message]
11631
11764
  */
11632
- (path10, base, message) => {
11633
- return `Invalid package config ${path10}${base ? ` while importing ${base}` : ""}${message ? `. ${message}` : ""}`;
11765
+ (path11, base, message) => {
11766
+ return `Invalid package config ${path11}${base ? ` while importing ${base}` : ""}${message ? `. ${message}` : ""}`;
11634
11767
  },
11635
11768
  Error
11636
11769
  );
@@ -11646,7 +11779,7 @@ codes.ERR_INVALID_PACKAGE_TARGET = createError(
11646
11779
  (packagePath, key, target2, isImport = false, base = void 0) => {
11647
11780
  const relatedError = typeof target2 === "string" && !isImport && target2.length > 0 && !target2.startsWith("./");
11648
11781
  if (key === ".") {
11649
- assert(isImport === false);
11782
+ assert2(isImport === false);
11650
11783
  return `Invalid "exports" main target ${JSON.stringify(target2)} defined in the package config ${packagePath}package.json${base ? ` imported from ${base}` : ""}${relatedError ? '; targets must start with "./"' : ""}`;
11651
11784
  }
11652
11785
  return `Invalid "${isImport ? "imports" : "exports"}" target ${JSON.stringify(
@@ -11662,8 +11795,8 @@ codes.ERR_MODULE_NOT_FOUND = createError(
11662
11795
  * @param {string} base
11663
11796
  * @param {boolean} [exactUrl]
11664
11797
  */
11665
- (path10, base, exactUrl = false) => {
11666
- return `Cannot find ${exactUrl ? "module" : "package"} '${path10}' imported from ${base}`;
11798
+ (path11, base, exactUrl = false) => {
11799
+ return `Cannot find ${exactUrl ? "module" : "package"} '${path11}' imported from ${base}`;
11667
11800
  },
11668
11801
  Error
11669
11802
  );
@@ -11714,8 +11847,8 @@ codes.ERR_UNKNOWN_FILE_EXTENSION = createError(
11714
11847
  * @param {string} extension
11715
11848
  * @param {string} path
11716
11849
  */
11717
- (extension, path10) => {
11718
- return `Unknown file extension "${extension}" for ${path10}`;
11850
+ (extension, path11) => {
11851
+ return `Unknown file extension "${extension}" for ${path11}`;
11719
11852
  },
11720
11853
  TypeError
11721
11854
  );
@@ -11811,9 +11944,9 @@ var captureLargerStackTrace = hideStackFrames(
11811
11944
  );
11812
11945
  function getMessage(key, parameters, self) {
11813
11946
  const message = messages.get(key);
11814
- assert(message !== void 0, "expected `message` to be found");
11947
+ assert2(message !== void 0, "expected `message` to be found");
11815
11948
  if (typeof message === "function") {
11816
- assert(
11949
+ assert2(
11817
11950
  message.length <= parameters.length,
11818
11951
  // Default options do not count.
11819
11952
  `Code: ${key}; The provided arguments length (${parameters.length}) does not match the required ones (${message.length}).`
@@ -11823,7 +11956,7 @@ function getMessage(key, parameters, self) {
11823
11956
  const regex = /%[dfijoOs]/g;
11824
11957
  let expectedLength = 0;
11825
11958
  while (regex.exec(message) !== null) expectedLength++;
11826
- assert(
11959
+ assert2(
11827
11960
  expectedLength === parameters.length,
11828
11961
  `Code: ${key}; The provided arguments length (${parameters.length}) does not match the required ones (${expectedLength}).`
11829
11962
  );
@@ -11860,7 +11993,7 @@ function read(jsonPath, { base, specifier }) {
11860
11993
  }
11861
11994
  let string;
11862
11995
  try {
11863
- string = fs.readFileSync(path2.toNamespacedPath(jsonPath), "utf8");
11996
+ string = fs2.readFileSync(path3.toNamespacedPath(jsonPath), "utf8");
11864
11997
  } catch (error) {
11865
11998
  const exception = (
11866
11999
  /** @type {ErrnoException} */
@@ -12076,7 +12209,7 @@ Default "index" lookups for the main are deprecated for ES modules.`,
12076
12209
  "DeprecationWarning",
12077
12210
  "DEP0151"
12078
12211
  );
12079
- } else if (path2.resolve(packagePath, main) !== urlPath) {
12212
+ } else if (path3.resolve(packagePath, main) !== urlPath) {
12080
12213
  process$1.emitWarning(
12081
12214
  `Package ${packagePath} has a "main" field set to "${main}", excluding the full filename and extension to the resolved file at "${urlPath.slice(
12082
12215
  packagePath.length
@@ -12087,9 +12220,9 @@ Default "index" lookups for the main are deprecated for ES modules.`,
12087
12220
  );
12088
12221
  }
12089
12222
  }
12090
- function tryStatSync(path10) {
12223
+ function tryStatSync(path11) {
12091
12224
  try {
12092
- return statSync(path10);
12225
+ return statSync(path11);
12093
12226
  } catch {
12094
12227
  }
12095
12228
  }
@@ -12183,7 +12316,7 @@ function finalizeResolution(resolved, base, preserveSymlinks) {
12183
12316
  {
12184
12317
  const real = realpathSync(filePath);
12185
12318
  const { search, hash } = resolved;
12186
- resolved = pathToFileURL$1(real + (filePath.endsWith(path2.sep) ? "/" : ""));
12319
+ resolved = pathToFileURL$1(real + (filePath.endsWith(path3.sep) ? "/" : ""));
12187
12320
  resolved.search = search;
12188
12321
  resolved.hash = hash;
12189
12322
  }
@@ -12723,7 +12856,7 @@ function moduleResolve(specifier, base, conditions, preserveSymlinks) {
12723
12856
  resolved = packageResolve(specifier, base, conditions);
12724
12857
  }
12725
12858
  }
12726
- assert(resolved !== void 0, "expected to be defined");
12859
+ assert2(resolved !== void 0, "expected to be defined");
12727
12860
  if (resolved.protocol !== "file:") {
12728
12861
  return resolved;
12729
12862
  }
@@ -12894,8 +13027,8 @@ function isNodeAls(workerConfig) {
12894
13027
  workerConfig.compatibility_flags ?? []
12895
13028
  ).mode === "als";
12896
13029
  }
12897
- function isNodeAlsModule(path10) {
12898
- return /^(node:)?async_hooks$/.test(path10);
13030
+ function isNodeAlsModule(path11) {
13031
+ return /^(node:)?async_hooks$/.test(path11);
12899
13032
  }
12900
13033
  function injectGlobalCode(id, code) {
12901
13034
  const injectedCode = Object.entries(env.inject).map(([globalName, globalInject]) => {
@@ -12906,11 +13039,11 @@ globalThis.${globalName} = var_${globalName};
12906
13039
  `;
12907
13040
  }
12908
13041
  const [moduleSpecifier, exportName] = globalInject;
12909
- assert2(
13042
+ assert3(
12910
13043
  moduleSpecifier !== void 0,
12911
13044
  "Expected moduleSpecifier to be defined"
12912
13045
  );
12913
- assert2(exportName !== void 0, "Expected exportName to be defined");
13046
+ assert3(exportName !== void 0, "Expected exportName to be defined");
12914
13047
  return `import var_${globalName} from "${moduleSpecifier}";
12915
13048
  globalThis.${globalName} = var_${globalName}.${exportName};
12916
13049
  `;
@@ -12946,7 +13079,7 @@ function getNodeCompatEntries() {
12946
13079
  if (typeof globalInject === "string") {
12947
13080
  entries.add(globalInject);
12948
13081
  } else {
12949
- assert2(
13082
+ assert3(
12950
13083
  globalInject[0] !== void 0,
12951
13084
  "Expected first element of globalInject to be defined"
12952
13085
  );
@@ -12985,7 +13118,7 @@ var NodeJsCompatWarnings = class {
12985
13118
  `;
12986
13119
  this.sources.forEach((importers, source) => {
12987
13120
  importers.forEach((importer) => {
12988
- message += ` - "${source}" imported from "${path3.relative(this.resolvedViteConfig.root, importer)}"
13121
+ message += ` - "${source}" imported from "${path4.relative(this.resolvedViteConfig.root, importer)}"
12989
13122
  `;
12990
13123
  });
12991
13124
  });
@@ -13009,13 +13142,13 @@ var additionalModuleGlobalRE = new RegExp(
13009
13142
  var VITE_DEV_METADATA_HEADER = "__VITE_DEV_METADATA__";
13010
13143
 
13011
13144
  // src/utils.ts
13012
- import * as path4 from "node:path";
13145
+ import * as path5 from "node:path";
13013
13146
  import getPort, { portNumbers } from "get-port";
13014
13147
  import { Request as MiniflareRequest } from "miniflare";
13015
13148
  import "vite";
13016
13149
  function getOutputDirectory(userConfig, environmentName) {
13017
13150
  const rootOutputDirectory = userConfig.build?.outDir ?? "dist";
13018
- return userConfig.environments?.[environmentName]?.build?.outDir ?? path4.join(rootOutputDirectory, environmentName);
13151
+ return userConfig.environments?.[environmentName]?.build?.outDir ?? path5.join(rootOutputDirectory, environmentName);
13019
13152
  }
13020
13153
  function toMiniflareRequest(request) {
13021
13154
  const host = request.headers.get("Host");
@@ -13048,7 +13181,7 @@ function createHotChannel(webSocketContainer) {
13048
13181
  const client = {
13049
13182
  send(payload) {
13050
13183
  const webSocket = webSocketContainer.webSocket;
13051
- assert3(webSocket, webSocketUndefinedError);
13184
+ assert4(webSocket, webSocketUndefinedError);
13052
13185
  webSocket.send(JSON.stringify(payload));
13053
13186
  }
13054
13187
  };
@@ -13062,7 +13195,7 @@ function createHotChannel(webSocketContainer) {
13062
13195
  return {
13063
13196
  send(payload) {
13064
13197
  const webSocket = webSocketContainer.webSocket;
13065
- assert3(webSocket, webSocketUndefinedError);
13198
+ assert4(webSocket, webSocketUndefinedError);
13066
13199
  webSocket.send(JSON.stringify(payload));
13067
13200
  },
13068
13201
  on(event, listener) {
@@ -13075,12 +13208,12 @@ function createHotChannel(webSocketContainer) {
13075
13208
  },
13076
13209
  listen() {
13077
13210
  const webSocket = webSocketContainer.webSocket;
13078
- assert3(webSocket, webSocketUndefinedError);
13211
+ assert4(webSocket, webSocketUndefinedError);
13079
13212
  webSocket.addEventListener("message", onMessage);
13080
13213
  },
13081
13214
  close() {
13082
13215
  const webSocket = webSocketContainer.webSocket;
13083
- assert3(webSocket, webSocketUndefinedError);
13216
+ assert4(webSocket, webSocketUndefinedError);
13084
13217
  webSocket.removeEventListener("message", onMessage);
13085
13218
  }
13086
13219
  };
@@ -13110,12 +13243,12 @@ var CloudflareDevEnvironment = class extends vite3.DevEnvironment {
13110
13243
  }
13111
13244
  }
13112
13245
  );
13113
- assert3(
13246
+ assert4(
13114
13247
  response.ok,
13115
13248
  `Failed to initialize module runner, error: ${await response.text()}`
13116
13249
  );
13117
13250
  const webSocket = response.webSocket;
13118
- assert3(webSocket, "Failed to establish WebSocket");
13251
+ assert4(webSocket, "Failed to establish WebSocket");
13119
13252
  webSocket.accept();
13120
13253
  this.#webSocketContainer.webSocket = webSocket;
13121
13254
  }
@@ -13128,7 +13261,7 @@ var cloudflareBuiltInModules = [
13128
13261
  ];
13129
13262
  var defaultConditions = ["workerd", "module", "browser"];
13130
13263
  var target = "es2022";
13131
- function createCloudflareEnvironmentOptions(workerConfig, userConfig, environmentName) {
13264
+ function createCloudflareEnvironmentOptions(workerConfig, userConfig, environment) {
13132
13265
  return {
13133
13266
  resolve: {
13134
13267
  // Note: in order for ssr pre-bundling to take effect we need to ask vite to treat all
@@ -13149,16 +13282,12 @@ function createCloudflareEnvironmentOptions(workerConfig, userConfig, environmen
13149
13282
  return new vite3.BuildEnvironment(name, config);
13150
13283
  },
13151
13284
  target,
13152
- // We need to enable `emitAssets` in order to support additional modules defined by `rules`
13153
13285
  emitAssets: true,
13154
- outDir: getOutputDirectory(userConfig, environmentName),
13286
+ manifest: environment.isEntry,
13287
+ outDir: getOutputDirectory(userConfig, environment.name),
13155
13288
  copyPublicDir: false,
13156
13289
  ssr: true,
13157
13290
  rollupOptions: {
13158
- // Note: vite starts dev pre-bundling crawling from either optimizeDeps.entries or rollupOptions.input
13159
- // so the input value here serves both as the build input as well as the starting point for
13160
- // dev pre-bundling crawling (were we not to set this input field we'd have to appropriately set
13161
- // optimizeDeps.entries in the dev config)
13162
13291
  input: workerConfig.main
13163
13292
  }
13164
13293
  },
@@ -13204,8 +13333,8 @@ function initRunners(resolvedPluginConfig, viteDevServer, miniflare2) {
13204
13333
  }
13205
13334
 
13206
13335
  // src/debugging.ts
13207
- import assert4 from "node:assert";
13208
- import colors from "picocolors";
13336
+ import assert5 from "node:assert";
13337
+ import colors2 from "picocolors";
13209
13338
  var debuggingPath = "/__debug";
13210
13339
  function addDebugToVitePrintUrls(server) {
13211
13340
  const originalPrintUrls = server.printUrls;
@@ -13214,19 +13343,19 @@ function addDebugToVitePrintUrls(server) {
13214
13343
  const localUrl = server.resolvedUrls?.local[0];
13215
13344
  if (localUrl) {
13216
13345
  const { protocol, hostname, port } = new URL(localUrl);
13217
- const colorDebugUrl = (url) => colors.dim(
13218
- colors.yellow(
13219
- url.replace(/:(\d+)\//, (_, port2) => `:${colors.bold(port2)}/`)
13346
+ const colorDebugUrl = (url) => colors2.dim(
13347
+ colors2.yellow(
13348
+ url.replace(/:(\d+)\//, (_, port2) => `:${colors2.bold(port2)}/`)
13220
13349
  )
13221
13350
  );
13222
13351
  server.config.logger.info(
13223
- ` ${colors.green("\u279C")} ${colors.bold("Debug")}: ${colorDebugUrl(`${protocol}//${hostname}:${port}${debuggingPath}`)}`
13352
+ ` ${colors2.green("\u279C")} ${colors2.bold("Debug")}: ${colorDebugUrl(`${protocol}//${hostname}:${port}${debuggingPath}`)}`
13224
13353
  );
13225
13354
  }
13226
13355
  };
13227
13356
  }
13228
13357
  function getDebugPathHtml(workerNames, inspectorPort) {
13229
- assert4(workerNames.length >= 1, "no workers present to debug");
13358
+ assert5(workerNames.length >= 1, "no workers present to debug");
13230
13359
  const workerDevtoolsUrls = workerNames.map((workerName) => {
13231
13360
  const localHost = `localhost:${inspectorPort}/${workerName}`;
13232
13361
  const searchParams = new URLSearchParams({
@@ -13253,25 +13382,25 @@ function getDebugPathHtml(workerNames, inspectorPort) {
13253
13382
  }
13254
13383
 
13255
13384
  // src/deploy-config.ts
13256
- import assert5 from "node:assert";
13257
- import * as fs2 from "node:fs";
13258
- import * as path5 from "node:path";
13385
+ import assert6 from "node:assert";
13386
+ import * as fs3 from "node:fs";
13387
+ import * as path6 from "node:path";
13259
13388
  import "vite";
13260
13389
  import { unstable_readConfig } from "wrangler";
13261
13390
  function getDeployConfigPath(root) {
13262
- return path5.resolve(root, ".wrangler", "deploy", "config.json");
13391
+ return path6.resolve(root, ".wrangler", "deploy", "config.json");
13263
13392
  }
13264
13393
  function getWorkerConfigs(root, mixedModeEnabled) {
13265
13394
  const deployConfigPath = getDeployConfigPath(root);
13266
13395
  const deployConfig = JSON.parse(
13267
- fs2.readFileSync(deployConfigPath, "utf-8")
13396
+ fs3.readFileSync(deployConfigPath, "utf-8")
13268
13397
  );
13269
13398
  return [
13270
13399
  { configPath: deployConfig.configPath },
13271
13400
  ...deployConfig.auxiliaryWorkers
13272
13401
  ].map(({ configPath }) => {
13273
- const resolvedConfigPath = path5.resolve(
13274
- path5.dirname(deployConfigPath),
13402
+ const resolvedConfigPath = path6.resolve(
13403
+ path6.dirname(deployConfigPath),
13275
13404
  configPath
13276
13405
  );
13277
13406
  return unstable_readConfig(
@@ -13281,18 +13410,18 @@ function getWorkerConfigs(root, mixedModeEnabled) {
13281
13410
  });
13282
13411
  }
13283
13412
  function getRelativePathToWorkerConfig(deployConfigDirectory, root, outputDirectory) {
13284
- return path5.relative(
13413
+ return path6.relative(
13285
13414
  deployConfigDirectory,
13286
- path5.resolve(root, outputDirectory, "wrangler.json")
13415
+ path6.resolve(root, outputDirectory, "wrangler.json")
13287
13416
  );
13288
13417
  }
13289
13418
  function writeDeployConfig(resolvedPluginConfig, resolvedViteConfig) {
13290
13419
  const deployConfigPath = getDeployConfigPath(resolvedViteConfig.root);
13291
- const deployConfigDirectory = path5.dirname(deployConfigPath);
13292
- fs2.mkdirSync(deployConfigDirectory, { recursive: true });
13420
+ const deployConfigDirectory = path6.dirname(deployConfigPath);
13421
+ fs3.mkdirSync(deployConfigDirectory, { recursive: true });
13293
13422
  if (resolvedPluginConfig.type === "assets-only") {
13294
13423
  const clientOutputDirectory = resolvedViteConfig.environments.client?.build.outDir;
13295
- assert5(
13424
+ assert6(
13296
13425
  clientOutputDirectory,
13297
13426
  "Unexpected error: client environment output directory is undefined"
13298
13427
  );
@@ -13304,13 +13433,13 @@ function writeDeployConfig(resolvedPluginConfig, resolvedViteConfig) {
13304
13433
  ),
13305
13434
  auxiliaryWorkers: []
13306
13435
  };
13307
- fs2.writeFileSync(deployConfigPath, JSON.stringify(deployConfig));
13436
+ fs3.writeFileSync(deployConfigPath, JSON.stringify(deployConfig));
13308
13437
  } else {
13309
13438
  let entryWorkerConfigPath;
13310
13439
  const auxiliaryWorkers = [];
13311
13440
  for (const environmentName of Object.keys(resolvedPluginConfig.workers)) {
13312
13441
  const outputDirectory = resolvedViteConfig.environments[environmentName]?.build.outDir;
13313
- assert5(
13442
+ assert6(
13314
13443
  outputDirectory,
13315
13444
  `Unexpected error: ${environmentName} environment output directory is undefined`
13316
13445
  );
@@ -13325,7 +13454,7 @@ function writeDeployConfig(resolvedPluginConfig, resolvedViteConfig) {
13325
13454
  auxiliaryWorkers.push({ configPath });
13326
13455
  }
13327
13456
  }
13328
- assert5(
13457
+ assert6(
13329
13458
  entryWorkerConfigPath,
13330
13459
  `Unexpected error: entryWorkerConfigPath is undefined`
13331
13460
  );
@@ -13333,15 +13462,15 @@ function writeDeployConfig(resolvedPluginConfig, resolvedViteConfig) {
13333
13462
  configPath: entryWorkerConfigPath,
13334
13463
  auxiliaryWorkers
13335
13464
  };
13336
- fs2.writeFileSync(deployConfigPath, JSON.stringify(deployConfig));
13465
+ fs3.writeFileSync(deployConfigPath, JSON.stringify(deployConfig));
13337
13466
  }
13338
13467
  }
13339
13468
 
13340
13469
  // src/miniflare-options.ts
13341
- import assert6 from "node:assert";
13342
- import * as fs3 from "node:fs";
13470
+ import assert7 from "node:assert";
13471
+ import * as fs4 from "node:fs";
13343
13472
  import * as fsp from "node:fs/promises";
13344
- import * as path6 from "node:path";
13473
+ import * as path7 from "node:path";
13345
13474
  import { fileURLToPath as fileURLToPath2 } from "node:url";
13346
13475
  import {
13347
13476
  getDefaultDevRegistryPath,
@@ -13350,7 +13479,7 @@ import {
13350
13479
  LogLevel,
13351
13480
  Response as MiniflareResponse
13352
13481
  } from "miniflare";
13353
- import colors2 from "picocolors";
13482
+ import colors3 from "picocolors";
13354
13483
  import { globSync } from "tinyglobby";
13355
13484
  import "vite";
13356
13485
  import {
@@ -13364,7 +13493,7 @@ function getPersistenceRoot(root, persistState) {
13364
13493
  return;
13365
13494
  }
13366
13495
  const defaultPersistPath = ".wrangler/state";
13367
- const persistPath = path6.resolve(
13496
+ const persistPath = path7.resolve(
13368
13497
  root,
13369
13498
  typeof persistState === "object" ? persistState.path : defaultPersistPath,
13370
13499
  "v3"
@@ -13383,7 +13512,7 @@ function getWorkerToWorkerEntrypointNamesMap(workers) {
13383
13512
  if (typeof value === "object" && "name" in value && value.entrypoint !== void 0 && value.entrypoint !== "default") {
13384
13513
  const targetWorkerName = value.name === kCurrentWorker ? worker.name : value.name;
13385
13514
  const entrypointNames = workerToWorkerEntrypointNamesMap.get(targetWorkerName);
13386
- assert6(entrypointNames, missingWorkerErrorMessage(targetWorkerName));
13515
+ assert7(entrypointNames, missingWorkerErrorMessage(targetWorkerName));
13387
13516
  entrypointNames.add(value.entrypoint);
13388
13517
  }
13389
13518
  }
@@ -13398,20 +13527,20 @@ function getWorkerToDurableObjectClassNamesMap(workers) {
13398
13527
  for (const value of Object.values(worker.durableObjects ?? {})) {
13399
13528
  if (typeof value === "string") {
13400
13529
  const classNames = workerToDurableObjectClassNamesMap.get(worker.name);
13401
- assert6(classNames, missingWorkerErrorMessage(worker.name));
13530
+ assert7(classNames, missingWorkerErrorMessage(worker.name));
13402
13531
  classNames.add(value);
13403
13532
  } else if (typeof value === "object") {
13404
13533
  if (value.scriptName) {
13405
13534
  const classNames = workerToDurableObjectClassNamesMap.get(
13406
13535
  value.scriptName
13407
13536
  );
13408
- assert6(classNames, missingWorkerErrorMessage(value.scriptName));
13537
+ assert7(classNames, missingWorkerErrorMessage(value.scriptName));
13409
13538
  classNames.add(value.className);
13410
13539
  } else {
13411
13540
  const classNames = workerToDurableObjectClassNamesMap.get(
13412
13541
  worker.name
13413
13542
  );
13414
- assert6(classNames, missingWorkerErrorMessage(worker.name));
13543
+ assert7(classNames, missingWorkerErrorMessage(worker.name));
13415
13544
  classNames.add(value.className);
13416
13545
  }
13417
13546
  }
@@ -13429,13 +13558,13 @@ function getWorkerToWorkflowEntrypointClassNamesMap(workers) {
13429
13558
  const classNames = workerToWorkflowEntrypointClassNamesMap.get(
13430
13559
  value.scriptName
13431
13560
  );
13432
- assert6(classNames, missingWorkerErrorMessage(value.scriptName));
13561
+ assert7(classNames, missingWorkerErrorMessage(value.scriptName));
13433
13562
  classNames.add(value.className);
13434
13563
  } else {
13435
13564
  const classNames = workerToWorkflowEntrypointClassNamesMap.get(
13436
13565
  worker.name
13437
13566
  );
13438
- assert6(classNames, missingWorkerErrorMessage(worker.name));
13567
+ assert7(classNames, missingWorkerErrorMessage(worker.name));
13439
13568
  classNames.add(value.className);
13440
13569
  }
13441
13570
  }
@@ -13466,8 +13595,8 @@ function logUnknownTails(tails, userWorkers, log) {
13466
13595
  const found = userWorkers.some((w) => w.name === name);
13467
13596
  if (!found) {
13468
13597
  log(
13469
- colors2.dim(
13470
- colors2.yellow(
13598
+ colors3.dim(
13599
+ colors3.yellow(
13471
13600
  `Tail consumer "${name}" was not found in your config. Make sure you add it to the config or run it in another dev session if you'd like to simulate receiving tail events locally.`
13472
13601
  )
13473
13602
  )
@@ -13491,8 +13620,8 @@ async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspe
13491
13620
  modules: [
13492
13621
  {
13493
13622
  type: "ESModule",
13494
- path: path6.join(miniflareModulesRoot, ROUTER_WORKER_PATH),
13495
- contents: fs3.readFileSync(
13623
+ path: path7.join(miniflareModulesRoot, ROUTER_WORKER_PATH),
13624
+ contents: fs4.readFileSync(
13496
13625
  fileURLToPath2(new URL(ROUTER_WORKER_PATH, import.meta.url))
13497
13626
  )
13498
13627
  }
@@ -13514,8 +13643,8 @@ async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspe
13514
13643
  modules: [
13515
13644
  {
13516
13645
  type: "ESModule",
13517
- path: path6.join(miniflareModulesRoot, ASSET_WORKER_PATH),
13518
- contents: fs3.readFileSync(
13646
+ path: path7.join(miniflareModulesRoot, ASSET_WORKER_PATH),
13647
+ contents: fs4.readFileSync(
13519
13648
  fileURLToPath2(new URL(ASSET_WORKER_PATH, import.meta.url))
13520
13649
  )
13521
13650
  }
@@ -13529,7 +13658,7 @@ async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspe
13529
13658
  let exists = false;
13530
13659
  if (pathname.endsWith(".html")) {
13531
13660
  try {
13532
- const filePath = path6.join(resolvedViteConfig.root, pathname);
13661
+ const filePath = path7.join(resolvedViteConfig.root, pathname);
13533
13662
  const stats = await fsp.stat(filePath);
13534
13663
  exists = stats.isFile();
13535
13664
  } catch (error) {
@@ -13539,7 +13668,7 @@ async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspe
13539
13668
  },
13540
13669
  __VITE_FETCH_ASSET__: async (request) => {
13541
13670
  const { pathname } = new URL(request.url);
13542
- const filePath = path6.join(resolvedViteConfig.root, pathname);
13671
+ const filePath = path7.join(resolvedViteConfig.root, pathname);
13543
13672
  try {
13544
13673
  let html = await fsp.readFile(filePath, "utf-8");
13545
13674
  html = await viteDevServer.transformIndexHtml(pathname, html);
@@ -13595,7 +13724,7 @@ async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspe
13595
13724
  __VITE_INVOKE_MODULE__: async (request) => {
13596
13725
  const payload = await request.json();
13597
13726
  const invokePayloadData = payload.data;
13598
- assert6(
13727
+ assert7(
13599
13728
  invokePayloadData.name === "fetchModule",
13600
13729
  `Invalid invoke event: ${invokePayloadData.name}`
13601
13730
  );
@@ -13653,7 +13782,7 @@ async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspe
13653
13782
  const workerEntrypointNames = workerToWorkerEntrypointNamesMap.get(
13654
13783
  workerOptions.name
13655
13784
  );
13656
- assert6(
13785
+ assert7(
13657
13786
  workerEntrypointNames,
13658
13787
  `WorkerEntrypoint names not found for worker ${workerOptions.name}`
13659
13788
  );
@@ -13665,7 +13794,7 @@ async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspe
13665
13794
  const durableObjectClassNames = workerToDurableObjectClassNamesMap.get(
13666
13795
  workerOptions.name
13667
13796
  );
13668
- assert6(
13797
+ assert7(
13669
13798
  durableObjectClassNames,
13670
13799
  `DurableObject class names not found for worker ${workerOptions.name}`
13671
13800
  );
@@ -13675,7 +13804,7 @@ async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspe
13675
13804
  );
13676
13805
  }
13677
13806
  const workflowEntrypointClassNames = workerToWorkflowEntrypointClassNamesMap.get(workerOptions.name);
13678
- assert6(
13807
+ assert7(
13679
13808
  workflowEntrypointClassNames,
13680
13809
  `WorkflowEntrypoint class names not found for worker: ${workerOptions.name}`
13681
13810
  );
@@ -13694,13 +13823,13 @@ async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspe
13694
13823
  modules: [
13695
13824
  {
13696
13825
  type: "ESModule",
13697
- path: path6.join(miniflareModulesRoot, WRAPPER_PATH),
13826
+ path: path7.join(miniflareModulesRoot, WRAPPER_PATH),
13698
13827
  contents: wrappers.join("\n")
13699
13828
  },
13700
13829
  {
13701
13830
  type: "ESModule",
13702
- path: path6.join(miniflareModulesRoot, RUNNER_PATH),
13703
- contents: fs3.readFileSync(
13831
+ path: path7.join(miniflareModulesRoot, RUNNER_PATH),
13832
+ contents: fs4.readFileSync(
13704
13833
  fileURLToPath2(new URL(RUNNER_PATH, import.meta.url))
13705
13834
  )
13706
13835
  }
@@ -13712,18 +13841,18 @@ async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspe
13712
13841
  async unsafeModuleFallbackService(request) {
13713
13842
  const url = new URL(request.url);
13714
13843
  const rawSpecifier = url.searchParams.get("rawSpecifier");
13715
- assert6(
13844
+ assert7(
13716
13845
  rawSpecifier,
13717
13846
  `Unexpected error: no specifier in request to module fallback service.`
13718
13847
  );
13719
13848
  const match = additionalModuleRE.exec(rawSpecifier);
13720
- assert6(match, `Unexpected error: no match for module: ${rawSpecifier}.`);
13849
+ assert7(match, `Unexpected error: no match for module: ${rawSpecifier}.`);
13721
13850
  const [full, moduleType, modulePath] = match;
13722
- assert6(
13851
+ assert7(
13723
13852
  moduleType,
13724
13853
  `Unexpected error: module type not found in reference: ${full}.`
13725
13854
  );
13726
- assert6(
13855
+ assert7(
13727
13856
  modulePath,
13728
13857
  `Unexpected error: module path not found in reference: ${full}.`
13729
13858
  );
@@ -13753,9 +13882,9 @@ async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspe
13753
13882
  };
13754
13883
  }
13755
13884
  function getPreviewModules(main, modulesRules) {
13756
- assert6(modulesRules, `Unexpected error: 'modulesRules' is undefined`);
13757
- const rootPath = path6.dirname(main);
13758
- const entryPath = path6.basename(main);
13885
+ assert7(modulesRules, `Unexpected error: 'modulesRules' is undefined`);
13886
+ const rootPath = path7.dirname(main);
13887
+ const entryPath = path7.basename(main);
13759
13888
  return {
13760
13889
  rootPath,
13761
13890
  modules: [
@@ -13764,9 +13893,9 @@ function getPreviewModules(main, modulesRules) {
13764
13893
  path: entryPath
13765
13894
  },
13766
13895
  ...modulesRules.flatMap(
13767
- ({ type, include }) => globSync(include, { cwd: rootPath, ignore: entryPath }).map((path10) => ({
13896
+ ({ type, include }) => globSync(include, { cwd: rootPath, ignore: entryPath }).map((path11) => ({
13768
13897
  type,
13769
- path: path10
13898
+ path: path11
13770
13899
  }))
13771
13900
  )
13772
13901
  ]
@@ -13864,11 +13993,16 @@ async function maybeStartOrUpdateMixedModeSession(workerConfig) {
13864
13993
  const workerRemoteBindings = experimental_pickRemoteBindings(
13865
13994
  unstable_convertConfigBindingsToStartWorkerBindings(workerConfig) ?? {}
13866
13995
  );
13867
- assert6(workerConfig.name, "Found workerConfig without a name");
13996
+ assert7(workerConfig.name, "Found workerConfig without a name");
13868
13997
  let mixedModeSession = mixedModeSessionsMap.get(workerConfig.name);
13869
13998
  if (mixedModeSession === void 0) {
13870
13999
  if (Object.keys(workerRemoteBindings).length > 0) {
13871
- mixedModeSession = await experimental_startMixedModeSession(workerRemoteBindings);
14000
+ mixedModeSession = await experimental_startMixedModeSession(
14001
+ workerRemoteBindings,
14002
+ {
14003
+ workerName: workerConfig.name
14004
+ }
14005
+ );
13872
14006
  mixedModeSessionsMap.set(workerConfig.name, mixedModeSession);
13873
14007
  }
13874
14008
  } else {
@@ -13879,14 +14013,14 @@ async function maybeStartOrUpdateMixedModeSession(workerConfig) {
13879
14013
  }
13880
14014
 
13881
14015
  // src/plugin-config.ts
13882
- import assert8 from "node:assert";
13883
- import * as path8 from "node:path";
14016
+ import assert9 from "node:assert";
14017
+ import * as path9 from "node:path";
13884
14018
  import * as vite6 from "vite";
13885
14019
 
13886
14020
  // src/workers-configs.ts
13887
- import assert7 from "node:assert";
13888
- import * as fs4 from "node:fs";
13889
- import * as path7 from "node:path";
14021
+ import assert8 from "node:assert";
14022
+ import * as fs5 from "node:fs";
14023
+ import * as path8 from "node:path";
13890
14024
  import { unstable_readConfig as unstable_readConfig2 } from "wrangler";
13891
14025
  var nonApplicableWorkerConfigs = {
13892
14026
  /**
@@ -13981,7 +14115,7 @@ function getWarningForWorkersConfigs(configs) {
13981
14115
  const lines2 = [
13982
14116
  `
13983
14117
 
13984
- \x1B[43mWARNING\x1B[0m: your worker config${configs.entryWorker.config.configPath ? ` (at \`${path7.relative("", configs.entryWorker.config.configPath)}\`)` : ""} contains the following configuration options which are ignored since they are not applicable when using Vite:`
14118
+ \x1B[43mWARNING\x1B[0m: your worker config${configs.entryWorker.config.configPath ? ` (at \`${path8.relative("", configs.entryWorker.config.configPath)}\`)` : ""} contains the following configuration options which are ignored since they are not applicable when using Vite:`
13985
14119
  ];
13986
14120
  nonApplicableLines.forEach((line) => lines2.push(line));
13987
14121
  lines2.push("");
@@ -13995,7 +14129,7 @@ function getWarningForWorkersConfigs(configs) {
13995
14129
  );
13996
14130
  if (nonApplicableLines.length > 0) {
13997
14131
  lines.push(
13998
- ` - (${isEntryWorker ? "entry" : "auxiliary"}) worker${workerConfig.config.name ? ` "${workerConfig.config.name}"` : ""}${workerConfig.config.configPath ? ` (config at \`${path7.relative("", workerConfig.config.configPath)}\`)` : ""}`
14132
+ ` - (${isEntryWorker ? "entry" : "auxiliary"}) worker${workerConfig.config.name ? ` "${workerConfig.config.name}"` : ""}${workerConfig.config.configPath ? ` (config at \`${path8.relative("", workerConfig.config.configPath)}\`)` : ""}`
13999
14133
  );
14000
14134
  nonApplicableLines.forEach((line) => lines.push(line));
14001
14135
  }
@@ -14076,7 +14210,7 @@ function getWorkerConfig(configPath, env2, mixedModeEnabled, opts) {
14076
14210
  if (!config.main) {
14077
14211
  throw new Error(missingFieldErrorMessage(`'main'`, configPath, env2));
14078
14212
  }
14079
- const mainStat = fs4.statSync(config.main, { throwIfNoEntry: false });
14213
+ const mainStat = fs5.statSync(config.main, { throwIfNoEntry: false });
14080
14214
  if (!mainStat) {
14081
14215
  throw new Error(
14082
14216
  `The provided Wrangler config main field (${config.main}) doesn't point to an existing file`
@@ -14100,17 +14234,17 @@ function getWorkerConfig(configPath, env2, mixedModeEnabled, opts) {
14100
14234
  }
14101
14235
  function getValidatedWranglerConfigPath(root, requestedConfigPath, isForAuxiliaryWorker = false) {
14102
14236
  if (requestedConfigPath) {
14103
- const configPath2 = path7.resolve(root, requestedConfigPath);
14237
+ const configPath2 = path8.resolve(root, requestedConfigPath);
14104
14238
  const forAuxiliaryWorkerErrorMessage = isForAuxiliaryWorker ? " requested for one of your auxiliary workers" : "";
14105
14239
  const errorMessagePrefix = `The provided configPath (${configPath2})${forAuxiliaryWorkerErrorMessage}`;
14106
- const fileExtension = path7.extname(configPath2).slice(1);
14240
+ const fileExtension = path8.extname(configPath2).slice(1);
14107
14241
  if (!allowedWranglerConfigExtensions.includes(fileExtension)) {
14108
14242
  const foundExtensionMessage = !fileExtension ? "no extension found" : `"${fileExtension}" found`;
14109
14243
  throw new Error(
14110
14244
  `${errorMessagePrefix} doesn't point to a file with the correct file extension. It should point to a jsonc, json or toml file (${foundExtensionMessage} instead)`
14111
14245
  );
14112
14246
  }
14113
- const mainStat = fs4.statSync(configPath2, { throwIfNoEntry: false });
14247
+ const mainStat = fs5.statSync(configPath2, { throwIfNoEntry: false });
14114
14248
  if (!mainStat) {
14115
14249
  throw new Error(
14116
14250
  `${errorMessagePrefix} doesn't point to an existing file`
@@ -14123,7 +14257,7 @@ function getValidatedWranglerConfigPath(root, requestedConfigPath, isForAuxiliar
14123
14257
  }
14124
14258
  return configPath2;
14125
14259
  }
14126
- assert7(
14260
+ assert8(
14127
14261
  isForAuxiliaryWorker === false,
14128
14262
  "Unexpected Error: trying to find the wrangler config for an auxiliary worker"
14129
14263
  );
@@ -14137,8 +14271,8 @@ function getValidatedWranglerConfigPath(root, requestedConfigPath, isForAuxiliar
14137
14271
  }
14138
14272
  function findWranglerConfig(root) {
14139
14273
  for (const extension of allowedWranglerConfigExtensions) {
14140
- const configPath = path7.join(root, `wrangler.${extension}`);
14141
- if (fs4.existsSync(configPath)) {
14274
+ const configPath = path8.join(root, `wrangler.${extension}`);
14275
+ if (fs5.existsSync(configPath)) {
14142
14276
  return configPath;
14143
14277
  }
14144
14278
  }
@@ -14153,7 +14287,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
14153
14287
  const configPaths = /* @__PURE__ */ new Set();
14154
14288
  const persistState = pluginConfig.persistState ?? true;
14155
14289
  const experimental = pluginConfig.experimental ?? {};
14156
- const root = userConfig.root ? path8.resolve(userConfig.root) : process.cwd();
14290
+ const root = userConfig.root ? path9.resolve(userConfig.root) : process.cwd();
14157
14291
  const { CLOUDFLARE_ENV: cloudflareEnv } = vite6.loadEnv(
14158
14292
  viteEnv.mode,
14159
14293
  root,
@@ -14207,7 +14341,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
14207
14341
  }
14208
14342
  );
14209
14343
  auxiliaryWorkersResolvedConfigs.push(workerResolvedConfig);
14210
- assert8(
14344
+ assert9(
14211
14345
  workerResolvedConfig.type === "worker",
14212
14346
  "Unexpected error: received AssetsOnlyResult with auxiliary workers."
14213
14347
  );
@@ -14273,14 +14407,14 @@ function handleWebSocket(httpServer, getFetcher) {
14273
14407
  }
14274
14408
 
14275
14409
  // src/worker-environments-validation.ts
14276
- import assert9 from "node:assert";
14410
+ import assert10 from "node:assert";
14277
14411
  function validateWorkerEnvironmentsResolvedConfigs(resolvedPluginConfig, resolvedViteConfig) {
14278
14412
  const workersEnvironmentNames = Object.keys(resolvedPluginConfig.workers);
14279
14413
  const disallowedEnvsConfigs = /* @__PURE__ */ new Map();
14280
14414
  for (const envName of workersEnvironmentNames) {
14281
14415
  const workerEnvConfig = resolvedViteConfig.environments[envName];
14282
- assert9(workerEnvConfig, `Missing environment config for "${envName}"`);
14283
- const { optimizeDeps, resolve: resolve7 } = workerEnvConfig;
14416
+ assert10(workerEnvConfig, `Missing environment config for "${envName}"`);
14417
+ const { optimizeDeps, resolve: resolve8 } = workerEnvConfig;
14284
14418
  const disallowedConfig = {};
14285
14419
  const disallowedOptimizeDepsExcludeEntries = (optimizeDeps.exclude ?? []).filter((entry) => {
14286
14420
  if (cloudflareBuiltInModules.includes(entry)) {
@@ -14297,8 +14431,8 @@ function validateWorkerEnvironmentsResolvedConfigs(resolvedPluginConfig, resolve
14297
14431
  if (disallowedOptimizeDepsExcludeEntries.length > 0) {
14298
14432
  disallowedConfig.optimizeDepsExclude = disallowedOptimizeDepsExcludeEntries;
14299
14433
  }
14300
- if (resolve7.external === true || resolve7.external.length > 0) {
14301
- disallowedConfig.resolveExternal = resolve7.external;
14434
+ if (resolve8.external === true || resolve8.external.length > 0) {
14435
+ disallowedConfig.resolveExternal = resolve8.external;
14302
14436
  }
14303
14437
  if (Object.keys(disallowedConfig).length > 0) {
14304
14438
  disallowedEnvsConfigs.set(envName, disallowedConfig);
@@ -14331,7 +14465,6 @@ function cloudflare2(pluginConfig = {}) {
14331
14465
  let resolvedViteConfig;
14332
14466
  const additionalModulePaths = /* @__PURE__ */ new Set();
14333
14467
  const nodeJsCompatWarningsMap = /* @__PURE__ */ new Map();
14334
- let hasClientBuild = false;
14335
14468
  return [
14336
14469
  {
14337
14470
  name: "vite-plugin-cloudflare",
@@ -14355,8 +14488,19 @@ function cloudflare2(pluginConfig = {}) {
14355
14488
  console.warn(workersConfigsWarning);
14356
14489
  }
14357
14490
  }
14491
+ const defaultDeniedFiles = [
14492
+ ".env",
14493
+ ".env.*",
14494
+ "*.{crt,pem}",
14495
+ "**/.git/**"
14496
+ ];
14358
14497
  return {
14359
14498
  appType: "custom",
14499
+ server: {
14500
+ fs: {
14501
+ deny: [...defaultDeniedFiles, ".dev.vars", ".dev.vars.*"]
14502
+ }
14503
+ },
14360
14504
  environments: resolvedPluginConfig.type === "workers" ? {
14361
14505
  ...Object.fromEntries(
14362
14506
  Object.entries(resolvedPluginConfig.workers).map(
@@ -14366,7 +14510,10 @@ function cloudflare2(pluginConfig = {}) {
14366
14510
  createCloudflareEnvironmentOptions(
14367
14511
  workerConfig,
14368
14512
  userConfig,
14369
- environmentName
14513
+ {
14514
+ name: environmentName,
14515
+ isEntry: resolvedPluginConfig.type === "workers" && environmentName === resolvedPluginConfig.entryWorkerEnvironmentName
14516
+ }
14370
14517
  )
14371
14518
  ];
14372
14519
  }
@@ -14379,33 +14526,7 @@ function cloudflare2(pluginConfig = {}) {
14379
14526
  }
14380
14527
  } : void 0,
14381
14528
  builder: {
14382
- buildApp: userConfig.builder?.buildApp ?? (async (builder) => {
14383
- const clientEnvironment = builder.environments.client;
14384
- const defaultHtmlPath = path9.resolve(
14385
- builder.config.root,
14386
- "index.html"
14387
- );
14388
- if (clientEnvironment && (clientEnvironment.config.build.rollupOptions.input || fs5.existsSync(defaultHtmlPath))) {
14389
- await builder.build(clientEnvironment);
14390
- }
14391
- if (resolvedPluginConfig.type === "workers") {
14392
- const workerEnvironments = Object.keys(
14393
- resolvedPluginConfig.workers
14394
- ).map((environmentName) => {
14395
- const environment = builder.environments[environmentName];
14396
- assert10(
14397
- environment,
14398
- `${environmentName} environment not found`
14399
- );
14400
- return environment;
14401
- });
14402
- await Promise.all(
14403
- workerEnvironments.map(
14404
- (environment) => builder.build(environment)
14405
- )
14406
- );
14407
- }
14408
- })
14529
+ buildApp: userConfig.builder?.buildApp ?? createBuildApp(resolvedPluginConfig)
14409
14530
  }
14410
14531
  };
14411
14532
  },
@@ -14437,18 +14558,18 @@ function cloudflare2(pluginConfig = {}) {
14437
14558
  { type: "ESModule", globs: ["**/*.js", "**/*.mjs"] }
14438
14559
  ];
14439
14560
  const isEntryWorker = this.environment.name === resolvedPluginConfig.entryWorkerEnvironmentName;
14440
- if (isEntryWorker && hasClientBuild) {
14561
+ if (isEntryWorker) {
14441
14562
  const workerOutputDirectory = this.environment.config.build.outDir;
14442
14563
  const clientOutputDirectory = resolvedViteConfig.environments.client?.build.outDir;
14443
- assert10(
14564
+ assert11(
14444
14565
  clientOutputDirectory,
14445
14566
  "Unexpected error: client output directory is undefined"
14446
14567
  );
14447
14568
  workerConfig.assets = {
14448
14569
  ...workerConfig.assets,
14449
- directory: path9.relative(
14450
- path9.resolve(resolvedViteConfig.root, workerOutputDirectory),
14451
- path9.resolve(resolvedViteConfig.root, clientOutputDirectory)
14570
+ directory: path10.relative(
14571
+ path10.resolve(resolvedViteConfig.root, workerOutputDirectory),
14572
+ path10.resolve(resolvedViteConfig.root, clientOutputDirectory)
14452
14573
  )
14453
14574
  };
14454
14575
  } else {
@@ -14496,15 +14617,12 @@ function cloudflare2(pluginConfig = {}) {
14496
14617
  });
14497
14618
  },
14498
14619
  writeBundle() {
14499
- if (this.environment.name === "client") {
14500
- hasClientBuild = true;
14501
- }
14502
14620
  if (this.environment.name === (resolvedPluginConfig.type === "assets-only" ? "client" : resolvedPluginConfig.entryWorkerEnvironmentName)) {
14503
14621
  writeDeployConfig(resolvedPluginConfig, resolvedViteConfig);
14504
14622
  }
14505
14623
  },
14506
14624
  hotUpdate(options) {
14507
- const changedFilePath = path9.resolve(options.file);
14625
+ const changedFilePath = path10.resolve(options.file);
14508
14626
  if (resolvedPluginConfig.configPaths.has(changedFilePath) || hasDotDevDotVarsFileChanged(resolvedPluginConfig, changedFilePath) || hasAssetsConfigChanged(
14509
14627
  resolvedPluginConfig,
14510
14628
  resolvedViteConfig,
@@ -14532,7 +14650,7 @@ function cloudflare2(pluginConfig = {}) {
14532
14650
  await initRunners(resolvedPluginConfig, viteDevServer, miniflare);
14533
14651
  if (viteDevServer.httpServer) {
14534
14652
  handleWebSocket(viteDevServer.httpServer, async () => {
14535
- assert10(miniflare, `Miniflare not defined`);
14653
+ assert11(miniflare, `Miniflare not defined`);
14536
14654
  const routerWorker = await miniflare.getWorker(ROUTER_WORKER_NAME);
14537
14655
  return routerWorker.fetch;
14538
14656
  });
@@ -14540,7 +14658,7 @@ function cloudflare2(pluginConfig = {}) {
14540
14658
  return () => {
14541
14659
  viteDevServer.middlewares.use(async (req, res, next) => {
14542
14660
  try {
14543
- assert10(miniflare, `Miniflare not defined`);
14661
+ assert11(miniflare, `Miniflare not defined`);
14544
14662
  const request = createRequest(req, res);
14545
14663
  let response;
14546
14664
  if (req[kRequestType] === "asset") {
@@ -14605,6 +14723,20 @@ function cloudflare2(pluginConfig = {}) {
14605
14723
  });
14606
14724
  }
14607
14725
  },
14726
+ // Plugin to provide a fallback entry file
14727
+ {
14728
+ name: "vite-plugin-cloudflare:fallback-entry",
14729
+ resolveId(source) {
14730
+ if (source === "virtual:__cloudflare_fallback_entry__") {
14731
+ return `\0virtual:__cloudflare_fallback_entry__`;
14732
+ }
14733
+ },
14734
+ load(id) {
14735
+ if (id === "\0virtual:__cloudflare_fallback_entry__") {
14736
+ return ``;
14737
+ }
14738
+ }
14739
+ },
14608
14740
  // Plugin to support `.wasm?init` extension
14609
14741
  {
14610
14742
  name: "vite-plugin-cloudflare:wasm-helper",
@@ -14664,7 +14796,7 @@ function cloudflare2(pluginConfig = {}) {
14664
14796
  for (const match of matches) {
14665
14797
  magicString ??= new MagicString(code);
14666
14798
  const [full, _, modulePath] = match;
14667
- assert10(
14799
+ assert11(
14668
14800
  modulePath,
14669
14801
  `Unexpected error: module path not found in reference ${full}.`
14670
14802
  );
@@ -14678,13 +14810,13 @@ function cloudflare2(pluginConfig = {}) {
14678
14810
  }
14679
14811
  const referenceId = this.emitFile({
14680
14812
  type: "asset",
14681
- name: path9.basename(modulePath),
14813
+ name: path10.basename(modulePath),
14682
14814
  originalFileName: modulePath,
14683
14815
  source
14684
14816
  });
14685
14817
  const emittedFileName = this.getFileName(referenceId);
14686
14818
  const relativePath = vite7.normalizePath(
14687
- path9.relative(path9.dirname(chunk.fileName), emittedFileName)
14819
+ path10.relative(path10.dirname(chunk.fileName), emittedFileName)
14688
14820
  );
14689
14821
  const importPath = relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
14690
14822
  magicString.update(
@@ -14749,7 +14881,7 @@ function cloudflare2(pluginConfig = {}) {
14749
14881
  return this.resolve(source, importer, options);
14750
14882
  }
14751
14883
  if (this.environment.mode === "dev") {
14752
- assert10(
14884
+ assert11(
14753
14885
  this.environment.depsOptimizer,
14754
14886
  "depsOptimizer is required in dev mode"
14755
14887
  );
@@ -14845,7 +14977,7 @@ function cloudflare2(pluginConfig = {}) {
14845
14977
  addDebugToVitePrintUrls(vitePreviewServer);
14846
14978
  }
14847
14979
  const workerNames = workerConfigs.map((worker) => {
14848
- assert10(worker.name, "Expected the Worker to have a name");
14980
+ assert11(worker.name, "Expected the Worker to have a name");
14849
14981
  return worker.name;
14850
14982
  });
14851
14983
  vitePreviewServer.middlewares.use(async (req, res, next) => {
@@ -14880,13 +15012,13 @@ function cloudflare2(pluginConfig = {}) {
14880
15012
  setup(build) {
14881
15013
  build.onResolve(
14882
15014
  { filter: NODEJS_MODULES_RE },
14883
- ({ path: path10, importer }) => {
14884
- if (isNodeAls(workerConfig) && isNodeAlsModule(path10)) {
15015
+ ({ path: path11, importer }) => {
15016
+ if (isNodeAls(workerConfig) && isNodeAlsModule(path11)) {
14885
15017
  return;
14886
15018
  }
14887
15019
  const nodeJsCompatWarnings = nodeJsCompatWarningsMap.get(workerConfig);
14888
- nodeJsCompatWarnings?.registerImport(path10, importer);
14889
- return { path: path10, external: true };
15020
+ nodeJsCompatWarnings?.registerImport(path11, importer);
15021
+ return { path: path11, external: true };
14890
15022
  }
14891
15023
  );
14892
15024
  }
@@ -14929,7 +15061,7 @@ function cloudflare2(pluginConfig = {}) {
14929
15061
  }
14930
15062
  ];
14931
15063
  function getWorkerConfig2(environmentName) {
14932
- assert10(resolvedPluginConfig, "Expected resolvedPluginConfig to be defined");
15064
+ assert11(resolvedPluginConfig, "Expected resolvedPluginConfig to be defined");
14933
15065
  return resolvedPluginConfig.type !== "assets-only" ? resolvedPluginConfig.workers[environmentName] : void 0;
14934
15066
  }
14935
15067
  }
@@ -14943,7 +15075,7 @@ async function getInputInspectorPortOption(pluginConfig, viteServer) {
14943
15075
  const inputInspectorPort = pluginConfig.inspectorPort ?? await getFirstAvailablePort(DEFAULT_INSPECTOR_PORT);
14944
15076
  if (pluginConfig.inspectorPort === void 0 && inputInspectorPort !== DEFAULT_INSPECTOR_PORT) {
14945
15077
  viteServer.config.logger.warn(
14946
- colors3.dim(
15078
+ colors4.dim(
14947
15079
  `Default inspector port ${DEFAULT_INSPECTOR_PORT} not available, using ${inputInspectorPort} instead
14948
15080
  `
14949
15081
  )
@@ -14959,19 +15091,19 @@ async function getResolvedInspectorPort(pluginConfig) {
14959
15091
  return null;
14960
15092
  }
14961
15093
  function getDotDevDotVarsContent(configPath, cloudflareEnv) {
14962
- const configDir = path9.dirname(configPath);
15094
+ const configDir = path10.dirname(configPath);
14963
15095
  const defaultDotDevDotVarsPath = `${configDir}/.dev.vars`;
14964
15096
  const inputDotDevDotVarsPath = `${defaultDotDevDotVarsPath}${cloudflareEnv ? `.${cloudflareEnv}` : ""}`;
14965
- const targetPath = fs5.existsSync(inputDotDevDotVarsPath) ? inputDotDevDotVarsPath : fs5.existsSync(defaultDotDevDotVarsPath) ? defaultDotDevDotVarsPath : null;
15097
+ const targetPath = fs6.existsSync(inputDotDevDotVarsPath) ? inputDotDevDotVarsPath : fs6.existsSync(defaultDotDevDotVarsPath) ? defaultDotDevDotVarsPath : null;
14966
15098
  if (targetPath) {
14967
- const dotDevDotVarsContent = fs5.readFileSync(targetPath);
15099
+ const dotDevDotVarsContent = fs6.readFileSync(targetPath);
14968
15100
  return dotDevDotVarsContent;
14969
15101
  }
14970
15102
  return null;
14971
15103
  }
14972
15104
  function hasDotDevDotVarsFileChanged(resolvedPluginConfig, changedFilePath) {
14973
15105
  return [...resolvedPluginConfig.configPaths].some((configPath) => {
14974
- const dotDevDotVars = path9.join(path9.dirname(configPath), ".dev.vars");
15106
+ const dotDevDotVars = path10.join(path10.dirname(configPath), ".dev.vars");
14975
15107
  if (dotDevDotVars === changedFilePath) {
14976
15108
  return true;
14977
15109
  }