@cloudflare/vite-plugin 0.1.17 → 0.1.19

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 +252 -110
  2. package/package.json +5 -5
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 = (path9, originalPath, doThrow) => {
252
- if (!isString(path9)) {
251
+ var checkPath = (path10, originalPath, doThrow) => {
252
+ if (!isString(path10)) {
253
253
  return doThrow(
254
254
  `path must be a string, but got \`${originalPath}\``,
255
255
  TypeError
256
256
  );
257
257
  }
258
- if (!path9) {
258
+ if (!path10) {
259
259
  return doThrow(`path must not be empty`, TypeError);
260
260
  }
261
- if (checkPath.isNotRelative(path9)) {
261
+ if (checkPath.isNotRelative(path10)) {
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 = (path9) => REGEX_TEST_INVALID_PATH.test(path9);
270
+ var isNotRelative = (path10) => REGEX_TEST_INVALID_PATH.test(path10);
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(path9, checkUnignored) {
329
+ _testOne(path10, 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(path9);
337
+ const matched = rule.regex.test(path10);
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 path9 = originalPath && checkPath.convert(originalPath);
350
+ const path10 = originalPath && checkPath.convert(originalPath);
351
351
  checkPath(
352
- path9,
352
+ path10,
353
353
  originalPath,
354
354
  this._allowRelativePaths ? RETURN_FALSE : throwError
355
355
  );
356
- return this._t(path9, cache2, checkUnignored, slices);
356
+ return this._t(path10, cache2, checkUnignored, slices);
357
357
  }
358
- _t(path9, cache2, checkUnignored, slices) {
359
- if (path9 in cache2) {
360
- return cache2[path9];
358
+ _t(path10, cache2, checkUnignored, slices) {
359
+ if (path10 in cache2) {
360
+ return cache2[path10];
361
361
  }
362
362
  if (!slices) {
363
- slices = path9.split(SLASH);
363
+ slices = path10.split(SLASH);
364
364
  }
365
365
  slices.pop();
366
366
  if (!slices.length) {
367
- return cache2[path9] = this._testOne(path9, checkUnignored);
367
+ return cache2[path10] = this._testOne(path10, 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[path9] = parent.ignored ? parent : this._testOne(path9, checkUnignored);
375
+ return cache2[path10] = parent.ignored ? parent : this._testOne(path10, checkUnignored);
376
376
  }
377
- ignores(path9) {
378
- return this._test(path9, this._ignoreCache, false).ignored;
377
+ ignores(path10) {
378
+ return this._test(path10, this._ignoreCache, false).ignored;
379
379
  }
380
380
  createFilter() {
381
- return (path9) => !this.ignores(path9);
381
+ return (path10) => !this.ignores(path10);
382
382
  }
383
383
  filter(paths) {
384
384
  return makeArray(paths).filter(this.createFilter());
385
385
  }
386
386
  // @returns {TestResult}
387
- test(path9) {
388
- return this._test(path9, this._testCache, true);
387
+ test(path10) {
388
+ return this._test(path10, this._testCache, true);
389
389
  }
390
390
  };
391
391
  var factory = (options) => new Ignore(options);
392
- var isPathValid = (path9) => checkPath(path9 && checkPath.convert(path9), path9, RETURN_FALSE);
392
+ var isPathValid = (path10) => checkPath(path10 && checkPath.convert(path10), path10, 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 = (path9) => REGIX_IS_WINDOWS_PATH_ABSOLUTE.test(path9) || isNotRelative(path9);
403
+ checkPath.isNotRelative = (path10) => REGIX_IS_WINDOWS_PATH_ABSOLUTE.test(path10) || isNotRelative(path10);
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(path9) {
447
- path9 = String(path9);
448
- let last = path9.replace(/^.*[/\\]/, "").toLowerCase();
446
+ Mime.prototype.getType = function(path10) {
447
+ path10 = String(path10);
448
+ let last = path10.replace(/^.*[/\\]/, "").toLowerCase();
449
449
  let ext = last.replace(/^.*\./, "").toLowerCase();
450
- let hasPath = last.length < path9.length;
450
+ let hasPath = last.length < path10.length;
451
451
  let hasDot = ext.length < last.length - 1;
452
452
  return (hasDot || !hasPath) && this._types[ext] || null;
453
453
  };
@@ -488,8 +488,7 @@ var require_mime = __commonJS({
488
488
  import assert8 from "node:assert";
489
489
  import * as fs5 from "node:fs";
490
490
  import * as fsp2 from "node:fs/promises";
491
- import { builtinModules as builtinModules2 } from "node:module";
492
- import * as path8 from "node:path";
491
+ import * as path9 from "node:path";
493
492
  import { createMiddleware } from "@hattip/adapter-node";
494
493
 
495
494
  // ../../node_modules/.pnpm/@jridgewell+sourcemap-codec@1.5.0/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
@@ -1558,7 +1557,7 @@ var MagicString = class _MagicString {
1558
1557
 
1559
1558
  // src/index.ts
1560
1559
  import { Miniflare } from "miniflare";
1561
- import * as vite6 from "vite";
1560
+ import * as vite7 from "vite";
1562
1561
 
1563
1562
  // src/constants.ts
1564
1563
  var ROUTER_WORKER_NAME = "__router-worker__";
@@ -1726,11 +1725,11 @@ ${invalidHeaderRulesList}`
1726
1725
  }
1727
1726
 
1728
1727
  // ../workers-shared/utils/configuration/validateURL.ts
1729
- var extractPathname = (path9 = "/", includeSearch, includeHash) => {
1730
- if (!path9.startsWith("/")) {
1731
- path9 = `/${path9}`;
1728
+ var extractPathname = (path10 = "/", includeSearch, includeHash) => {
1729
+ if (!path10.startsWith("/")) {
1730
+ path10 = `/${path10}`;
1732
1731
  }
1733
- const url = new URL(`//${path9}`, "relative://");
1732
+ const url = new URL(`//${path10}`, "relative://");
1734
1733
  return `${url.pathname}${includeSearch ? url.search : ""}${includeHash ? url.hash : ""}`;
1735
1734
  };
1736
1735
  var URL_REGEX = /^https:\/\/+(?<host>[^/]+)\/?(?<path>.*)/;
@@ -1763,8 +1762,8 @@ var validateUrl = (token, onlyRelative = false, disallowPorts = false, includeSe
1763
1762
  if (!token.startsWith("/") && onlyRelative) {
1764
1763
  token = `/${token}`;
1765
1764
  }
1766
- const path9 = PATH_REGEX.exec(token);
1767
- if (path9) {
1765
+ const path10 = PATH_REGEX.exec(token);
1766
+ if (path10) {
1768
1767
  try {
1769
1768
  return [extractPathname(token, includeSearch, includeHash), void 0];
1770
1769
  } catch {
@@ -1825,7 +1824,7 @@ function parseHeaders(input, {
1825
1824
  });
1826
1825
  }
1827
1826
  }
1828
- const [path9, pathError] = validateUrl(line, false, true);
1827
+ const [path10, pathError] = validateUrl(line, false, true);
1829
1828
  if (pathError) {
1830
1829
  invalid.push({
1831
1830
  line,
@@ -1836,7 +1835,7 @@ function parseHeaders(input, {
1836
1835
  continue;
1837
1836
  }
1838
1837
  rule = {
1839
- path: path9,
1838
+ path: path10,
1840
1839
  line,
1841
1840
  headers: {},
1842
1841
  unsetHeaders: []
@@ -2411,8 +2410,8 @@ function getErrorMap() {
2411
2410
  return overrideErrorMap;
2412
2411
  }
2413
2412
  var makeIssue = (params) => {
2414
- const { data: data2, path: path9, errorMaps, issueData } = params;
2415
- const fullPath = [...path9, ...issueData.path || []];
2413
+ const { data: data2, path: path10, errorMaps, issueData } = params;
2414
+ const fullPath = [...path10, ...issueData.path || []];
2416
2415
  const fullIssue = {
2417
2416
  ...issueData,
2418
2417
  path: fullPath
@@ -2511,11 +2510,11 @@ var errorUtil;
2511
2510
  errorUtil2.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
2512
2511
  })(errorUtil || (errorUtil = {}));
2513
2512
  var ParseInputLazyPath = class {
2514
- constructor(parent, value, path9, key) {
2513
+ constructor(parent, value, path10, key) {
2515
2514
  this._cachedPath = [];
2516
2515
  this.parent = parent;
2517
2516
  this.data = value;
2518
- this._path = path9;
2517
+ this._path = path10;
2519
2518
  this._key = key;
2520
2519
  }
2521
2520
  get path() {
@@ -5905,10 +5904,12 @@ function getHeadersConfigPath(config) {
5905
5904
 
5906
5905
  // src/cloudflare-environment.ts
5907
5906
  import assert3 from "node:assert";
5908
- import * as vite2 from "vite";
5907
+ import * as vite3 from "vite";
5909
5908
 
5910
5909
  // src/node-js-compat.ts
5911
5910
  import assert2 from "node:assert";
5911
+ import { builtinModules as builtinModules2 } from "node:module";
5912
+ import path3 from "node:path";
5912
5913
  import { cloudflare } from "@cloudflare/unenv-preset";
5913
5914
  import { getNodeCompat } from "miniflare";
5914
5915
 
@@ -11460,17 +11461,17 @@ function withTrailingSlash(input = "", respectQueryAndFragment) {
11460
11461
  if (hasTrailingSlash(input, true)) {
11461
11462
  return input || "/";
11462
11463
  }
11463
- let path9 = input;
11464
+ let path10 = input;
11464
11465
  let fragment = "";
11465
11466
  const fragmentIndex = input.indexOf("#");
11466
11467
  if (fragmentIndex >= 0) {
11467
- path9 = input.slice(0, fragmentIndex);
11468
+ path10 = input.slice(0, fragmentIndex);
11468
11469
  fragment = input.slice(fragmentIndex);
11469
- if (!path9) {
11470
+ if (!path10) {
11470
11471
  return fragment;
11471
11472
  }
11472
11473
  }
11473
- const [s0, ...s] = path9.split("?");
11474
+ const [s0, ...s] = path10.split("?");
11474
11475
  return s0 + "/" + (s.length > 0 ? `?${s.join("?")}` : "") + fragment;
11475
11476
  }
11476
11477
  function isNonEmptyURL(url) {
@@ -11504,8 +11505,8 @@ import path2, { dirname as dirname2 } from "node:path";
11504
11505
  import v8 from "node:v8";
11505
11506
  import { format as format2, inspect } from "node:util";
11506
11507
  var BUILTIN_MODULES = new Set(builtinModules);
11507
- function normalizeSlash(path9) {
11508
- return path9.replace(/\\/g, "/");
11508
+ function normalizeSlash(path10) {
11509
+ return path10.replace(/\\/g, "/");
11509
11510
  }
11510
11511
  var own$1 = {}.hasOwnProperty;
11511
11512
  var classRegExp = /^([A-Z][a-z\d]*)+$/;
@@ -11618,8 +11619,8 @@ codes.ERR_INVALID_PACKAGE_CONFIG = createError(
11618
11619
  * @param {string} [base]
11619
11620
  * @param {string} [message]
11620
11621
  */
11621
- (path9, base, message) => {
11622
- return `Invalid package config ${path9}${base ? ` while importing ${base}` : ""}${message ? `. ${message}` : ""}`;
11622
+ (path10, base, message) => {
11623
+ return `Invalid package config ${path10}${base ? ` while importing ${base}` : ""}${message ? `. ${message}` : ""}`;
11623
11624
  },
11624
11625
  Error
11625
11626
  );
@@ -11651,8 +11652,8 @@ codes.ERR_MODULE_NOT_FOUND = createError(
11651
11652
  * @param {string} base
11652
11653
  * @param {boolean} [exactUrl]
11653
11654
  */
11654
- (path9, base, exactUrl = false) => {
11655
- return `Cannot find ${exactUrl ? "module" : "package"} '${path9}' imported from ${base}`;
11655
+ (path10, base, exactUrl = false) => {
11656
+ return `Cannot find ${exactUrl ? "module" : "package"} '${path10}' imported from ${base}`;
11656
11657
  },
11657
11658
  Error
11658
11659
  );
@@ -11703,8 +11704,8 @@ codes.ERR_UNKNOWN_FILE_EXTENSION = createError(
11703
11704
  * @param {string} extension
11704
11705
  * @param {string} path
11705
11706
  */
11706
- (extension, path9) => {
11707
- return `Unknown file extension "${extension}" for ${path9}`;
11707
+ (extension, path10) => {
11708
+ return `Unknown file extension "${extension}" for ${path10}`;
11708
11709
  },
11709
11710
  TypeError
11710
11711
  );
@@ -12076,9 +12077,9 @@ Default "index" lookups for the main are deprecated for ES modules.`,
12076
12077
  );
12077
12078
  }
12078
12079
  }
12079
- function tryStatSync(path9) {
12080
+ function tryStatSync(path10) {
12080
12081
  try {
12081
- return statSync(path9);
12082
+ return statSync(path10);
12082
12083
  } catch {
12083
12084
  }
12084
12085
  }
@@ -12845,12 +12846,20 @@ function resolvePathSync(id, options) {
12845
12846
 
12846
12847
  // src/node-js-compat.ts
12847
12848
  import { defineEnv } from "unenv";
12849
+ import "vite";
12848
12850
  var { env } = defineEnv({
12849
12851
  nodeCompat: true,
12850
12852
  presets: [cloudflare]
12851
12853
  });
12852
12854
  var nodeCompatExternals = new Set(env.external);
12853
12855
  var nodeCompatEntries = getNodeCompatEntries();
12856
+ var nodejsBuiltins = /* @__PURE__ */ new Set([
12857
+ ...builtinModules2,
12858
+ ...builtinModules2.map((m) => `node:${m}`)
12859
+ ]);
12860
+ var NODEJS_MODULES_RE = new RegExp(
12861
+ `^(node:)?(${builtinModules2.join("|")})$`
12862
+ );
12854
12863
  function isNodeCompat(workerConfig) {
12855
12864
  if (workerConfig === void 0) {
12856
12865
  return false;
@@ -12929,6 +12938,46 @@ function getNodeCompatEntries() {
12929
12938
  nodeCompatExternals.forEach((external) => entries.delete(external));
12930
12939
  return entries;
12931
12940
  }
12941
+ var NodeJsCompatWarnings = class {
12942
+ constructor(environment) {
12943
+ this.environment = environment;
12944
+ }
12945
+ sources = /* @__PURE__ */ new Map();
12946
+ timer;
12947
+ registerImport(source, importer = "<unknown>") {
12948
+ const importers = this.sources.get(source) ?? /* @__PURE__ */ new Set();
12949
+ this.sources.set(source, importers);
12950
+ importers.add(importer);
12951
+ }
12952
+ renderWarningsOnIdle() {
12953
+ if (this.timer) {
12954
+ clearTimeout(this.timer);
12955
+ }
12956
+ this.timer = setTimeout(() => {
12957
+ this.renderWarnings();
12958
+ this.timer = void 0;
12959
+ }, 500);
12960
+ }
12961
+ renderWarnings() {
12962
+ if (this.sources.size > 0) {
12963
+ let message = `
12964
+
12965
+ Unexpected Node.js imports for environment "${this.environment.name}". Do you need to enable the "nodejs_compat" compatibility flag?
12966
+ Refer to https://developers.cloudflare.com/workers/runtime-apis/nodejs/ for more details.
12967
+ `;
12968
+ this.sources.forEach((importers, source) => {
12969
+ importers.forEach((importer) => {
12970
+ message += ` - "${source}" imported from "${path3.relative(this.environment.config.root, importer)}"
12971
+ `;
12972
+ });
12973
+ });
12974
+ this.environment.logger.warn(message, {
12975
+ environment: this.environment.name
12976
+ });
12977
+ this.sources.clear();
12978
+ }
12979
+ }
12980
+ };
12932
12981
 
12933
12982
  // src/shared.ts
12934
12983
  var UNKNOWN_HOST = "http://localhost";
@@ -12942,17 +12991,21 @@ var additionalModuleGlobalRE = new RegExp(
12942
12991
  var VITE_DEV_METADATA_HEADER = "__VITE_DEV_METADATA__";
12943
12992
 
12944
12993
  // src/utils.ts
12945
- import * as path3 from "node:path";
12994
+ import * as path4 from "node:path";
12946
12995
  import { Request as MiniflareRequest } from "miniflare";
12947
12996
  import "vite";
12948
12997
  function getOutputDirectory(userConfig, environmentName) {
12949
12998
  const rootOutputDirectory = userConfig.build?.outDir ?? "dist";
12950
- return userConfig.environments?.[environmentName]?.build?.outDir ?? path3.join(rootOutputDirectory, environmentName);
12999
+ return userConfig.environments?.[environmentName]?.build?.outDir ?? path4.join(rootOutputDirectory, environmentName);
12951
13000
  }
12952
13001
  function getRouterWorker(miniflare2) {
12953
13002
  return miniflare2.getWorker(ROUTER_WORKER_NAME);
12954
13003
  }
12955
13004
  function toMiniflareRequest(request) {
13005
+ const host = request.headers.get("Host");
13006
+ if (host) {
13007
+ request.headers.set("X-Forwarded-Host", host);
13008
+ }
12956
13009
  const secFetchMode = request.headers.get("Sec-Fetch-Mode");
12957
13010
  if (secFetchMode) {
12958
13011
  request.headers.set("X-Mf-Sec-Fetch-Mode", secFetchMode);
@@ -13026,7 +13079,7 @@ function createHotChannel(webSocketContainer) {
13026
13079
  }
13027
13080
  };
13028
13081
  }
13029
- var CloudflareDevEnvironment = class extends vite2.DevEnvironment {
13082
+ var CloudflareDevEnvironment = class extends vite3.DevEnvironment {
13030
13083
  #webSocketContainer;
13031
13084
  #worker;
13032
13085
  constructor(name, config) {
@@ -13087,7 +13140,7 @@ function createCloudflareEnvironmentOptions(workerConfig, userConfig, environmen
13087
13140
  },
13088
13141
  build: {
13089
13142
  createEnvironment(name, config) {
13090
- return new vite2.BuildEnvironment(name, config);
13143
+ return new vite3.BuildEnvironment(name, config);
13091
13144
  },
13092
13145
  target,
13093
13146
  // We need to enable `emitAssets` in order to support additional modules defined by `rules`
@@ -13196,11 +13249,11 @@ function getDebugPathHtml(workerNames, inspectorPort) {
13196
13249
  // src/deploy-config.ts
13197
13250
  import assert5 from "node:assert";
13198
13251
  import * as fs2 from "node:fs";
13199
- import * as path4 from "node:path";
13252
+ import * as path5 from "node:path";
13200
13253
  import "vite";
13201
13254
  import { unstable_readConfig } from "wrangler";
13202
13255
  function getDeployConfigPath(root) {
13203
- return path4.resolve(root, ".wrangler", "deploy", "config.json");
13256
+ return path5.resolve(root, ".wrangler", "deploy", "config.json");
13204
13257
  }
13205
13258
  function getWorkerConfigs(root) {
13206
13259
  const deployConfigPath = getDeployConfigPath(root);
@@ -13211,22 +13264,22 @@ function getWorkerConfigs(root) {
13211
13264
  { configPath: deployConfig.configPath },
13212
13265
  ...deployConfig.auxiliaryWorkers
13213
13266
  ].map(({ configPath }) => {
13214
- const resolvedConfigPath = path4.resolve(
13215
- path4.dirname(deployConfigPath),
13267
+ const resolvedConfigPath = path5.resolve(
13268
+ path5.dirname(deployConfigPath),
13216
13269
  configPath
13217
13270
  );
13218
13271
  return unstable_readConfig({ config: resolvedConfigPath });
13219
13272
  });
13220
13273
  }
13221
13274
  function getRelativePathToWorkerConfig(deployConfigDirectory, root, outputDirectory) {
13222
- return path4.relative(
13275
+ return path5.relative(
13223
13276
  deployConfigDirectory,
13224
- path4.resolve(root, outputDirectory, "wrangler.json")
13277
+ path5.resolve(root, outputDirectory, "wrangler.json")
13225
13278
  );
13226
13279
  }
13227
13280
  function writeDeployConfig(resolvedPluginConfig, resolvedViteConfig) {
13228
13281
  const deployConfigPath = getDeployConfigPath(resolvedViteConfig.root);
13229
- const deployConfigDirectory = path4.dirname(deployConfigPath);
13282
+ const deployConfigDirectory = path5.dirname(deployConfigPath);
13230
13283
  fs2.mkdirSync(deployConfigDirectory, { recursive: true });
13231
13284
  if (resolvedPluginConfig.type === "assets-only") {
13232
13285
  const clientOutputDirectory = resolvedViteConfig.environments.client?.build.outDir;
@@ -13279,7 +13332,7 @@ function writeDeployConfig(resolvedPluginConfig, resolvedViteConfig) {
13279
13332
  import assert6 from "node:assert";
13280
13333
  import * as fs3 from "node:fs";
13281
13334
  import * as fsp from "node:fs/promises";
13282
- import * as path5 from "node:path";
13335
+ import * as path6 from "node:path";
13283
13336
  import { fileURLToPath as fileURLToPath2 } from "node:url";
13284
13337
  import {
13285
13338
  kCurrentWorker,
@@ -13295,18 +13348,18 @@ function getPersistence(root, persistState) {
13295
13348
  return {};
13296
13349
  }
13297
13350
  const defaultPersistPath = ".wrangler/state";
13298
- const persistPath = path5.resolve(
13351
+ const persistPath = path6.resolve(
13299
13352
  root,
13300
13353
  typeof persistState === "object" ? persistState.path : defaultPersistPath,
13301
13354
  "v3"
13302
13355
  );
13303
13356
  return {
13304
- cachePersist: path5.join(persistPath, "cache"),
13305
- d1Persist: path5.join(persistPath, "d1"),
13306
- durableObjectsPersist: path5.join(persistPath, "do"),
13307
- kvPersist: path5.join(persistPath, "kv"),
13308
- r2Persist: path5.join(persistPath, "r2"),
13309
- workflowsPersist: path5.join(persistPath, "workflows")
13357
+ cachePersist: path6.join(persistPath, "cache"),
13358
+ d1Persist: path6.join(persistPath, "d1"),
13359
+ durableObjectsPersist: path6.join(persistPath, "do"),
13360
+ kvPersist: path6.join(persistPath, "kv"),
13361
+ r2Persist: path6.join(persistPath, "r2"),
13362
+ workflowsPersist: path6.join(persistPath, "workflows")
13310
13363
  };
13311
13364
  }
13312
13365
  function missingWorkerErrorMessage(workerName) {
@@ -13407,7 +13460,7 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer) {
13407
13460
  modules: [
13408
13461
  {
13409
13462
  type: "ESModule",
13410
- path: path5.join(miniflareModulesRoot, ROUTER_WORKER_PATH),
13463
+ path: path6.join(miniflareModulesRoot, ROUTER_WORKER_PATH),
13411
13464
  contents: fs3.readFileSync(
13412
13465
  fileURLToPath2(new URL(ROUTER_WORKER_PATH, import.meta.url))
13413
13466
  )
@@ -13430,7 +13483,7 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer) {
13430
13483
  modules: [
13431
13484
  {
13432
13485
  type: "ESModule",
13433
- path: path5.join(miniflareModulesRoot, ASSET_WORKER_PATH),
13486
+ path: path6.join(miniflareModulesRoot, ASSET_WORKER_PATH),
13434
13487
  contents: fs3.readFileSync(
13435
13488
  fileURLToPath2(new URL(ASSET_WORKER_PATH, import.meta.url))
13436
13489
  )
@@ -13442,7 +13495,7 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer) {
13442
13495
  serviceBindings: {
13443
13496
  __VITE_ASSET_EXISTS__: async (request) => {
13444
13497
  const { pathname } = new URL(request.url);
13445
- const filePath = path5.join(resolvedViteConfig.root, pathname);
13498
+ const filePath = path6.join(resolvedViteConfig.root, pathname);
13446
13499
  let exists;
13447
13500
  try {
13448
13501
  exists = fs3.statSync(filePath).isFile();
@@ -13453,7 +13506,7 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer) {
13453
13506
  },
13454
13507
  __VITE_FETCH_ASSET__: async (request) => {
13455
13508
  const { pathname } = new URL(request.url);
13456
- const filePath = path5.join(resolvedViteConfig.root, pathname);
13509
+ const filePath = path6.join(resolvedViteConfig.root, pathname);
13457
13510
  try {
13458
13511
  let html = await fsp.readFile(filePath, "utf-8");
13459
13512
  html = await viteDevServer.transformIndexHtml(pathname, html);
@@ -13585,12 +13638,12 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer) {
13585
13638
  modules: [
13586
13639
  {
13587
13640
  type: "ESModule",
13588
- path: path5.join(miniflareModulesRoot, WRAPPER_PATH),
13641
+ path: path6.join(miniflareModulesRoot, WRAPPER_PATH),
13589
13642
  contents: wrappers.join("\n")
13590
13643
  },
13591
13644
  {
13592
13645
  type: "ESModule",
13593
- path: path5.join(miniflareModulesRoot, RUNNER_PATH),
13646
+ path: path6.join(miniflareModulesRoot, RUNNER_PATH),
13594
13647
  contents: fs3.readFileSync(
13595
13648
  fileURLToPath2(new URL(RUNNER_PATH, import.meta.url))
13596
13649
  )
@@ -13645,8 +13698,8 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer) {
13645
13698
  }
13646
13699
  function getPreviewModules(main, modulesRules) {
13647
13700
  assert6(modulesRules, `Unexpected error: 'modulesRules' is undefined`);
13648
- const rootPath = path5.dirname(main);
13649
- const entryPath = path5.basename(main);
13701
+ const rootPath = path6.dirname(main);
13702
+ const entryPath = path6.basename(main);
13650
13703
  return {
13651
13704
  rootPath,
13652
13705
  modules: [
@@ -13655,9 +13708,9 @@ function getPreviewModules(main, modulesRules) {
13655
13708
  path: entryPath
13656
13709
  },
13657
13710
  ...modulesRules.flatMap(
13658
- ({ type, include }) => globSync(include, { cwd: rootPath, ignore: entryPath }).map((path9) => ({
13711
+ ({ type, include }) => globSync(include, { cwd: rootPath, ignore: entryPath }).map((path10) => ({
13659
13712
  type,
13660
- path: path9
13713
+ path: path10
13661
13714
  }))
13662
13715
  )
13663
13716
  ]
@@ -13733,12 +13786,12 @@ function miniflareLogLevelFromViteLogLevel(level = "info") {
13733
13786
 
13734
13787
  // src/plugin-config.ts
13735
13788
  import assert7 from "node:assert";
13736
- import * as path7 from "node:path";
13737
- import * as vite5 from "vite";
13789
+ import * as path8 from "node:path";
13790
+ import * as vite6 from "vite";
13738
13791
 
13739
13792
  // src/workers-configs.ts
13740
13793
  import * as fs4 from "node:fs";
13741
- import * as path6 from "node:path";
13794
+ import * as path7 from "node:path";
13742
13795
  import { unstable_readConfig as unstable_readConfig2 } from "wrangler";
13743
13796
  var nonApplicableWorkerConfigs = {
13744
13797
  /**
@@ -13832,7 +13885,7 @@ function getWarningForWorkersConfigs(configs) {
13832
13885
  const lines2 = [
13833
13886
  `
13834
13887
 
13835
- \x1B[43mWARNING\x1B[0m: your worker config${configs.entryWorker.config.configPath ? ` (at \`${path6.relative("", configs.entryWorker.config.configPath)}\`)` : ""} contains the following configuration options which are ignored since they are not applicable when using Vite:`
13888
+ \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:`
13836
13889
  ];
13837
13890
  nonApplicableLines.forEach((line) => lines2.push(line));
13838
13891
  lines2.push("");
@@ -13846,7 +13899,7 @@ function getWarningForWorkersConfigs(configs) {
13846
13899
  );
13847
13900
  if (nonApplicableLines.length > 0) {
13848
13901
  lines.push(
13849
- ` - (${isEntryWorker ? "entry" : "auxiliary"}) worker${workerConfig.config.name ? ` "${workerConfig.config.name}"` : ""}${workerConfig.config.configPath ? ` (config at \`${path6.relative("", workerConfig.config.configPath)}\`)` : ""}`
13902
+ ` - (${isEntryWorker ? "entry" : "auxiliary"}) worker${workerConfig.config.name ? ` "${workerConfig.config.name}"` : ""}${workerConfig.config.configPath ? ` (config at \`${path7.relative("", workerConfig.config.configPath)}\`)` : ""}`
13850
13903
  );
13851
13904
  nonApplicableLines.forEach((line) => lines.push(line));
13852
13905
  }
@@ -13947,7 +14000,7 @@ function getWorkerConfig(configPath, env2, opts) {
13947
14000
  }
13948
14001
  function findWranglerConfig(root) {
13949
14002
  for (const extension of ["json", "jsonc", "toml"]) {
13950
- const configPath = path6.join(root, `wrangler.${extension}`);
14003
+ const configPath = path7.join(root, `wrangler.${extension}`);
13951
14004
  if (fs4.existsSync(configPath)) {
13952
14005
  return configPath;
13953
14006
  }
@@ -13963,14 +14016,14 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
13963
14016
  const persistState = pluginConfig.persistState ?? true;
13964
14017
  const inspectorPort = pluginConfig.inspectorPort ?? DEFAULT_INSPECTOR_PORT;
13965
14018
  const experimental = pluginConfig.experimental ?? {};
13966
- const root = userConfig.root ? path7.resolve(userConfig.root) : process.cwd();
13967
- const { CLOUDFLARE_ENV: cloudflareEnv } = vite5.loadEnv(
14019
+ const root = userConfig.root ? path8.resolve(userConfig.root) : process.cwd();
14020
+ const { CLOUDFLARE_ENV: cloudflareEnv } = vite6.loadEnv(
13968
14021
  viteEnv.mode,
13969
14022
  root,
13970
14023
  /* prefixes */
13971
14024
  ""
13972
14025
  );
13973
- const configPath = pluginConfig.configPath ? path7.resolve(root, pluginConfig.configPath) : findWranglerConfig(root);
14026
+ const configPath = pluginConfig.configPath ? path8.resolve(root, pluginConfig.configPath) : findWranglerConfig(root);
13974
14027
  if (!configPath) {
13975
14028
  throw new Error(
13976
14029
  `Config not found. Have you created a wrangler.json(c) or wrangler.toml file?`
@@ -14002,7 +14055,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
14002
14055
  const auxiliaryWorkersResolvedConfigs = [];
14003
14056
  for (const auxiliaryWorker of pluginConfig.auxiliaryWorkers ?? []) {
14004
14057
  const workerResolvedConfig = getWorkerConfig(
14005
- path7.resolve(root, auxiliaryWorker.configPath),
14058
+ path8.resolve(root, auxiliaryWorker.configPath),
14006
14059
  cloudflareEnv,
14007
14060
  {
14008
14061
  visitedConfigPaths: configPaths
@@ -14081,6 +14134,7 @@ function cloudflare2(pluginConfig = {}) {
14081
14134
  let resolvedPluginConfig;
14082
14135
  let resolvedViteConfig;
14083
14136
  const additionalModulePaths = /* @__PURE__ */ new Set();
14137
+ const nodeJsCompatWarningsMap = /* @__PURE__ */ new Map();
14084
14138
  let hasClientBuild = false;
14085
14139
  return [
14086
14140
  {
@@ -14131,7 +14185,7 @@ function cloudflare2(pluginConfig = {}) {
14131
14185
  builder: {
14132
14186
  buildApp: userConfig.builder?.buildApp ?? (async (builder) => {
14133
14187
  const clientEnvironment = builder.environments.client;
14134
- const defaultHtmlPath = path8.resolve(
14188
+ const defaultHtmlPath = path9.resolve(
14135
14189
  builder.config.root,
14136
14190
  "index.html"
14137
14191
  );
@@ -14190,9 +14244,9 @@ function cloudflare2(pluginConfig = {}) {
14190
14244
  );
14191
14245
  workerConfig.assets = {
14192
14246
  ...workerConfig.assets,
14193
- directory: path8.relative(
14194
- path8.resolve(resolvedViteConfig.root, workerOutputDirectory),
14195
- path8.resolve(resolvedViteConfig.root, clientOutputDirectory)
14247
+ directory: path9.relative(
14248
+ path9.resolve(resolvedViteConfig.root, workerOutputDirectory),
14249
+ path9.resolve(resolvedViteConfig.root, clientOutputDirectory)
14196
14250
  )
14197
14251
  };
14198
14252
  } else {
@@ -14250,7 +14304,7 @@ function cloudflare2(pluginConfig = {}) {
14250
14304
  hotUpdate(options) {
14251
14305
  if (
14252
14306
  // Vite normalizes `options.file` so we use `path.resolve` for Windows compatibility
14253
- resolvedPluginConfig.configPaths.has(path8.resolve(options.file)) || hasAssetsConfigChanged(
14307
+ resolvedPluginConfig.configPaths.has(path9.resolve(options.file)) || hasAssetsConfigChanged(
14254
14308
  resolvedPluginConfig,
14255
14309
  resolvedViteConfig,
14256
14310
  options.file
@@ -14396,13 +14450,13 @@ function cloudflare2(pluginConfig = {}) {
14396
14450
  }
14397
14451
  const referenceId = this.emitFile({
14398
14452
  type: "asset",
14399
- name: path8.basename(modulePath),
14453
+ name: path9.basename(modulePath),
14400
14454
  originalFileName: modulePath,
14401
14455
  source
14402
14456
  });
14403
14457
  const emittedFileName = this.getFileName(referenceId);
14404
- const relativePath = vite6.normalizePath(
14405
- path8.relative(path8.dirname(chunk.fileName), emittedFileName)
14458
+ const relativePath = vite7.normalizePath(
14459
+ path9.relative(path9.dirname(chunk.fileName), emittedFileName)
14406
14460
  );
14407
14461
  const importPath = relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
14408
14462
  magicString.update(
@@ -14444,10 +14498,7 @@ function cloudflare2(pluginConfig = {}) {
14444
14498
  // Obviously we don't want/need the optimizer to try to process modules that are built-in;
14445
14499
  // But also we want to avoid following the ones that are polyfilled since the dependency-optimizer import analyzer does not
14446
14500
  // resolve these imports using our `resolveId()` hook causing the optimization step to fail.
14447
- exclude: [
14448
- ...builtinModules2,
14449
- ...builtinModules2.map((m) => `node:${m}`)
14450
- ]
14501
+ exclude: [...nodejsBuiltins]
14451
14502
  }
14452
14503
  };
14453
14504
  }
@@ -14517,7 +14568,7 @@ function cloudflare2(pluginConfig = {}) {
14517
14568
  addDebugToVitePrintUrls(vitePreviewServer);
14518
14569
  }
14519
14570
  const workerNames = workerConfigs.map((worker) => {
14520
- assert8(worker.name);
14571
+ assert8(worker.name, "Expected the Worker to have a name");
14521
14572
  return worker.name;
14522
14573
  });
14523
14574
  vitePreviewServer.middlewares.use((req, res, next) => {
@@ -14532,6 +14583,97 @@ function cloudflare2(pluginConfig = {}) {
14532
14583
  next();
14533
14584
  });
14534
14585
  }
14586
+ },
14587
+ // Plugin to warn if Node.js APIs are being used without nodejs_compat turned on
14588
+ {
14589
+ name: "vite-plugin-cloudflare:nodejs-compat-warnings",
14590
+ apply(_config, env2) {
14591
+ return !env2.isPreview;
14592
+ },
14593
+ configEnvironment(environmentName) {
14594
+ const workerConfig = getWorkerConfig2(environmentName);
14595
+ if (workerConfig && !isNodeCompat(workerConfig)) {
14596
+ return {
14597
+ optimizeDeps: {
14598
+ esbuildOptions: {
14599
+ plugins: [
14600
+ {
14601
+ name: "vite-plugin-cloudflare:nodejs-compat-warnings-resolver",
14602
+ setup(build) {
14603
+ build.onResolve(
14604
+ { filter: NODEJS_MODULES_RE },
14605
+ ({ path: path10, importer }) => {
14606
+ const nodeJsCompatWarnings = nodeJsCompatWarningsMap.get(workerConfig);
14607
+ assert8(
14608
+ nodeJsCompatWarnings,
14609
+ `expected nodeJsCompatWarnings to be defined for Worker "${workerConfig.name}"`
14610
+ );
14611
+ nodeJsCompatWarnings.registerImport(path10, importer);
14612
+ return { path: path10, external: true };
14613
+ }
14614
+ );
14615
+ build.onEnd(() => {
14616
+ const nodeJsCompatWarnings = nodeJsCompatWarningsMap.get(workerConfig);
14617
+ if (nodeJsCompatWarnings) {
14618
+ nodeJsCompatWarnings.renderWarnings();
14619
+ }
14620
+ });
14621
+ }
14622
+ }
14623
+ ]
14624
+ }
14625
+ }
14626
+ };
14627
+ }
14628
+ },
14629
+ configureServer(viteDevServer) {
14630
+ for (const environment of Object.values(viteDevServer.environments)) {
14631
+ const workerConfig = getWorkerConfig2(environment.name);
14632
+ if (workerConfig && !isNodeCompat(workerConfig)) {
14633
+ nodeJsCompatWarningsMap.set(
14634
+ workerConfig,
14635
+ new NodeJsCompatWarnings(environment)
14636
+ );
14637
+ }
14638
+ }
14639
+ },
14640
+ buildStart() {
14641
+ const workerConfig = getWorkerConfig2(this.environment.name);
14642
+ if (workerConfig && !isNodeCompat(workerConfig)) {
14643
+ nodeJsCompatWarningsMap.set(
14644
+ workerConfig,
14645
+ new NodeJsCompatWarnings(this.environment)
14646
+ );
14647
+ }
14648
+ },
14649
+ buildEnd() {
14650
+ const workerConfig = getWorkerConfig2(this.environment.name);
14651
+ if (workerConfig && !isNodeCompat(workerConfig)) {
14652
+ const nodeJsCompatWarnings = nodeJsCompatWarningsMap.get(workerConfig);
14653
+ assert8(
14654
+ nodeJsCompatWarnings,
14655
+ `expected nodeJsCompatWarnings to be defined for Worker "${workerConfig.name}"`
14656
+ );
14657
+ nodeJsCompatWarnings.renderWarnings();
14658
+ }
14659
+ },
14660
+ // We must ensure that the `resolveId` hook runs before the built-in ones otherwise we
14661
+ // never see the Node.js built-in imports since they get handled by default Vite behavior.
14662
+ enforce: "pre",
14663
+ async resolveId(source, importer) {
14664
+ const workerConfig = getWorkerConfig2(this.environment.name);
14665
+ if (workerConfig && !isNodeCompat(workerConfig)) {
14666
+ const nodeJsCompatWarnings = nodeJsCompatWarningsMap.get(workerConfig);
14667
+ if (nodejsBuiltins.has(source)) {
14668
+ nodeJsCompatWarnings?.registerImport(source, importer);
14669
+ nodeJsCompatWarnings?.renderWarningsOnIdle();
14670
+ return {
14671
+ id: source,
14672
+ external: true
14673
+ };
14674
+ }
14675
+ }
14676
+ }
14535
14677
  }
14536
14678
  ];
14537
14679
  function getWorkerConfig2(environmentName) {
@@ -14540,7 +14682,7 @@ function cloudflare2(pluginConfig = {}) {
14540
14682
  }
14541
14683
  }
14542
14684
  function getDotDevDotVarsContent(configPath, cloudflareEnv) {
14543
- const configDir = path8.dirname(configPath);
14685
+ const configDir = path9.dirname(configPath);
14544
14686
  const defaultDotDevDotVarsPath = `${configDir}/.dev.vars`;
14545
14687
  const inputDotDevDotVarsPath = `${defaultDotDevDotVarsPath}${cloudflareEnv ? `.${cloudflareEnv}` : ""}`;
14546
14688
  const targetPath = fs5.existsSync(inputDotDevDotVarsPath) ? inputDotDevDotVarsPath : fs5.existsSync(defaultDotDevDotVarsPath) ? defaultDotDevDotVarsPath : null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudflare/vite-plugin",
3
- "version": "0.1.17",
3
+ "version": "0.1.19",
4
4
  "description": "Cloudflare plugin for Vite",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -38,9 +38,9 @@
38
38
  "tinyglobby": "^0.2.12",
39
39
  "unenv": "2.0.0-rc.15",
40
40
  "ws": "8.18.0",
41
- "@cloudflare/unenv-preset": "2.3.1",
42
- "miniflare": "4.20250321.0",
43
- "wrangler": "4.5.0"
41
+ "miniflare": "4.20250321.1",
42
+ "wrangler": "4.6.0",
43
+ "@cloudflare/unenv-preset": "2.3.1"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@cloudflare/workers-types": "^4.20250321.0",
@@ -53,8 +53,8 @@
53
53
  "undici": "^5.28.5",
54
54
  "vite": "^6.1.0",
55
55
  "vitest": "~3.0.8",
56
- "@cloudflare/workers-shared": "0.17.1",
57
56
  "@cloudflare/mock-npm-registry": "0.0.0",
57
+ "@cloudflare/workers-shared": "0.17.1",
58
58
  "@cloudflare/workers-tsconfig": "0.0.0"
59
59
  },
60
60
  "peerDependencies": {