@cloudflare/vite-plugin 0.1.17 → 0.1.18

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 +248 -110
  2. package/package.json +4 -4
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,12 +12991,12 @@ 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);
@@ -13026,7 +13075,7 @@ function createHotChannel(webSocketContainer) {
13026
13075
  }
13027
13076
  };
13028
13077
  }
13029
- var CloudflareDevEnvironment = class extends vite2.DevEnvironment {
13078
+ var CloudflareDevEnvironment = class extends vite3.DevEnvironment {
13030
13079
  #webSocketContainer;
13031
13080
  #worker;
13032
13081
  constructor(name, config) {
@@ -13087,7 +13136,7 @@ function createCloudflareEnvironmentOptions(workerConfig, userConfig, environmen
13087
13136
  },
13088
13137
  build: {
13089
13138
  createEnvironment(name, config) {
13090
- return new vite2.BuildEnvironment(name, config);
13139
+ return new vite3.BuildEnvironment(name, config);
13091
13140
  },
13092
13141
  target,
13093
13142
  // We need to enable `emitAssets` in order to support additional modules defined by `rules`
@@ -13196,11 +13245,11 @@ function getDebugPathHtml(workerNames, inspectorPort) {
13196
13245
  // src/deploy-config.ts
13197
13246
  import assert5 from "node:assert";
13198
13247
  import * as fs2 from "node:fs";
13199
- import * as path4 from "node:path";
13248
+ import * as path5 from "node:path";
13200
13249
  import "vite";
13201
13250
  import { unstable_readConfig } from "wrangler";
13202
13251
  function getDeployConfigPath(root) {
13203
- return path4.resolve(root, ".wrangler", "deploy", "config.json");
13252
+ return path5.resolve(root, ".wrangler", "deploy", "config.json");
13204
13253
  }
13205
13254
  function getWorkerConfigs(root) {
13206
13255
  const deployConfigPath = getDeployConfigPath(root);
@@ -13211,22 +13260,22 @@ function getWorkerConfigs(root) {
13211
13260
  { configPath: deployConfig.configPath },
13212
13261
  ...deployConfig.auxiliaryWorkers
13213
13262
  ].map(({ configPath }) => {
13214
- const resolvedConfigPath = path4.resolve(
13215
- path4.dirname(deployConfigPath),
13263
+ const resolvedConfigPath = path5.resolve(
13264
+ path5.dirname(deployConfigPath),
13216
13265
  configPath
13217
13266
  );
13218
13267
  return unstable_readConfig({ config: resolvedConfigPath });
13219
13268
  });
13220
13269
  }
13221
13270
  function getRelativePathToWorkerConfig(deployConfigDirectory, root, outputDirectory) {
13222
- return path4.relative(
13271
+ return path5.relative(
13223
13272
  deployConfigDirectory,
13224
- path4.resolve(root, outputDirectory, "wrangler.json")
13273
+ path5.resolve(root, outputDirectory, "wrangler.json")
13225
13274
  );
13226
13275
  }
13227
13276
  function writeDeployConfig(resolvedPluginConfig, resolvedViteConfig) {
13228
13277
  const deployConfigPath = getDeployConfigPath(resolvedViteConfig.root);
13229
- const deployConfigDirectory = path4.dirname(deployConfigPath);
13278
+ const deployConfigDirectory = path5.dirname(deployConfigPath);
13230
13279
  fs2.mkdirSync(deployConfigDirectory, { recursive: true });
13231
13280
  if (resolvedPluginConfig.type === "assets-only") {
13232
13281
  const clientOutputDirectory = resolvedViteConfig.environments.client?.build.outDir;
@@ -13279,7 +13328,7 @@ function writeDeployConfig(resolvedPluginConfig, resolvedViteConfig) {
13279
13328
  import assert6 from "node:assert";
13280
13329
  import * as fs3 from "node:fs";
13281
13330
  import * as fsp from "node:fs/promises";
13282
- import * as path5 from "node:path";
13331
+ import * as path6 from "node:path";
13283
13332
  import { fileURLToPath as fileURLToPath2 } from "node:url";
13284
13333
  import {
13285
13334
  kCurrentWorker,
@@ -13295,18 +13344,18 @@ function getPersistence(root, persistState) {
13295
13344
  return {};
13296
13345
  }
13297
13346
  const defaultPersistPath = ".wrangler/state";
13298
- const persistPath = path5.resolve(
13347
+ const persistPath = path6.resolve(
13299
13348
  root,
13300
13349
  typeof persistState === "object" ? persistState.path : defaultPersistPath,
13301
13350
  "v3"
13302
13351
  );
13303
13352
  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")
13353
+ cachePersist: path6.join(persistPath, "cache"),
13354
+ d1Persist: path6.join(persistPath, "d1"),
13355
+ durableObjectsPersist: path6.join(persistPath, "do"),
13356
+ kvPersist: path6.join(persistPath, "kv"),
13357
+ r2Persist: path6.join(persistPath, "r2"),
13358
+ workflowsPersist: path6.join(persistPath, "workflows")
13310
13359
  };
13311
13360
  }
13312
13361
  function missingWorkerErrorMessage(workerName) {
@@ -13407,7 +13456,7 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer) {
13407
13456
  modules: [
13408
13457
  {
13409
13458
  type: "ESModule",
13410
- path: path5.join(miniflareModulesRoot, ROUTER_WORKER_PATH),
13459
+ path: path6.join(miniflareModulesRoot, ROUTER_WORKER_PATH),
13411
13460
  contents: fs3.readFileSync(
13412
13461
  fileURLToPath2(new URL(ROUTER_WORKER_PATH, import.meta.url))
13413
13462
  )
@@ -13430,7 +13479,7 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer) {
13430
13479
  modules: [
13431
13480
  {
13432
13481
  type: "ESModule",
13433
- path: path5.join(miniflareModulesRoot, ASSET_WORKER_PATH),
13482
+ path: path6.join(miniflareModulesRoot, ASSET_WORKER_PATH),
13434
13483
  contents: fs3.readFileSync(
13435
13484
  fileURLToPath2(new URL(ASSET_WORKER_PATH, import.meta.url))
13436
13485
  )
@@ -13442,7 +13491,7 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer) {
13442
13491
  serviceBindings: {
13443
13492
  __VITE_ASSET_EXISTS__: async (request) => {
13444
13493
  const { pathname } = new URL(request.url);
13445
- const filePath = path5.join(resolvedViteConfig.root, pathname);
13494
+ const filePath = path6.join(resolvedViteConfig.root, pathname);
13446
13495
  let exists;
13447
13496
  try {
13448
13497
  exists = fs3.statSync(filePath).isFile();
@@ -13453,7 +13502,7 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer) {
13453
13502
  },
13454
13503
  __VITE_FETCH_ASSET__: async (request) => {
13455
13504
  const { pathname } = new URL(request.url);
13456
- const filePath = path5.join(resolvedViteConfig.root, pathname);
13505
+ const filePath = path6.join(resolvedViteConfig.root, pathname);
13457
13506
  try {
13458
13507
  let html = await fsp.readFile(filePath, "utf-8");
13459
13508
  html = await viteDevServer.transformIndexHtml(pathname, html);
@@ -13585,12 +13634,12 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer) {
13585
13634
  modules: [
13586
13635
  {
13587
13636
  type: "ESModule",
13588
- path: path5.join(miniflareModulesRoot, WRAPPER_PATH),
13637
+ path: path6.join(miniflareModulesRoot, WRAPPER_PATH),
13589
13638
  contents: wrappers.join("\n")
13590
13639
  },
13591
13640
  {
13592
13641
  type: "ESModule",
13593
- path: path5.join(miniflareModulesRoot, RUNNER_PATH),
13642
+ path: path6.join(miniflareModulesRoot, RUNNER_PATH),
13594
13643
  contents: fs3.readFileSync(
13595
13644
  fileURLToPath2(new URL(RUNNER_PATH, import.meta.url))
13596
13645
  )
@@ -13645,8 +13694,8 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer) {
13645
13694
  }
13646
13695
  function getPreviewModules(main, modulesRules) {
13647
13696
  assert6(modulesRules, `Unexpected error: 'modulesRules' is undefined`);
13648
- const rootPath = path5.dirname(main);
13649
- const entryPath = path5.basename(main);
13697
+ const rootPath = path6.dirname(main);
13698
+ const entryPath = path6.basename(main);
13650
13699
  return {
13651
13700
  rootPath,
13652
13701
  modules: [
@@ -13655,9 +13704,9 @@ function getPreviewModules(main, modulesRules) {
13655
13704
  path: entryPath
13656
13705
  },
13657
13706
  ...modulesRules.flatMap(
13658
- ({ type, include }) => globSync(include, { cwd: rootPath, ignore: entryPath }).map((path9) => ({
13707
+ ({ type, include }) => globSync(include, { cwd: rootPath, ignore: entryPath }).map((path10) => ({
13659
13708
  type,
13660
- path: path9
13709
+ path: path10
13661
13710
  }))
13662
13711
  )
13663
13712
  ]
@@ -13733,12 +13782,12 @@ function miniflareLogLevelFromViteLogLevel(level = "info") {
13733
13782
 
13734
13783
  // src/plugin-config.ts
13735
13784
  import assert7 from "node:assert";
13736
- import * as path7 from "node:path";
13737
- import * as vite5 from "vite";
13785
+ import * as path8 from "node:path";
13786
+ import * as vite6 from "vite";
13738
13787
 
13739
13788
  // src/workers-configs.ts
13740
13789
  import * as fs4 from "node:fs";
13741
- import * as path6 from "node:path";
13790
+ import * as path7 from "node:path";
13742
13791
  import { unstable_readConfig as unstable_readConfig2 } from "wrangler";
13743
13792
  var nonApplicableWorkerConfigs = {
13744
13793
  /**
@@ -13832,7 +13881,7 @@ function getWarningForWorkersConfigs(configs) {
13832
13881
  const lines2 = [
13833
13882
  `
13834
13883
 
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:`
13884
+ \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
13885
  ];
13837
13886
  nonApplicableLines.forEach((line) => lines2.push(line));
13838
13887
  lines2.push("");
@@ -13846,7 +13895,7 @@ function getWarningForWorkersConfigs(configs) {
13846
13895
  );
13847
13896
  if (nonApplicableLines.length > 0) {
13848
13897
  lines.push(
13849
- ` - (${isEntryWorker ? "entry" : "auxiliary"}) worker${workerConfig.config.name ? ` "${workerConfig.config.name}"` : ""}${workerConfig.config.configPath ? ` (config at \`${path6.relative("", workerConfig.config.configPath)}\`)` : ""}`
13898
+ ` - (${isEntryWorker ? "entry" : "auxiliary"}) worker${workerConfig.config.name ? ` "${workerConfig.config.name}"` : ""}${workerConfig.config.configPath ? ` (config at \`${path7.relative("", workerConfig.config.configPath)}\`)` : ""}`
13850
13899
  );
13851
13900
  nonApplicableLines.forEach((line) => lines.push(line));
13852
13901
  }
@@ -13947,7 +13996,7 @@ function getWorkerConfig(configPath, env2, opts) {
13947
13996
  }
13948
13997
  function findWranglerConfig(root) {
13949
13998
  for (const extension of ["json", "jsonc", "toml"]) {
13950
- const configPath = path6.join(root, `wrangler.${extension}`);
13999
+ const configPath = path7.join(root, `wrangler.${extension}`);
13951
14000
  if (fs4.existsSync(configPath)) {
13952
14001
  return configPath;
13953
14002
  }
@@ -13963,14 +14012,14 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
13963
14012
  const persistState = pluginConfig.persistState ?? true;
13964
14013
  const inspectorPort = pluginConfig.inspectorPort ?? DEFAULT_INSPECTOR_PORT;
13965
14014
  const experimental = pluginConfig.experimental ?? {};
13966
- const root = userConfig.root ? path7.resolve(userConfig.root) : process.cwd();
13967
- const { CLOUDFLARE_ENV: cloudflareEnv } = vite5.loadEnv(
14015
+ const root = userConfig.root ? path8.resolve(userConfig.root) : process.cwd();
14016
+ const { CLOUDFLARE_ENV: cloudflareEnv } = vite6.loadEnv(
13968
14017
  viteEnv.mode,
13969
14018
  root,
13970
14019
  /* prefixes */
13971
14020
  ""
13972
14021
  );
13973
- const configPath = pluginConfig.configPath ? path7.resolve(root, pluginConfig.configPath) : findWranglerConfig(root);
14022
+ const configPath = pluginConfig.configPath ? path8.resolve(root, pluginConfig.configPath) : findWranglerConfig(root);
13974
14023
  if (!configPath) {
13975
14024
  throw new Error(
13976
14025
  `Config not found. Have you created a wrangler.json(c) or wrangler.toml file?`
@@ -14002,7 +14051,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
14002
14051
  const auxiliaryWorkersResolvedConfigs = [];
14003
14052
  for (const auxiliaryWorker of pluginConfig.auxiliaryWorkers ?? []) {
14004
14053
  const workerResolvedConfig = getWorkerConfig(
14005
- path7.resolve(root, auxiliaryWorker.configPath),
14054
+ path8.resolve(root, auxiliaryWorker.configPath),
14006
14055
  cloudflareEnv,
14007
14056
  {
14008
14057
  visitedConfigPaths: configPaths
@@ -14081,6 +14130,7 @@ function cloudflare2(pluginConfig = {}) {
14081
14130
  let resolvedPluginConfig;
14082
14131
  let resolvedViteConfig;
14083
14132
  const additionalModulePaths = /* @__PURE__ */ new Set();
14133
+ const nodeJsCompatWarningsMap = /* @__PURE__ */ new Map();
14084
14134
  let hasClientBuild = false;
14085
14135
  return [
14086
14136
  {
@@ -14131,7 +14181,7 @@ function cloudflare2(pluginConfig = {}) {
14131
14181
  builder: {
14132
14182
  buildApp: userConfig.builder?.buildApp ?? (async (builder) => {
14133
14183
  const clientEnvironment = builder.environments.client;
14134
- const defaultHtmlPath = path8.resolve(
14184
+ const defaultHtmlPath = path9.resolve(
14135
14185
  builder.config.root,
14136
14186
  "index.html"
14137
14187
  );
@@ -14190,9 +14240,9 @@ function cloudflare2(pluginConfig = {}) {
14190
14240
  );
14191
14241
  workerConfig.assets = {
14192
14242
  ...workerConfig.assets,
14193
- directory: path8.relative(
14194
- path8.resolve(resolvedViteConfig.root, workerOutputDirectory),
14195
- path8.resolve(resolvedViteConfig.root, clientOutputDirectory)
14243
+ directory: path9.relative(
14244
+ path9.resolve(resolvedViteConfig.root, workerOutputDirectory),
14245
+ path9.resolve(resolvedViteConfig.root, clientOutputDirectory)
14196
14246
  )
14197
14247
  };
14198
14248
  } else {
@@ -14250,7 +14300,7 @@ function cloudflare2(pluginConfig = {}) {
14250
14300
  hotUpdate(options) {
14251
14301
  if (
14252
14302
  // Vite normalizes `options.file` so we use `path.resolve` for Windows compatibility
14253
- resolvedPluginConfig.configPaths.has(path8.resolve(options.file)) || hasAssetsConfigChanged(
14303
+ resolvedPluginConfig.configPaths.has(path9.resolve(options.file)) || hasAssetsConfigChanged(
14254
14304
  resolvedPluginConfig,
14255
14305
  resolvedViteConfig,
14256
14306
  options.file
@@ -14396,13 +14446,13 @@ function cloudflare2(pluginConfig = {}) {
14396
14446
  }
14397
14447
  const referenceId = this.emitFile({
14398
14448
  type: "asset",
14399
- name: path8.basename(modulePath),
14449
+ name: path9.basename(modulePath),
14400
14450
  originalFileName: modulePath,
14401
14451
  source
14402
14452
  });
14403
14453
  const emittedFileName = this.getFileName(referenceId);
14404
- const relativePath = vite6.normalizePath(
14405
- path8.relative(path8.dirname(chunk.fileName), emittedFileName)
14454
+ const relativePath = vite7.normalizePath(
14455
+ path9.relative(path9.dirname(chunk.fileName), emittedFileName)
14406
14456
  );
14407
14457
  const importPath = relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
14408
14458
  magicString.update(
@@ -14444,10 +14494,7 @@ function cloudflare2(pluginConfig = {}) {
14444
14494
  // Obviously we don't want/need the optimizer to try to process modules that are built-in;
14445
14495
  // But also we want to avoid following the ones that are polyfilled since the dependency-optimizer import analyzer does not
14446
14496
  // resolve these imports using our `resolveId()` hook causing the optimization step to fail.
14447
- exclude: [
14448
- ...builtinModules2,
14449
- ...builtinModules2.map((m) => `node:${m}`)
14450
- ]
14497
+ exclude: [...nodejsBuiltins]
14451
14498
  }
14452
14499
  };
14453
14500
  }
@@ -14517,7 +14564,7 @@ function cloudflare2(pluginConfig = {}) {
14517
14564
  addDebugToVitePrintUrls(vitePreviewServer);
14518
14565
  }
14519
14566
  const workerNames = workerConfigs.map((worker) => {
14520
- assert8(worker.name);
14567
+ assert8(worker.name, "Expected the Worker to have a name");
14521
14568
  return worker.name;
14522
14569
  });
14523
14570
  vitePreviewServer.middlewares.use((req, res, next) => {
@@ -14532,6 +14579,97 @@ function cloudflare2(pluginConfig = {}) {
14532
14579
  next();
14533
14580
  });
14534
14581
  }
14582
+ },
14583
+ // Plugin to warn if Node.js APIs are being used without nodejs_compat turned on
14584
+ {
14585
+ name: "vite-plugin-cloudflare:nodejs-compat-warnings",
14586
+ apply(_config, env2) {
14587
+ return !env2.isPreview;
14588
+ },
14589
+ configEnvironment(environmentName) {
14590
+ const workerConfig = getWorkerConfig2(environmentName);
14591
+ if (workerConfig && !isNodeCompat(workerConfig)) {
14592
+ return {
14593
+ optimizeDeps: {
14594
+ esbuildOptions: {
14595
+ plugins: [
14596
+ {
14597
+ name: "vite-plugin-cloudflare:nodejs-compat-warnings-resolver",
14598
+ setup(build) {
14599
+ build.onResolve(
14600
+ { filter: NODEJS_MODULES_RE },
14601
+ ({ path: path10, importer }) => {
14602
+ const nodeJsCompatWarnings = nodeJsCompatWarningsMap.get(workerConfig);
14603
+ assert8(
14604
+ nodeJsCompatWarnings,
14605
+ `expected nodeJsCompatWarnings to be defined for Worker "${workerConfig.name}"`
14606
+ );
14607
+ nodeJsCompatWarnings.registerImport(path10, importer);
14608
+ return { path: path10, external: true };
14609
+ }
14610
+ );
14611
+ build.onEnd(() => {
14612
+ const nodeJsCompatWarnings = nodeJsCompatWarningsMap.get(workerConfig);
14613
+ if (nodeJsCompatWarnings) {
14614
+ nodeJsCompatWarnings.renderWarnings();
14615
+ }
14616
+ });
14617
+ }
14618
+ }
14619
+ ]
14620
+ }
14621
+ }
14622
+ };
14623
+ }
14624
+ },
14625
+ configureServer(viteDevServer) {
14626
+ for (const environment of Object.values(viteDevServer.environments)) {
14627
+ const workerConfig = getWorkerConfig2(environment.name);
14628
+ if (workerConfig && !isNodeCompat(workerConfig)) {
14629
+ nodeJsCompatWarningsMap.set(
14630
+ workerConfig,
14631
+ new NodeJsCompatWarnings(environment)
14632
+ );
14633
+ }
14634
+ }
14635
+ },
14636
+ buildStart() {
14637
+ const workerConfig = getWorkerConfig2(this.environment.name);
14638
+ if (workerConfig && !isNodeCompat(workerConfig)) {
14639
+ nodeJsCompatWarningsMap.set(
14640
+ workerConfig,
14641
+ new NodeJsCompatWarnings(this.environment)
14642
+ );
14643
+ }
14644
+ },
14645
+ buildEnd() {
14646
+ const workerConfig = getWorkerConfig2(this.environment.name);
14647
+ if (workerConfig && !isNodeCompat(workerConfig)) {
14648
+ const nodeJsCompatWarnings = nodeJsCompatWarningsMap.get(workerConfig);
14649
+ assert8(
14650
+ nodeJsCompatWarnings,
14651
+ `expected nodeJsCompatWarnings to be defined for Worker "${workerConfig.name}"`
14652
+ );
14653
+ nodeJsCompatWarnings.renderWarnings();
14654
+ }
14655
+ },
14656
+ // We must ensure that the `resolveId` hook runs before the built-in ones otherwise we
14657
+ // never see the Node.js built-in imports since they get handled by default Vite behavior.
14658
+ enforce: "pre",
14659
+ async resolveId(source, importer) {
14660
+ const workerConfig = getWorkerConfig2(this.environment.name);
14661
+ if (workerConfig && !isNodeCompat(workerConfig)) {
14662
+ const nodeJsCompatWarnings = nodeJsCompatWarningsMap.get(workerConfig);
14663
+ if (nodejsBuiltins.has(source)) {
14664
+ nodeJsCompatWarnings?.registerImport(source, importer);
14665
+ nodeJsCompatWarnings?.renderWarningsOnIdle();
14666
+ return {
14667
+ id: source,
14668
+ external: true
14669
+ };
14670
+ }
14671
+ }
14672
+ }
14535
14673
  }
14536
14674
  ];
14537
14675
  function getWorkerConfig2(environmentName) {
@@ -14540,7 +14678,7 @@ function cloudflare2(pluginConfig = {}) {
14540
14678
  }
14541
14679
  }
14542
14680
  function getDotDevDotVarsContent(configPath, cloudflareEnv) {
14543
- const configDir = path8.dirname(configPath);
14681
+ const configDir = path9.dirname(configPath);
14544
14682
  const defaultDotDevDotVarsPath = `${configDir}/.dev.vars`;
14545
14683
  const inputDotDevDotVarsPath = `${defaultDotDevDotVarsPath}${cloudflareEnv ? `.${cloudflareEnv}` : ""}`;
14546
14684
  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.18",
4
4
  "description": "Cloudflare plugin for Vite",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -39,8 +39,8 @@
39
39
  "unenv": "2.0.0-rc.15",
40
40
  "ws": "8.18.0",
41
41
  "@cloudflare/unenv-preset": "2.3.1",
42
- "miniflare": "4.20250321.0",
43
- "wrangler": "4.5.0"
42
+ "miniflare": "4.20250321.1",
43
+ "wrangler": "4.5.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": {