@cloudflare/vite-plugin 1.13.2 → 1.13.3

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 +150 -142
  2. package/package.json +7 -7
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 = (path14, originalPath, doThrow) => {
252
- if (!isString2(path14)) {
251
+ var checkPath = (path15, originalPath, doThrow) => {
252
+ if (!isString2(path15)) {
253
253
  return doThrow(
254
254
  `path must be a string, but got \`${originalPath}\``,
255
255
  TypeError
256
256
  );
257
257
  }
258
- if (!path14) {
258
+ if (!path15) {
259
259
  return doThrow(`path must not be empty`, TypeError);
260
260
  }
261
- if (checkPath.isNotRelative(path14)) {
261
+ if (checkPath.isNotRelative(path15)) {
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 = (path14) => REGEX_TEST_INVALID_PATH.test(path14);
270
+ var isNotRelative = (path15) => REGEX_TEST_INVALID_PATH.test(path15);
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(path14, checkUnignored) {
329
+ _testOne(path15, 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(path14);
337
+ const matched = rule.regex.test(path15);
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 path14 = originalPath && checkPath.convert(originalPath);
350
+ const path15 = originalPath && checkPath.convert(originalPath);
351
351
  checkPath(
352
- path14,
352
+ path15,
353
353
  originalPath,
354
354
  this._allowRelativePaths ? RETURN_FALSE : throwError
355
355
  );
356
- return this._t(path14, cache2, checkUnignored, slices);
356
+ return this._t(path15, cache2, checkUnignored, slices);
357
357
  }
358
- _t(path14, cache2, checkUnignored, slices) {
359
- if (path14 in cache2) {
360
- return cache2[path14];
358
+ _t(path15, cache2, checkUnignored, slices) {
359
+ if (path15 in cache2) {
360
+ return cache2[path15];
361
361
  }
362
362
  if (!slices) {
363
- slices = path14.split(SLASH);
363
+ slices = path15.split(SLASH);
364
364
  }
365
365
  slices.pop();
366
366
  if (!slices.length) {
367
- return cache2[path14] = this._testOne(path14, checkUnignored);
367
+ return cache2[path15] = this._testOne(path15, 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[path14] = parent.ignored ? parent : this._testOne(path14, checkUnignored);
375
+ return cache2[path15] = parent.ignored ? parent : this._testOne(path15, checkUnignored);
376
376
  }
377
- ignores(path14) {
378
- return this._test(path14, this._ignoreCache, false).ignored;
377
+ ignores(path15) {
378
+ return this._test(path15, this._ignoreCache, false).ignored;
379
379
  }
380
380
  createFilter() {
381
- return (path14) => !this.ignores(path14);
381
+ return (path15) => !this.ignores(path15);
382
382
  }
383
383
  filter(paths) {
384
384
  return makeArray(paths).filter(this.createFilter());
385
385
  }
386
386
  // @returns {TestResult}
387
- test(path14) {
388
- return this._test(path14, this._testCache, true);
387
+ test(path15) {
388
+ return this._test(path15, this._testCache, true);
389
389
  }
390
390
  };
391
391
  var factory = (options) => new Ignore(options);
392
- var isPathValid = (path14) => checkPath(path14 && checkPath.convert(path14), path14, RETURN_FALSE);
392
+ var isPathValid = (path15) => checkPath(path15 && checkPath.convert(path15), path15, RETURN_FALSE);
393
393
  factory.isPathValid = isPathValid;
394
394
  factory.default = factory;
395
395
  module.exports = factory;
@@ -400,15 +400,15 @@ 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 = (path14) => REGIX_IS_WINDOWS_PATH_ABSOLUTE.test(path14) || isNotRelative(path14);
403
+ checkPath.isNotRelative = (path15) => REGIX_IS_WINDOWS_PATH_ABSOLUTE.test(path15) || isNotRelative(path15);
404
404
  }
405
405
  }
406
406
  });
407
407
 
408
408
  // src/index.ts
409
- import assert12 from "node:assert";
409
+ import assert13 from "node:assert";
410
410
  import * as fsp2 from "node:fs/promises";
411
- import * as path13 from "node:path";
411
+ import * as path14 from "node:path";
412
412
  import * as util3 from "node:util";
413
413
 
414
414
  // ../containers-shared/src/utils.ts
@@ -685,8 +685,8 @@ for (let i = 0; i < chars.length; i++) {
685
685
  intToChar[i] = c;
686
686
  charToInt[c] = i;
687
687
  }
688
- function encodeInteger(builder, num, relative8) {
689
- let delta = num - relative8;
688
+ function encodeInteger(builder, num, relative9) {
689
+ let delta = num - relative9;
690
690
  delta = delta < 0 ? -delta << 1 | 1 : delta << 1;
691
691
  do {
692
692
  let clamped = delta & 31;
@@ -1741,7 +1741,7 @@ var MagicString = class _MagicString {
1741
1741
  // src/index.ts
1742
1742
  import { CoreHeaders, Miniflare } from "miniflare";
1743
1743
  import colors4 from "picocolors";
1744
- import * as vite5 from "vite";
1744
+ import * as vite6 from "vite";
1745
1745
 
1746
1746
  // src/constants.ts
1747
1747
  var ROUTER_WORKER_NAME = "__router-worker__";
@@ -1927,11 +1927,11 @@ ${invalidHeaderRulesList}`
1927
1927
  }
1928
1928
 
1929
1929
  // ../workers-shared/utils/configuration/validateURL.ts
1930
- var extractPathname = (path14 = "/", includeSearch, includeHash) => {
1931
- if (!path14.startsWith("/")) {
1932
- path14 = `/${path14}`;
1930
+ var extractPathname = (path15 = "/", includeSearch, includeHash) => {
1931
+ if (!path15.startsWith("/")) {
1932
+ path15 = `/${path15}`;
1933
1933
  }
1934
- const url = new URL(`//${path14}`, "relative://");
1934
+ const url = new URL(`//${path15}`, "relative://");
1935
1935
  return `${url.pathname}${includeSearch ? url.search : ""}${includeHash ? url.hash : ""}`;
1936
1936
  };
1937
1937
  var URL_REGEX = /^https:\/\/+(?<host>[^/]+)\/?(?<path>.*)/;
@@ -1964,8 +1964,8 @@ var validateUrl = (token, onlyRelative = false, disallowPorts = false, includeSe
1964
1964
  if (!token.startsWith("/") && onlyRelative) {
1965
1965
  token = `/${token}`;
1966
1966
  }
1967
- const path14 = PATH_REGEX.exec(token);
1968
- if (path14) {
1967
+ const path15 = PATH_REGEX.exec(token);
1968
+ if (path15) {
1969
1969
  try {
1970
1970
  return [extractPathname(token, includeSearch, includeHash), void 0];
1971
1971
  } catch {
@@ -2026,7 +2026,7 @@ function parseHeaders(input, {
2026
2026
  });
2027
2027
  }
2028
2028
  }
2029
- const [path14, pathError] = validateUrl(line, false, true);
2029
+ const [path15, pathError] = validateUrl(line, false, true);
2030
2030
  if (pathError) {
2031
2031
  invalid.push({
2032
2032
  line,
@@ -2037,7 +2037,7 @@ function parseHeaders(input, {
2037
2037
  continue;
2038
2038
  }
2039
2039
  rule = {
2040
- path: path14,
2040
+ path: path15,
2041
2041
  line,
2042
2042
  headers: {},
2043
2043
  unsetHeaders: []
@@ -3385,12 +3385,12 @@ var Mime = class {
3385
3385
  }
3386
3386
  return this;
3387
3387
  }
3388
- getType(path14) {
3389
- if (typeof path14 !== "string")
3388
+ getType(path15) {
3389
+ if (typeof path15 !== "string")
3390
3390
  return null;
3391
- const last = path14.replace(/^.*[/\\]/s, "").toLowerCase();
3391
+ const last = path15.replace(/^.*[/\\]/s, "").toLowerCase();
3392
3392
  const ext = last.replace(/^.*\./s, "").toLowerCase();
3393
- const hasPath = last.length < path14.length;
3393
+ const hasPath = last.length < path15.length;
3394
3394
  const hasDot = ext.length < last.length - 1;
3395
3395
  if (!hasDot && hasPath)
3396
3396
  return null;
@@ -3792,8 +3792,8 @@ function getErrorMap() {
3792
3792
  return overrideErrorMap;
3793
3793
  }
3794
3794
  var makeIssue = (params) => {
3795
- const { data: data2, path: path14, errorMaps, issueData } = params;
3796
- const fullPath = [...path14, ...issueData.path || []];
3795
+ const { data: data2, path: path15, errorMaps, issueData } = params;
3796
+ const fullPath = [...path15, ...issueData.path || []];
3797
3797
  const fullIssue = {
3798
3798
  ...issueData,
3799
3799
  path: fullPath
@@ -3892,11 +3892,11 @@ var errorUtil;
3892
3892
  errorUtil2.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
3893
3893
  })(errorUtil || (errorUtil = {}));
3894
3894
  var ParseInputLazyPath = class {
3895
- constructor(parent, value, path14, key) {
3895
+ constructor(parent, value, path15, key) {
3896
3896
  this._cachedPath = [];
3897
3897
  this.parent = parent;
3898
3898
  this.data = value;
3899
- this._path = path14;
3899
+ this._path = path15;
3900
3900
  this._key = key;
3901
3901
  }
3902
3902
  get path() {
@@ -7464,8 +7464,8 @@ var postfixRE = /[?#].*$/;
7464
7464
  function cleanUrl(url) {
7465
7465
  return url.replace(postfixRE, "");
7466
7466
  }
7467
- function withTrailingSlash(path14) {
7468
- return path14.endsWith("/") ? path14 : `${path14}/`;
7467
+ function withTrailingSlash(path15) {
7468
+ return path15.endsWith("/") ? path15 : `${path15}/`;
7469
7469
  }
7470
7470
  function createRequestHandler(handler) {
7471
7471
  return async (req, res, next) => {
@@ -8152,13 +8152,13 @@ var getQueryString = (params) => {
8152
8152
  };
8153
8153
  var getUrl = (config, options) => {
8154
8154
  const encoder = config.ENCODE_PATH || encodeURI;
8155
- const path14 = options.url.replace("{api-version}", config.VERSION).replace(/{(.*?)}/g, (substring, group) => {
8155
+ const path15 = options.url.replace("{api-version}", config.VERSION).replace(/{(.*?)}/g, (substring, group) => {
8156
8156
  if (options.path?.hasOwnProperty(group)) {
8157
8157
  return encoder(String(options.path[group]));
8158
8158
  }
8159
8159
  return substring;
8160
8160
  });
8161
- const url = `${config.BASE}${path14}`;
8161
+ const url = `${config.BASE}${path15}`;
8162
8162
  if (options.query) {
8163
8163
  return `${url}${getQueryString(options.query)}`;
8164
8164
  }
@@ -9463,9 +9463,9 @@ function getPreviewModules(main, modulesRules) {
9463
9463
  path: entryPath
9464
9464
  },
9465
9465
  ...modulesRules.flatMap(
9466
- ({ type, include }) => globSync(include, { cwd: rootPath, ignore: entryPath }).map((path14) => ({
9466
+ ({ type, include }) => globSync(include, { cwd: rootPath, ignore: entryPath }).map((path15) => ({
9467
9467
  type,
9468
- path: path14
9468
+ path: path15
9469
9469
  }))
9470
9470
  )
9471
9471
  ]
@@ -15136,17 +15136,17 @@ function withTrailingSlash2(input = "", respectQueryAndFragment) {
15136
15136
  if (hasTrailingSlash(input, true)) {
15137
15137
  return input || "/";
15138
15138
  }
15139
- let path14 = input;
15139
+ let path15 = input;
15140
15140
  let fragment = "";
15141
15141
  const fragmentIndex = input.indexOf("#");
15142
15142
  if (fragmentIndex >= 0) {
15143
- path14 = input.slice(0, fragmentIndex);
15143
+ path15 = input.slice(0, fragmentIndex);
15144
15144
  fragment = input.slice(fragmentIndex);
15145
- if (!path14) {
15145
+ if (!path15) {
15146
15146
  return fragment;
15147
15147
  }
15148
15148
  }
15149
- const [s0, ...s] = path14.split("?");
15149
+ const [s0, ...s] = path15.split("?");
15150
15150
  return s0 + "/" + (s.length > 0 ? `?${s.join("?")}` : "") + fragment;
15151
15151
  }
15152
15152
  function isNonEmptyURL(url) {
@@ -15180,8 +15180,8 @@ import path9, { dirname as dirname6 } from "node:path";
15180
15180
  import v8 from "node:v8";
15181
15181
  import { format as format2, inspect } from "node:util";
15182
15182
  var BUILTIN_MODULES = new Set(builtinModules);
15183
- function normalizeSlash(path14) {
15184
- return path14.replace(/\\/g, "/");
15183
+ function normalizeSlash(path15) {
15184
+ return path15.replace(/\\/g, "/");
15185
15185
  }
15186
15186
  var own$1 = {}.hasOwnProperty;
15187
15187
  var classRegExp = /^([A-Z][a-z\d]*)+$/;
@@ -15294,8 +15294,8 @@ codes.ERR_INVALID_PACKAGE_CONFIG = createError(
15294
15294
  * @param {string} [base]
15295
15295
  * @param {string} [message]
15296
15296
  */
15297
- (path14, base, message) => {
15298
- return `Invalid package config ${path14}${base ? ` while importing ${base}` : ""}${message ? `. ${message}` : ""}`;
15297
+ (path15, base, message) => {
15298
+ return `Invalid package config ${path15}${base ? ` while importing ${base}` : ""}${message ? `. ${message}` : ""}`;
15299
15299
  },
15300
15300
  Error
15301
15301
  );
@@ -15327,8 +15327,8 @@ codes.ERR_MODULE_NOT_FOUND = createError(
15327
15327
  * @param {string} base
15328
15328
  * @param {boolean} [exactUrl]
15329
15329
  */
15330
- (path14, base, exactUrl = false) => {
15331
- return `Cannot find ${exactUrl ? "module" : "package"} '${path14}' imported from ${base}`;
15330
+ (path15, base, exactUrl = false) => {
15331
+ return `Cannot find ${exactUrl ? "module" : "package"} '${path15}' imported from ${base}`;
15332
15332
  },
15333
15333
  Error
15334
15334
  );
@@ -15379,8 +15379,8 @@ codes.ERR_UNKNOWN_FILE_EXTENSION = createError(
15379
15379
  * @param {string} extension
15380
15380
  * @param {string} path
15381
15381
  */
15382
- (extension, path14) => {
15383
- return `Unknown file extension "${extension}" for ${path14}`;
15382
+ (extension, path15) => {
15383
+ return `Unknown file extension "${extension}" for ${path15}`;
15384
15384
  },
15385
15385
  TypeError
15386
15386
  );
@@ -15752,9 +15752,9 @@ Default "index" lookups for the main are deprecated for ES modules.`,
15752
15752
  );
15753
15753
  }
15754
15754
  }
15755
- function tryStatSync(path14) {
15755
+ function tryStatSync(path15) {
15756
15756
  try {
15757
- return statSync2(path14);
15757
+ return statSync2(path15);
15758
15758
  } catch {
15759
15759
  }
15760
15760
  }
@@ -16679,8 +16679,8 @@ var nodeJsBuiltins = /* @__PURE__ */ new Set([
16679
16679
  var NODEJS_MODULES_RE = new RegExp(
16680
16680
  `^(node:)?(${builtinModules2.join("|")})$`
16681
16681
  );
16682
- function isNodeAlsModule(path14) {
16683
- return /^(node:)?async_hooks$/.test(path14);
16682
+ function isNodeAlsModule(path15) {
16683
+ return /^(node:)?async_hooks$/.test(path15);
16684
16684
  }
16685
16685
  function assertHasNodeJsCompat(nodeJsCompat) {
16686
16686
  assert8(nodeJsCompat, `expected nodeJsCompat to be defined`);
@@ -16725,9 +16725,25 @@ var NodeJsCompatWarnings = class {
16725
16725
  }
16726
16726
  };
16727
16727
 
16728
+ // src/output-config.ts
16729
+ import assert9 from "node:assert";
16730
+ import * as path11 from "node:path";
16731
+ import "vite";
16732
+ function getAssetsDirectory(workerOutputDirectory, resolvedViteConfig) {
16733
+ const clientOutputDirectory = resolvedViteConfig.environments.client?.build.outDir;
16734
+ assert9(
16735
+ clientOutputDirectory,
16736
+ "Unexpected error: client output directory is undefined"
16737
+ );
16738
+ return path11.relative(
16739
+ path11.resolve(resolvedViteConfig.root, workerOutputDirectory),
16740
+ path11.resolve(resolvedViteConfig.root, clientOutputDirectory)
16741
+ );
16742
+ }
16743
+
16728
16744
  // src/plugin-config.ts
16729
- import assert10 from "node:assert";
16730
- import * as path12 from "node:path";
16745
+ import assert11 from "node:assert";
16746
+ import * as path13 from "node:path";
16731
16747
 
16732
16748
  // ../workers-shared/utils/configuration/parseStaticRouting.ts
16733
16749
  function parseStaticRouting(input) {
@@ -16806,12 +16822,12 @@ var formatInvalidRoutes = (invalidRules) => {
16806
16822
  };
16807
16823
 
16808
16824
  // src/plugin-config.ts
16809
- import * as vite4 from "vite";
16825
+ import * as vite5 from "vite";
16810
16826
 
16811
16827
  // src/workers-configs.ts
16812
- import assert9 from "node:assert";
16828
+ import assert10 from "node:assert";
16813
16829
  import * as fs5 from "node:fs";
16814
- import * as path11 from "node:path";
16830
+ import * as path12 from "node:path";
16815
16831
  import { unstable_readConfig as unstable_readConfig2 } from "wrangler";
16816
16832
  var nonApplicableWorkerConfigs = {
16817
16833
  /**
@@ -16907,7 +16923,7 @@ function getWarningForWorkersConfigs(configs) {
16907
16923
  const lines2 = [
16908
16924
  `
16909
16925
 
16910
- \x1B[43mWARNING\x1B[0m: your worker config${configs.entryWorker.config.configPath ? ` (at \`${path11.relative("", configs.entryWorker.config.configPath)}\`)` : ""} contains the following configuration options which are ignored since they are not applicable when using Vite:`
16926
+ \x1B[43mWARNING\x1B[0m: your worker config${configs.entryWorker.config.configPath ? ` (at \`${path12.relative("", configs.entryWorker.config.configPath)}\`)` : ""} contains the following configuration options which are ignored since they are not applicable when using Vite:`
16911
16927
  ];
16912
16928
  nonApplicableLines.forEach((line) => lines2.push(line));
16913
16929
  lines2.push("");
@@ -16921,7 +16937,7 @@ function getWarningForWorkersConfigs(configs) {
16921
16937
  );
16922
16938
  if (nonApplicableLines.length > 0) {
16923
16939
  lines.push(
16924
- ` - (${isEntryWorker ? "entry" : "auxiliary"}) worker${workerConfig.config.name ? ` "${workerConfig.config.name}"` : ""}${workerConfig.config.configPath ? ` (config at \`${path11.relative("", workerConfig.config.configPath)}\`)` : ""}`
16940
+ ` - (${isEntryWorker ? "entry" : "auxiliary"}) worker${workerConfig.config.name ? ` "${workerConfig.config.name}"` : ""}${workerConfig.config.configPath ? ` (config at \`${path12.relative("", workerConfig.config.configPath)}\`)` : ""}`
16925
16941
  );
16926
16942
  nonApplicableLines.forEach((line) => lines.push(line));
16927
16943
  }
@@ -17013,7 +17029,7 @@ function maybeResolveMain(main, configPath) {
17013
17029
  if (!ENTRY_MODULE_EXTENSIONS.some((extension) => main.endsWith(extension))) {
17014
17030
  return main;
17015
17031
  }
17016
- const resolvedMain = path11.resolve(path11.dirname(configPath), main);
17032
+ const resolvedMain = path12.resolve(path12.dirname(configPath), main);
17017
17033
  if (!fs5.existsSync(resolvedMain)) {
17018
17034
  throw new Error(
17019
17035
  `The provided Wrangler config main field (${resolvedMain}) doesn't point to an existing file`
@@ -17023,10 +17039,10 @@ function maybeResolveMain(main, configPath) {
17023
17039
  }
17024
17040
  function getValidatedWranglerConfigPath(root, requestedConfigPath, isForAuxiliaryWorker = false) {
17025
17041
  if (requestedConfigPath) {
17026
- const configPath2 = path11.resolve(root, requestedConfigPath);
17042
+ const configPath2 = path12.resolve(root, requestedConfigPath);
17027
17043
  const forAuxiliaryWorkerErrorMessage = isForAuxiliaryWorker ? " requested for one of your auxiliary workers" : "";
17028
17044
  const errorMessagePrefix = `The provided configPath (${configPath2})${forAuxiliaryWorkerErrorMessage}`;
17029
- const fileExtension = path11.extname(configPath2).slice(1);
17045
+ const fileExtension = path12.extname(configPath2).slice(1);
17030
17046
  if (!allowedWranglerConfigExtensions.includes(fileExtension)) {
17031
17047
  const foundExtensionMessage = !fileExtension ? "no extension found" : `"${fileExtension}" found`;
17032
17048
  throw new Error(
@@ -17046,7 +17062,7 @@ function getValidatedWranglerConfigPath(root, requestedConfigPath, isForAuxiliar
17046
17062
  }
17047
17063
  return configPath2;
17048
17064
  }
17049
- assert9(
17065
+ assert10(
17050
17066
  isForAuxiliaryWorker === false,
17051
17067
  "Unexpected Error: trying to find the wrangler config for an auxiliary worker"
17052
17068
  );
@@ -17060,7 +17076,7 @@ function getValidatedWranglerConfigPath(root, requestedConfigPath, isForAuxiliar
17060
17076
  }
17061
17077
  function findWranglerConfig(root) {
17062
17078
  for (const extension of allowedWranglerConfigExtensions) {
17063
- const configPath = path11.join(root, `wrangler.${extension}`);
17079
+ const configPath = path12.join(root, `wrangler.${extension}`);
17064
17080
  if (fs5.existsSync(configPath)) {
17065
17081
  return configPath;
17066
17082
  }
@@ -17078,7 +17094,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
17078
17094
  inspectorPort: pluginConfig.inspectorPort,
17079
17095
  experimental: pluginConfig.experimental ?? {}
17080
17096
  };
17081
- const root = userConfig.root ? path12.resolve(userConfig.root) : process.cwd();
17097
+ const root = userConfig.root ? path13.resolve(userConfig.root) : process.cwd();
17082
17098
  if (viteEnv.isPreview) {
17083
17099
  return {
17084
17100
  ...shared,
@@ -17087,7 +17103,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
17087
17103
  };
17088
17104
  }
17089
17105
  const configPaths = /* @__PURE__ */ new Set();
17090
- const { CLOUDFLARE_ENV: cloudflareEnv } = vite4.loadEnv(
17106
+ const { CLOUDFLARE_ENV: cloudflareEnv } = vite5.loadEnv(
17091
17107
  viteEnv.mode,
17092
17108
  root,
17093
17109
  /* prefixes */
@@ -17143,7 +17159,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
17143
17159
  }
17144
17160
  );
17145
17161
  auxiliaryWorkersResolvedConfigs.push(workerResolvedConfig);
17146
- assert10(
17162
+ assert11(
17147
17163
  workerResolvedConfig.type === "worker",
17148
17164
  "Unexpected error: received AssetsOnlyResult with auxiliary workers."
17149
17165
  );
@@ -17178,26 +17194,26 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
17178
17194
  };
17179
17195
  }
17180
17196
  function assertIsNotPreview(resolvedPluginConfig) {
17181
- assert10(
17197
+ assert11(
17182
17198
  resolvedPluginConfig.type !== "preview",
17183
17199
  `Expected "assets-only" or "workers" plugin config`
17184
17200
  );
17185
17201
  }
17186
17202
  function assertIsPreview(resolvedPluginConfig) {
17187
- assert10(
17203
+ assert11(
17188
17204
  resolvedPluginConfig.type === "preview",
17189
17205
  `Expected "preview" plugin config`
17190
17206
  );
17191
17207
  }
17192
17208
 
17193
17209
  // src/vite-config.ts
17194
- import assert11 from "node:assert";
17210
+ import assert12 from "node:assert";
17195
17211
  function validateWorkerEnvironmentOptions(resolvedPluginConfig, resolvedViteConfig) {
17196
17212
  const workerEnvironmentNames = Object.keys(resolvedPluginConfig.workers);
17197
17213
  const disallowedEnvironmentOptionsMap = /* @__PURE__ */ new Map();
17198
17214
  for (const environmentName of workerEnvironmentNames) {
17199
17215
  const environmentOptions = resolvedViteConfig.environments[environmentName];
17200
- assert11(
17216
+ assert12(
17201
17217
  environmentOptions,
17202
17218
  `Missing environment config for "${environmentName}"`
17203
17219
  );
@@ -17392,46 +17408,36 @@ if (import.meta.hot) {
17392
17408
  },
17393
17409
  generateBundle(_, bundle) {
17394
17410
  assertIsNotPreview(resolvedPluginConfig);
17395
- let config;
17411
+ let outputConfig;
17396
17412
  if (resolvedPluginConfig.type === "workers") {
17397
- const workerConfig = resolvedPluginConfig.workers[this.environment.name];
17398
- if (!workerConfig) {
17413
+ const inputConfig = resolvedPluginConfig.workers[this.environment.name];
17414
+ if (!inputConfig) {
17399
17415
  return;
17400
17416
  }
17401
17417
  const entryChunk = Object.values(bundle).find(
17402
17418
  (chunk) => chunk.type === "chunk" && chunk.isEntry && chunk.name === MAIN_ENTRY_NAME
17403
17419
  );
17404
- assert12(
17420
+ assert13(
17405
17421
  entryChunk,
17406
17422
  `Expected entry chunk with name "${MAIN_ENTRY_NAME}"`
17407
17423
  );
17408
- workerConfig.main = entryChunk.fileName;
17409
- workerConfig.no_bundle = true;
17410
- workerConfig.rules = [
17411
- { type: "ESModule", globs: ["**/*.js", "**/*.mjs"] }
17412
- ];
17413
17424
  const isEntryWorker = this.environment.name === resolvedPluginConfig.entryWorkerEnvironmentName;
17414
- if (isEntryWorker) {
17415
- const workerOutputDirectory = this.environment.config.build.outDir;
17416
- const clientOutputDirectory = resolvedViteConfig.environments.client?.build.outDir;
17417
- assert12(
17418
- clientOutputDirectory,
17419
- "Unexpected error: client output directory is undefined"
17420
- );
17421
- workerConfig.assets = {
17422
- ...workerConfig.assets,
17423
- directory: path13.relative(
17424
- path13.resolve(resolvedViteConfig.root, workerOutputDirectory),
17425
- path13.resolve(resolvedViteConfig.root, clientOutputDirectory)
17425
+ outputConfig = {
17426
+ ...inputConfig,
17427
+ main: entryChunk.fileName,
17428
+ no_bundle: true,
17429
+ rules: [{ type: "ESModule", globs: ["**/*.js", "**/*.mjs"] }],
17430
+ assets: isEntryWorker ? {
17431
+ ...inputConfig.assets,
17432
+ directory: getAssetsDirectory(
17433
+ this.environment.config.build.outDir,
17434
+ resolvedViteConfig
17426
17435
  )
17427
- };
17428
- } else {
17429
- workerConfig.assets = void 0;
17430
- }
17431
- config = workerConfig;
17432
- if (workerConfig.configPath) {
17436
+ } : void 0
17437
+ };
17438
+ if (inputConfig.configPath) {
17433
17439
  const localDevVars = getLocalDevVarsForPreview(
17434
- workerConfig.configPath,
17440
+ inputConfig.configPath,
17435
17441
  resolvedPluginConfig.cloudflareEnv
17436
17442
  );
17437
17443
  if (localDevVars) {
@@ -17443,10 +17449,13 @@ if (import.meta.hot) {
17443
17449
  }
17444
17450
  }
17445
17451
  } else if (this.environment.name === "client") {
17446
- const assetsOnlyConfig = resolvedPluginConfig.config;
17447
- assetsOnlyConfig.assets = {
17448
- ...assetsOnlyConfig.assets,
17449
- directory: "."
17452
+ const inputConfig = resolvedPluginConfig.config;
17453
+ outputConfig = {
17454
+ ...inputConfig,
17455
+ assets: {
17456
+ ...inputConfig.assets,
17457
+ directory: "."
17458
+ }
17450
17459
  };
17451
17460
  const filesToAssetsIgnore = ["wrangler.json", ".dev.vars"];
17452
17461
  this.emitFile({
@@ -17455,18 +17464,17 @@ if (import.meta.hot) {
17455
17464
  source: `${filesToAssetsIgnore.join("\n")}
17456
17465
  `
17457
17466
  });
17458
- config = assetsOnlyConfig;
17459
17467
  }
17460
- if (!config) {
17468
+ if (!outputConfig) {
17461
17469
  return;
17462
17470
  }
17463
- if (config.unsafe && Object.keys(config.unsafe).length === 0) {
17464
- config.unsafe = void 0;
17471
+ if (outputConfig.unsafe && Object.keys(outputConfig.unsafe).length === 0) {
17472
+ outputConfig.unsafe = void 0;
17465
17473
  }
17466
17474
  this.emitFile({
17467
17475
  type: "asset",
17468
17476
  fileName: "wrangler.json",
17469
- source: JSON.stringify(config)
17477
+ source: JSON.stringify(outputConfig)
17470
17478
  });
17471
17479
  },
17472
17480
  writeBundle() {
@@ -17533,13 +17541,13 @@ if (import.meta.hot) {
17533
17541
  }
17534
17542
  let preMiddleware;
17535
17543
  if (resolvedPluginConfig.type === "workers") {
17536
- assert12(entryWorkerConfig, `No entry Worker config`);
17544
+ assert13(entryWorkerConfig, `No entry Worker config`);
17537
17545
  debuglog4("Initializing the Vite module runners");
17538
17546
  await initRunners(resolvedPluginConfig, viteDevServer, miniflare);
17539
17547
  const entryWorkerName = entryWorkerConfig.name;
17540
17548
  if (viteDevServer.httpServer) {
17541
17549
  handleWebSocket(viteDevServer.httpServer, async () => {
17542
- assert12(miniflare, `Miniflare not defined`);
17550
+ assert13(miniflare, `Miniflare not defined`);
17543
17551
  const entryWorker = await miniflare.getWorker(entryWorkerName);
17544
17552
  return entryWorker.fetch;
17545
17553
  });
@@ -17553,12 +17561,12 @@ if (import.meta.hot) {
17553
17561
  staticRouting.user_worker
17554
17562
  );
17555
17563
  const userWorkerHandler = createRequestHandler(async (request2) => {
17556
- assert12(miniflare, `Miniflare not defined`);
17564
+ assert13(miniflare, `Miniflare not defined`);
17557
17565
  const userWorker = await miniflare.getWorker(entryWorkerName);
17558
17566
  return userWorker.fetch(request2, { redirect: "manual" });
17559
17567
  });
17560
17568
  preMiddleware = async (req, res, next) => {
17561
- assert12(req.url, `req.url not defined`);
17569
+ assert13(req.url, `req.url not defined`);
17562
17570
  const request2 = new Request(new URL(req.url, UNKNOWN_HOST));
17563
17571
  if (req[kRequestType] === "asset") {
17564
17572
  next();
@@ -17607,7 +17615,7 @@ if (import.meta.hot) {
17607
17615
  const cachedTransformMiddlewareIndex = middlewareStack.findIndex(
17608
17616
  (middleware) => "name" in middleware.handle && middleware.handle.name === "viteCachedTransformMiddleware"
17609
17617
  );
17610
- assert12(
17618
+ assert13(
17611
17619
  cachedTransformMiddlewareIndex !== -1,
17612
17620
  "Failed to find viteCachedTransformMiddleware"
17613
17621
  );
@@ -17618,7 +17626,7 @@ if (import.meta.hot) {
17618
17626
  }
17619
17627
  viteDevServer.middlewares.use(
17620
17628
  createRequestHandler(async (request2, req) => {
17621
- assert12(miniflare, `Miniflare not defined`);
17629
+ assert13(miniflare, `Miniflare not defined`);
17622
17630
  if (req[kRequestType] === "asset") {
17623
17631
  const assetWorker = await miniflare.getWorker(ASSET_WORKER_NAME);
17624
17632
  return assetWorker.fetch(request2, { redirect: "manual" });
@@ -17680,12 +17688,12 @@ if (import.meta.hot) {
17680
17688
  });
17681
17689
  }
17682
17690
  handleWebSocket(vitePreviewServer.httpServer, () => {
17683
- assert12(miniflare, `Miniflare not defined`);
17691
+ assert13(miniflare, `Miniflare not defined`);
17684
17692
  return miniflare.dispatchFetch;
17685
17693
  });
17686
17694
  vitePreviewServer.middlewares.use(
17687
17695
  createRequestHandler((request2) => {
17688
- assert12(miniflare, `Miniflare not defined`);
17696
+ assert13(miniflare, `Miniflare not defined`);
17689
17697
  return miniflare.dispatchFetch(request2, { redirect: "manual" });
17690
17698
  })
17691
17699
  );
@@ -17778,7 +17786,7 @@ if (import.meta.hot) {
17778
17786
  for (const match of matches) {
17779
17787
  magicString ??= new MagicString(code);
17780
17788
  const [full, _, modulePath] = match;
17781
- assert12(
17789
+ assert13(
17782
17790
  modulePath,
17783
17791
  `Unexpected error: module path not found in reference ${full}.`
17784
17792
  );
@@ -17792,13 +17800,13 @@ if (import.meta.hot) {
17792
17800
  }
17793
17801
  const referenceId = this.emitFile({
17794
17802
  type: "asset",
17795
- name: path13.basename(modulePath),
17803
+ name: path14.basename(modulePath),
17796
17804
  originalFileName: modulePath,
17797
17805
  source
17798
17806
  });
17799
17807
  const emittedFileName = this.getFileName(referenceId);
17800
- const relativePath = vite5.normalizePath(
17801
- path13.relative(path13.dirname(chunk.fileName), emittedFileName)
17808
+ const relativePath = vite6.normalizePath(
17809
+ path14.relative(path14.dirname(chunk.fileName), emittedFileName)
17802
17810
  );
17803
17811
  const importPath = relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
17804
17812
  magicString.update(
@@ -17857,7 +17865,7 @@ if (import.meta.hot) {
17857
17865
  return this.resolve(source, importer, options);
17858
17866
  }
17859
17867
  if (this.environment.mode === "dev") {
17860
- assert12(
17868
+ assert13(
17861
17869
  this.environment.depsOptimizer,
17862
17870
  "depsOptimizer is required in dev mode"
17863
17871
  );
@@ -17940,13 +17948,13 @@ export default mod.default ?? {};
17940
17948
  setup(build) {
17941
17949
  build.onResolve(
17942
17950
  { filter: NODEJS_MODULES_RE },
17943
- ({ path: path14, importer }) => {
17944
- if (hasNodeJsAls(workerConfig) && isNodeAlsModule(path14)) {
17951
+ ({ path: path15, importer }) => {
17952
+ if (hasNodeJsAls(workerConfig) && isNodeAlsModule(path15)) {
17945
17953
  return;
17946
17954
  }
17947
17955
  const nodeJsCompatWarnings = nodeJsCompatWarningsMap.get(workerConfig);
17948
- nodeJsCompatWarnings?.registerImport(path14, importer);
17949
- return { path: path14, external: true };
17956
+ nodeJsCompatWarnings?.registerImport(path15, importer);
17957
+ return { path: path15, external: true };
17950
17958
  }
17951
17959
  );
17952
17960
  }
@@ -18031,7 +18039,7 @@ export default mod.default ?? {};
18031
18039
  addDebugToVitePrintUrls(vitePreviewServer);
18032
18040
  }
18033
18041
  const workerNames = resolvedPluginConfig.workers.map((worker) => {
18034
- assert12(worker.name, "Expected the Worker to have a name");
18042
+ assert13(worker.name, "Expected the Worker to have a name");
18035
18043
  return worker.name;
18036
18044
  });
18037
18045
  vitePreviewServer.middlewares.use(DEBUG_PATH, async (_, res, next) => {
@@ -18057,11 +18065,11 @@ export default mod.default ?? {};
18057
18065
  assertIsNotPreview(resolvedPluginConfig);
18058
18066
  if (resolvedPluginConfig.type === "workers") {
18059
18067
  const entryWorkerConfig = getEntryWorkerConfig(resolvedPluginConfig);
18060
- assert12(entryWorkerConfig, `No entry Worker config`);
18068
+ assert13(entryWorkerConfig, `No entry Worker config`);
18061
18069
  const entryWorkerName = entryWorkerConfig.name;
18062
18070
  viteDevServer.middlewares.use("/cdn-cgi/", (req, res, next) => {
18063
18071
  const requestHandler = createRequestHandler((request2) => {
18064
- assert12(miniflare, `Miniflare not defined`);
18072
+ assert13(miniflare, `Miniflare not defined`);
18065
18073
  request2.headers.set(CoreHeaders.ROUTE_OVERRIDE, entryWorkerName);
18066
18074
  return miniflare.dispatchFetch(request2, { redirect: "manual" });
18067
18075
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudflare/vite-plugin",
3
- "version": "1.13.2",
3
+ "version": "1.13.3",
4
4
  "description": "Cloudflare plugin for Vite",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -39,12 +39,12 @@
39
39
  "tinyglobby": "^0.2.12",
40
40
  "unenv": "2.0.0-rc.21",
41
41
  "ws": "8.18.0",
42
- "@cloudflare/unenv-preset": "2.7.3",
43
- "miniflare": "4.20250913.0",
44
- "wrangler": "4.37.1"
42
+ "@cloudflare/unenv-preset": "2.7.4",
43
+ "miniflare": "4.20250917.0",
44
+ "wrangler": "4.38.0"
45
45
  },
46
46
  "devDependencies": {
47
- "@cloudflare/workers-types": "^4.20250913.0",
47
+ "@cloudflare/workers-types": "^4.20250917.0",
48
48
  "@types/node": "^22.10.1",
49
49
  "@types/ws": "^8.5.13",
50
50
  "magic-string": "^0.30.12",
@@ -53,14 +53,14 @@
53
53
  "typescript": "^5.8.3",
54
54
  "vite": "7.0.0",
55
55
  "vitest": "~3.2.0",
56
- "@cloudflare/containers-shared": "0.2.10",
57
56
  "@cloudflare/mock-npm-registry": "0.0.0",
57
+ "@cloudflare/containers-shared": "0.2.10",
58
58
  "@cloudflare/workers-shared": "0.18.8",
59
59
  "@cloudflare/workers-tsconfig": "0.0.0"
60
60
  },
61
61
  "peerDependencies": {
62
62
  "vite": "^6.1.0 || ^7.0.0",
63
- "wrangler": "^4.37.1"
63
+ "wrangler": "^4.38.0"
64
64
  },
65
65
  "publishConfig": {
66
66
  "access": "public"