@cloudflare/vite-plugin 0.0.0-2d776aeed → 0.0.0-2e12e6e6f

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.
@@ -1985,7 +1985,7 @@ var we = class {
1985
1985
  this.hasWritten || this.readyAnalytics && (this.hasWritten = true, this.readyAnalytics.logEvent({ version: 1, accountId: this.data.accountId, indexId: this.data.scriptId?.toString(), doubles: [this.data.requestTime ?? -1, this.data.coloId ?? -1, this.data.metalId ?? -1, this.data.coloTier ?? -1, this.data.userWorkerAhead === void 0 ? -1 : Number(this.data.userWorkerAhead)], blobs: [this.data.hostname?.substring(0, 256), this.data.dispatchtype, this.data.error?.substring(0, 256), this.data.version, this.data.coloRegion] }));
1986
1986
  }
1987
1987
  };
1988
- var On = (t4) => ({ invoke_user_worker_ahead_of_assets: t4?.invoke_user_worker_ahead_of_assets ?? false, has_user_worker: t4?.has_user_worker ?? false, account_id: t4?.account_id ?? -1, script_id: t4?.script_id ?? -1 });
1988
+ var On = (t4) => ({ invoke_user_worker_ahead_of_assets: t4?.invoke_user_worker_ahead_of_assets ?? false, has_user_worker: t4?.has_user_worker ?? false, account_id: t4?.account_id ?? -1, script_id: t4?.script_id ?? -1, debug: t4?.debug ?? false });
1989
1989
  var Bc = { async fetch(t4, e, n) {
1990
1990
  let r, o = false, s = new we(e.ANALYTICS), i = new ue(e.UNSAFE_PERFORMANCE), a = i.now();
1991
1991
  try {
package/dist/index.js CHANGED
@@ -489,7 +489,8 @@ import assert10 from "node:assert";
489
489
  import * as fs5 from "node:fs";
490
490
  import * as fsp2 from "node:fs/promises";
491
491
  import * as path9 from "node:path";
492
- import { createMiddleware } from "@hattip/adapter-node";
492
+ import { createRequest, sendResponse } from "@mjackson/node-fetch-server";
493
+ import replace from "@rollup/plugin-replace";
493
494
 
494
495
  // ../../node_modules/.pnpm/@jridgewell+sourcemap-codec@1.5.0/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
495
496
  var comma = ",".charCodeAt(0);
@@ -1557,7 +1558,7 @@ var MagicString = class _MagicString {
1557
1558
 
1558
1559
  // src/index.ts
1559
1560
  import { Miniflare } from "miniflare";
1560
- import colors2 from "picocolors";
1561
+ import colors3 from "picocolors";
1561
1562
  import * as vite7 from "vite";
1562
1563
 
1563
1564
  // src/constants.ts
@@ -1588,7 +1589,7 @@ function matchAdditionalModule(source) {
1588
1589
  return null;
1589
1590
  }
1590
1591
  function createModuleReference(type, id) {
1591
- return `__CLOUDFLARE_MODULE__${type}__${id}__`;
1592
+ return `__CLOUDFLARE_MODULE__${type}__${id}__CLOUDFLARE_MODULE__`;
1592
1593
  }
1593
1594
 
1594
1595
  // src/asset-config.ts
@@ -5783,7 +5784,8 @@ var z = /* @__PURE__ */ Object.freeze({
5783
5784
  // ../workers-shared/utils/types.ts
5784
5785
  var InternalConfigSchema = z.object({
5785
5786
  account_id: z.number().optional(),
5786
- script_id: z.number().optional()
5787
+ script_id: z.number().optional(),
5788
+ debug: z.boolean().optional()
5787
5789
  });
5788
5790
  var RouterConfigSchema = z.object({
5789
5791
  invoke_user_worker_ahead_of_assets: z.boolean().optional(),
@@ -5831,14 +5833,14 @@ var AssetConfigSchema = z.object({
5831
5833
  });
5832
5834
 
5833
5835
  // src/asset-config.ts
5834
- function hasAssetsConfigChanged(resolvedPluginConfig, resolvedViteConfig, changedFile) {
5836
+ function hasAssetsConfigChanged(resolvedPluginConfig, resolvedViteConfig, changedFilePath) {
5835
5837
  if (!resolvedPluginConfig.experimental?.headersAndRedirectsDevModeSupport) {
5836
5838
  return false;
5837
5839
  }
5838
5840
  return [
5839
5841
  getRedirectsConfigPath(resolvedViteConfig),
5840
5842
  getHeadersConfigPath(resolvedViteConfig)
5841
- ].includes(path.resolve(changedFile));
5843
+ ].includes(changedFilePath);
5842
5844
  }
5843
5845
  function getAssetsConfig(resolvedPluginConfig, entryWorkerConfig, resolvedConfig) {
5844
5846
  const assetsConfig = resolvedPluginConfig.type === "assets-only" ? resolvedPluginConfig.config.assets : entryWorkerConfig?.assets;
@@ -12879,6 +12881,15 @@ function isNodeCompat(workerConfig) {
12879
12881
  }
12880
12882
  return false;
12881
12883
  }
12884
+ function isNodeAls(workerConfig) {
12885
+ return workerConfig !== void 0 && getNodeCompat(
12886
+ workerConfig.compatibility_date,
12887
+ workerConfig.compatibility_flags ?? []
12888
+ ).mode === "als";
12889
+ }
12890
+ function isNodeAlsModule(path10) {
12891
+ return /^(node:)?async_hooks$/.test(path10);
12892
+ }
12882
12893
  function injectGlobalCode(id, code) {
12883
12894
  const injectedCode = Object.entries(env.inject).map(([globalName, globalInject]) => {
12884
12895
  if (typeof globalInject === "string") {
@@ -12909,7 +12920,7 @@ globalThis.${globalName} = var_${globalName}.${exportName};
12909
12920
  }
12910
12921
  function resolveNodeJSImport(source) {
12911
12922
  const alias = env.alias[source];
12912
- if (alias) {
12923
+ if (alias && !nodeCompatExternals.has(alias)) {
12913
12924
  return {
12914
12925
  unresolved: alias,
12915
12926
  resolved: resolvePathSync(alias, { url: import.meta.url })
@@ -12982,7 +12993,7 @@ var NodeJsCompatWarnings = class {
12982
12993
  // src/shared.ts
12983
12994
  var UNKNOWN_HOST = "http://localhost";
12984
12995
  var INIT_PATH = "/__vite_plugin_cloudflare_init__";
12985
- var ADDITIONAL_MODULE_PATTERN = `__CLOUDFLARE_MODULE__(${ADDITIONAL_MODULE_TYPES.join("|")})__(.*?)__`;
12996
+ var ADDITIONAL_MODULE_PATTERN = `__CLOUDFLARE_MODULE__(${ADDITIONAL_MODULE_TYPES.join("|")})__(.*?)__CLOUDFLARE_MODULE__`;
12986
12997
  var additionalModuleRE = new RegExp(ADDITIONAL_MODULE_PATTERN);
12987
12998
  var additionalModuleGlobalRE = new RegExp(
12988
12999
  ADDITIONAL_MODULE_PATTERN,
@@ -13018,19 +13029,6 @@ function toMiniflareRequest(request) {
13018
13029
  duplex: "half"
13019
13030
  });
13020
13031
  }
13021
- function nodeHeadersToWebHeaders(nodeHeaders) {
13022
- const headers = new Headers();
13023
- for (const [key, value] of Object.entries(nodeHeaders)) {
13024
- if (typeof value === "string") {
13025
- headers.append(key, value);
13026
- } else if (Array.isArray(value)) {
13027
- for (const item of value) {
13028
- headers.append(key, item);
13029
- }
13030
- }
13031
- }
13032
- return headers;
13033
- }
13034
13032
  var postfixRE = /[?#].*$/;
13035
13033
  function cleanUrl(url) {
13036
13034
  return url.replace(postfixRE, "");
@@ -13344,12 +13342,13 @@ import {
13344
13342
  LogLevel,
13345
13343
  Response as MiniflareResponse
13346
13344
  } from "miniflare";
13345
+ import colors2 from "picocolors";
13347
13346
  import { globSync } from "tinyglobby";
13348
13347
  import "vite";
13349
13348
  import { unstable_getMiniflareWorkerOptions } from "wrangler";
13350
- function getPersistence(root, persistState) {
13349
+ function getPersistenceRoot(root, persistState) {
13351
13350
  if (persistState === false) {
13352
- return {};
13351
+ return;
13353
13352
  }
13354
13353
  const defaultPersistPath = ".wrangler/state";
13355
13354
  const persistPath = path6.resolve(
@@ -13357,14 +13356,7 @@ function getPersistence(root, persistState) {
13357
13356
  typeof persistState === "object" ? persistState.path : defaultPersistPath,
13358
13357
  "v3"
13359
13358
  );
13360
- return {
13361
- cachePersist: path6.join(persistPath, "cache"),
13362
- d1Persist: path6.join(persistPath, "d1"),
13363
- durableObjectsPersist: path6.join(persistPath, "do"),
13364
- kvPersist: path6.join(persistPath, "kv"),
13365
- r2Persist: path6.join(persistPath, "r2"),
13366
- workflowsPersist: path6.join(persistPath, "workflows")
13367
- };
13359
+ return persistPath;
13368
13360
  }
13369
13361
  function missingWorkerErrorMessage(workerName) {
13370
13362
  return `${workerName} does not match a worker name.`;
@@ -13448,6 +13440,29 @@ function getEntryWorkerConfig(resolvedPluginConfig) {
13448
13440
  }
13449
13441
  return resolvedPluginConfig.workers[resolvedPluginConfig.entryWorkerEnvironmentName];
13450
13442
  }
13443
+ function filterTails(tails, userWorkers, log) {
13444
+ return tails?.filter((tailService) => {
13445
+ let name;
13446
+ if (typeof tailService === "string") {
13447
+ name = tailService;
13448
+ } else if (typeof tailService === "object" && "name" in tailService && typeof tailService.name === "string") {
13449
+ name = tailService.name;
13450
+ } else {
13451
+ return true;
13452
+ }
13453
+ const found = userWorkers.some((w) => w.name === name);
13454
+ if (!found) {
13455
+ log(
13456
+ colors2.dim(
13457
+ colors2.yellow(
13458
+ `Tail consumer "${name}" was not found in your config. Make sure you add it if you'd like to simulate receiving tail events locally.`
13459
+ )
13460
+ )
13461
+ );
13462
+ }
13463
+ return found;
13464
+ });
13465
+ }
13451
13466
  function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPort) {
13452
13467
  const resolvedViteConfig = viteDevServer.config;
13453
13468
  const entryWorkerConfig = getEntryWorkerConfig(resolvedPluginConfig);
@@ -13582,6 +13597,7 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPo
13582
13597
  const logger = new ViteMiniflareLogger(resolvedViteConfig);
13583
13598
  return {
13584
13599
  log: logger,
13600
+ logRequests: false,
13585
13601
  inspectorPort: inspectorPort === false ? void 0 : inspectorPort,
13586
13602
  unsafeInspectorProxy: inspectorPort !== false,
13587
13603
  handleRuntimeStdio(stdout, stderr) {
@@ -13591,7 +13607,7 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPo
13591
13607
  (error) => logger.logWithLevel(LogLevel.ERROR, decoder.decode(error))
13592
13608
  );
13593
13609
  },
13594
- ...getPersistence(
13610
+ defaultPersistRoot: getPersistenceRoot(
13595
13611
  resolvedViteConfig.root,
13596
13612
  resolvedPluginConfig.persistState
13597
13613
  ),
@@ -13639,6 +13655,11 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPo
13639
13655
  }
13640
13656
  return {
13641
13657
  ...workerOptions,
13658
+ tails: filterTails(
13659
+ workerOptions.tails,
13660
+ userWorkers,
13661
+ viteDevServer.config.logger.warn
13662
+ ),
13642
13663
  modules: [
13643
13664
  {
13644
13665
  type: "ESModule",
@@ -13729,6 +13750,11 @@ function getPreviewMiniflareOptions(vitePreviewServer, workerConfigs, persistSta
13729
13750
  return [
13730
13751
  {
13731
13752
  ...workerOptions,
13753
+ tails: filterTails(
13754
+ workerOptions.tails,
13755
+ workerConfigs,
13756
+ vitePreviewServer.config.logger.warn
13757
+ ),
13732
13758
  name: workerOptions.name ?? config.name,
13733
13759
  unsafeInspectorProxy: inspectorPort !== false,
13734
13760
  ...miniflareWorkerOptions.main ? getPreviewModules(miniflareWorkerOptions.main, modulesRules) : { modules: true, script: "" }
@@ -13748,11 +13774,13 @@ function getPreviewMiniflareOptions(vitePreviewServer, workerConfigs, persistSta
13748
13774
  (error) => logger.logWithLevel(LogLevel.ERROR, decoder.decode(error))
13749
13775
  );
13750
13776
  },
13751
- ...getPersistence(resolvedViteConfig.root, persistState),
13777
+ defaultPersistRoot: getPersistenceRoot(
13778
+ resolvedViteConfig.root,
13779
+ persistState
13780
+ ),
13752
13781
  workers
13753
13782
  };
13754
13783
  }
13755
- var removedMessages = [/^Ready on http/, /^Updated and ready on http/];
13756
13784
  var ViteMiniflareLogger = class extends Log {
13757
13785
  logger;
13758
13786
  constructor(config) {
@@ -13760,11 +13788,6 @@ var ViteMiniflareLogger = class extends Log {
13760
13788
  this.logger = config.logger;
13761
13789
  }
13762
13790
  logWithLevel(level, message) {
13763
- for (const removedMessage of removedMessages) {
13764
- if (removedMessage.test(message)) {
13765
- return;
13766
- }
13767
- }
13768
13791
  switch (level) {
13769
13792
  case LogLevel.ERROR:
13770
13793
  return this.logger.error(message);
@@ -13774,6 +13797,8 @@ var ViteMiniflareLogger = class extends Log {
13774
13797
  return this.logger.info(message);
13775
13798
  }
13776
13799
  }
13800
+ logReady() {
13801
+ }
13777
13802
  };
13778
13803
  function miniflareLogLevelFromViteLogLevel(level = "info") {
13779
13804
  switch (level) {
@@ -14137,6 +14162,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
14137
14162
  }
14138
14163
 
14139
14164
  // src/websockets.ts
14165
+ import { createHeaders } from "@mjackson/node-fetch-server";
14140
14166
  import { coupleWebSocket } from "miniflare";
14141
14167
  import { WebSocketServer } from "ws";
14142
14168
  function handleWebSocket(httpServer, getFetcher) {
@@ -14148,7 +14174,7 @@ function handleWebSocket(httpServer, getFetcher) {
14148
14174
  if (request.headers["sec-websocket-protocol"]?.startsWith("vite")) {
14149
14175
  return;
14150
14176
  }
14151
- const headers = nodeHeadersToWebHeaders(request.headers);
14177
+ const headers = createHeaders(request);
14152
14178
  const fetcher = await getFetcher();
14153
14179
  const response = await fetcher(url, {
14154
14180
  headers,
@@ -14180,12 +14206,15 @@ function validateWorkerEnvironmentsResolvedConfigs(resolvedPluginConfig, resolve
14180
14206
  for (const envName of workersEnvironmentNames) {
14181
14207
  const workerEnvConfig = resolvedViteConfig.environments[envName];
14182
14208
  assert9(workerEnvConfig, `Missing environment config for "${envName}"`);
14183
- const { optimizeDeps, resolve: resolve8 } = workerEnvConfig;
14209
+ const { optimizeDeps, resolve: resolve7 } = workerEnvConfig;
14184
14210
  const disallowedConfig = {};
14185
14211
  const disallowedOptimizeDepsExcludeEntries = (optimizeDeps.exclude ?? []).filter((entry) => {
14186
14212
  if (cloudflareBuiltInModules.includes(entry)) {
14187
14213
  return false;
14188
14214
  }
14215
+ if (isNodeAlsModule(entry) && isNodeAls(resolvedPluginConfig.workers[envName])) {
14216
+ return false;
14217
+ }
14189
14218
  if (NODEJS_MODULES_RE.test(entry) && isNodeCompat(resolvedPluginConfig.workers[envName])) {
14190
14219
  return false;
14191
14220
  }
@@ -14194,8 +14223,8 @@ function validateWorkerEnvironmentsResolvedConfigs(resolvedPluginConfig, resolve
14194
14223
  if (disallowedOptimizeDepsExcludeEntries.length > 0) {
14195
14224
  disallowedConfig.optimizeDepsExclude = disallowedOptimizeDepsExcludeEntries;
14196
14225
  }
14197
- if (resolve8.external === true || resolve8.external.length > 0) {
14198
- disallowedConfig.resolveExternal = resolve8.external;
14226
+ if (resolve7.external === true || resolve7.external.length > 0) {
14227
+ disallowedConfig.resolveExternal = resolve7.external;
14199
14228
  }
14200
14229
  if (Object.keys(disallowedConfig).length > 0) {
14201
14230
  disallowedEnvsConfigs.set(envName, disallowedConfig);
@@ -14401,28 +14430,22 @@ function cloudflare2(pluginConfig = {}) {
14401
14430
  }
14402
14431
  },
14403
14432
  hotUpdate(options) {
14404
- if (
14405
- // Vite normalizes `options.file` so we use `path.resolve` for Windows compatibility
14406
- resolvedPluginConfig.configPaths.has(path9.resolve(options.file)) || hasAssetsConfigChanged(
14407
- resolvedPluginConfig,
14408
- resolvedViteConfig,
14409
- options.file
14410
- )
14411
- ) {
14433
+ const changedFilePath = path9.resolve(options.file);
14434
+ if (resolvedPluginConfig.configPaths.has(changedFilePath) || hasDotDevDotVarsFileChanged(resolvedPluginConfig, changedFilePath) || hasAssetsConfigChanged(
14435
+ resolvedPluginConfig,
14436
+ resolvedViteConfig,
14437
+ changedFilePath
14438
+ )) {
14412
14439
  options.server.restart();
14413
14440
  return [];
14414
14441
  }
14415
14442
  },
14416
14443
  async configureServer(viteDevServer) {
14417
- assert10(
14418
- viteDevServer.httpServer,
14419
- "Unexpected error: No Vite HTTP server"
14444
+ const inputInspectorPort = await getInputInspectorPortOption(
14445
+ pluginConfig,
14446
+ viteDevServer
14420
14447
  );
14421
14448
  if (!miniflare) {
14422
- const inputInspectorPort = await getInputInspectorPortOption(
14423
- pluginConfig,
14424
- viteDevServer
14425
- );
14426
14449
  miniflare = new Miniflare(
14427
14450
  getDevMiniflareOptions(
14428
14451
  resolvedPluginConfig,
@@ -14431,34 +14454,41 @@ function cloudflare2(pluginConfig = {}) {
14431
14454
  )
14432
14455
  );
14433
14456
  } else {
14434
- const resolvedInspectorPort = await getResolvedInspectorPort(pluginConfig);
14435
14457
  await miniflare.setOptions(
14436
14458
  getDevMiniflareOptions(
14437
14459
  resolvedPluginConfig,
14438
14460
  viteDevServer,
14439
- resolvedInspectorPort ?? false
14461
+ inputInspectorPort
14440
14462
  )
14441
14463
  );
14442
14464
  }
14443
14465
  await initRunners(resolvedPluginConfig, viteDevServer, miniflare);
14444
- const middleware = createMiddleware(
14445
- async ({ request }) => {
14466
+ if (viteDevServer.httpServer) {
14467
+ handleWebSocket(viteDevServer.httpServer, async () => {
14446
14468
  assert10(miniflare, `Miniflare not defined`);
14447
14469
  const routerWorker = await getRouterWorker(miniflare);
14448
- return routerWorker.fetch(toMiniflareRequest(request), {
14449
- redirect: "manual"
14450
- });
14451
- },
14452
- { alwaysCallNext: false }
14453
- );
14454
- handleWebSocket(viteDevServer.httpServer, async () => {
14455
- assert10(miniflare, `Miniflare not defined`);
14456
- const routerWorker = await getRouterWorker(miniflare);
14457
- return routerWorker.fetch;
14458
- });
14470
+ return routerWorker.fetch;
14471
+ });
14472
+ }
14459
14473
  return () => {
14460
- viteDevServer.middlewares.use((req, res, next) => {
14461
- middleware(req, res, next);
14474
+ viteDevServer.middlewares.use(async (req, res, next) => {
14475
+ try {
14476
+ assert10(miniflare, `Miniflare not defined`);
14477
+ const routerWorker = await getRouterWorker(miniflare);
14478
+ const request = createRequest(req, res);
14479
+ const response = await routerWorker.fetch(
14480
+ toMiniflareRequest(request),
14481
+ {
14482
+ redirect: "manual"
14483
+ }
14484
+ );
14485
+ if (req.httpVersionMajor === 2) {
14486
+ response.headers.delete("transfer-encoding");
14487
+ }
14488
+ await sendResponse(res, response);
14489
+ } catch (error) {
14490
+ next(error);
14491
+ }
14462
14492
  });
14463
14493
  };
14464
14494
  },
@@ -14476,20 +14506,24 @@ function cloudflare2(pluginConfig = {}) {
14476
14506
  inputInspectorPort
14477
14507
  )
14478
14508
  );
14479
- const middleware = createMiddleware(
14480
- ({ request }) => {
14481
- return miniflare2.dispatchFetch(toMiniflareRequest(request), {
14482
- redirect: "manual"
14483
- });
14484
- },
14485
- { alwaysCallNext: false }
14486
- );
14487
14509
  handleWebSocket(
14488
14510
  vitePreviewServer.httpServer,
14489
14511
  () => miniflare2.dispatchFetch
14490
14512
  );
14491
- vitePreviewServer.middlewares.use((req, res, next) => {
14492
- middleware(req, res, next);
14513
+ vitePreviewServer.middlewares.use(async (req, res, next) => {
14514
+ try {
14515
+ const request = createRequest(req, res);
14516
+ const response = await miniflare2.dispatchFetch(
14517
+ toMiniflareRequest(request),
14518
+ { redirect: "manual" }
14519
+ );
14520
+ if (req.httpVersionMajor === 2) {
14521
+ response.headers.delete("transfer-encoding");
14522
+ }
14523
+ await sendResponse(res, response);
14524
+ } catch (error) {
14525
+ next(error);
14526
+ }
14493
14527
  });
14494
14528
  }
14495
14529
  },
@@ -14598,6 +14632,18 @@ function cloudflare2(pluginConfig = {}) {
14598
14632
  configEnvironment(name) {
14599
14633
  if (isNodeCompat(getWorkerConfig2(name))) {
14600
14634
  return {
14635
+ build: {
14636
+ rollupOptions: {
14637
+ plugins: [
14638
+ replace({
14639
+ "process.env.NODE_ENV": JSON.stringify(
14640
+ process.env.NODE_ENV ?? "production"
14641
+ ),
14642
+ preventAssignment: true
14643
+ })
14644
+ ]
14645
+ }
14646
+ },
14601
14647
  resolve: {
14602
14648
  builtins: [...nodeCompatExternals]
14603
14649
  },
@@ -14639,7 +14685,9 @@ function cloudflare2(pluginConfig = {}) {
14639
14685
  },
14640
14686
  async transform(code, id) {
14641
14687
  const workerConfig = getWorkerConfig2(this.environment.name);
14642
- assert10(workerConfig, "Expected a worker config");
14688
+ if (!workerConfig) {
14689
+ return;
14690
+ }
14643
14691
  const resolvedId = await this.resolve(workerConfig.main);
14644
14692
  if (id === resolvedId?.id) {
14645
14693
  return injectGlobalCode(id, code);
@@ -14668,6 +14716,25 @@ function cloudflare2(pluginConfig = {}) {
14668
14716
  );
14669
14717
  }
14670
14718
  },
14719
+ // Plugin that handles Node.js Async Local Storage (ALS) compatibility support for Vite Environments that are hosted in Cloudflare Workers.
14720
+ {
14721
+ name: "vite-plugin-cloudflare:nodejs-als",
14722
+ apply(_config, env2) {
14723
+ return !env2.isPreview;
14724
+ },
14725
+ configEnvironment(name, config) {
14726
+ if (isNodeAls(getWorkerConfig2(name))) {
14727
+ return {
14728
+ resolve: {
14729
+ builtins: ["async_hooks", "node:async_hooks"]
14730
+ },
14731
+ optimizeDeps: {
14732
+ exclude: ["async_hooks", "node:async_hooks"]
14733
+ }
14734
+ };
14735
+ }
14736
+ }
14737
+ },
14671
14738
  // Plugin that provides an __debug path for debugging the Cloudflare Workers.
14672
14739
  {
14673
14740
  name: "vite-plugin-cloudflare:debug",
@@ -14733,6 +14800,9 @@ function cloudflare2(pluginConfig = {}) {
14733
14800
  build.onResolve(
14734
14801
  { filter: NODEJS_MODULES_RE },
14735
14802
  ({ path: path10, importer }) => {
14803
+ if (isNodeAls(workerConfig) && isNodeAlsModule(path10)) {
14804
+ return;
14805
+ }
14736
14806
  const nodeJsCompatWarnings = nodeJsCompatWarningsMap.get(workerConfig);
14737
14807
  nodeJsCompatWarnings?.registerImport(path10, importer);
14738
14808
  return { path: path10, external: true };
@@ -14762,6 +14832,9 @@ function cloudflare2(pluginConfig = {}) {
14762
14832
  async resolveId(source, importer) {
14763
14833
  const workerConfig = getWorkerConfig2(this.environment.name);
14764
14834
  if (workerConfig && !isNodeCompat(workerConfig)) {
14835
+ if (isNodeAls(workerConfig) && isNodeAlsModule(source)) {
14836
+ return;
14837
+ }
14765
14838
  const nodeJsCompatWarnings = nodeJsCompatWarningsMap.get(workerConfig);
14766
14839
  if (nodejsBuiltins.has(source)) {
14767
14840
  nodeJsCompatWarnings?.registerImport(source, importer);
@@ -14780,10 +14853,16 @@ function cloudflare2(pluginConfig = {}) {
14780
14853
  }
14781
14854
  }
14782
14855
  async function getInputInspectorPortOption(pluginConfig, viteServer) {
14856
+ if (pluginConfig.inspectorPort === void 0 || pluginConfig.inspectorPort === 0) {
14857
+ const resolvedInspectorPort = await getResolvedInspectorPort(pluginConfig);
14858
+ if (resolvedInspectorPort !== null) {
14859
+ return resolvedInspectorPort;
14860
+ }
14861
+ }
14783
14862
  const inputInspectorPort = pluginConfig.inspectorPort ?? await getFirstAvailablePort(DEFAULT_INSPECTOR_PORT);
14784
14863
  if (pluginConfig.inspectorPort === void 0 && inputInspectorPort !== DEFAULT_INSPECTOR_PORT) {
14785
14864
  viteServer.config.logger.warn(
14786
- colors2.dim(
14865
+ colors3.dim(
14787
14866
  `Default inspector port ${DEFAULT_INSPECTOR_PORT} not available, using ${inputInspectorPort} instead
14788
14867
  `
14789
14868
  )
@@ -14809,6 +14888,19 @@ function getDotDevDotVarsContent(configPath, cloudflareEnv) {
14809
14888
  }
14810
14889
  return null;
14811
14890
  }
14891
+ function hasDotDevDotVarsFileChanged(resolvedPluginConfig, changedFilePath) {
14892
+ return [...resolvedPluginConfig.configPaths].some((configPath) => {
14893
+ const dotDevDotVars = path9.join(path9.dirname(configPath), ".dev.vars");
14894
+ if (dotDevDotVars === changedFilePath) {
14895
+ return true;
14896
+ }
14897
+ if (resolvedPluginConfig.cloudflareEnv) {
14898
+ const dotDevDotVarsForEnv = `${dotDevDotVars}.${resolvedPluginConfig.cloudflareEnv}`;
14899
+ return dotDevDotVarsForEnv === changedFilePath;
14900
+ }
14901
+ return false;
14902
+ });
14903
+ }
14812
14904
  export {
14813
14905
  cloudflare2 as cloudflare
14814
14906
  };
@@ -15,7 +15,7 @@ var ADDITIONAL_MODULE_TYPES = [
15
15
  // src/shared.ts
16
16
  var UNKNOWN_HOST = "http://localhost";
17
17
  var INIT_PATH = "/__vite_plugin_cloudflare_init__";
18
- var ADDITIONAL_MODULE_PATTERN = `__CLOUDFLARE_MODULE__(${ADDITIONAL_MODULE_TYPES.join("|")})__(.*?)__`;
18
+ var ADDITIONAL_MODULE_PATTERN = `__CLOUDFLARE_MODULE__(${ADDITIONAL_MODULE_TYPES.join("|")})__(.*?)__CLOUDFLARE_MODULE__`;
19
19
  var additionalModuleRE = new RegExp(ADDITIONAL_MODULE_PATTERN);
20
20
  var additionalModuleGlobalRE = new RegExp(
21
21
  ADDITIONAL_MODULE_PATTERN,
@@ -29,7 +29,7 @@ function stripInternalEnv(internalEnv) {
29
29
  return userEnv;
30
30
  }
31
31
 
32
- // ../../node_modules/.pnpm/vite@6.1.0_@types+node@18.19.76_jiti@2.4.2_lightningcss@1.29.2/node_modules/vite/dist/node/module-runner.js
32
+ // ../../node_modules/.pnpm/vite@6.1.0_@types+node@20.17.32_jiti@2.4.2_lightningcss@1.29.2/node_modules/vite/dist/node/module-runner.js
33
33
  var VALID_ID_PREFIX = "/@id/";
34
34
  var NULL_BYTE_PLACEHOLDER = "__x00__";
35
35
  var SOURCEMAPPING_URL = "sourceMa";
@@ -1435,20 +1435,21 @@ async function getWorkerEntryExport(path, entrypoint) {
1435
1435
  }
1436
1436
 
1437
1437
  // src/runner-worker/index.ts
1438
+ var IGNORED_KEYS = ["self", "tailStream"];
1438
1439
  var WORKER_ENTRYPOINT_KEYS = [
1439
1440
  "fetch",
1441
+ "queue",
1440
1442
  "tail",
1443
+ "test",
1441
1444
  "trace",
1442
- "scheduled",
1443
- "queue",
1444
- "test"
1445
+ "scheduled"
1445
1446
  ];
1446
1447
  var DURABLE_OBJECT_KEYS = [
1447
- "fetch",
1448
1448
  "alarm",
1449
- "webSocketMessage",
1449
+ "fetch",
1450
1450
  "webSocketClose",
1451
- "webSocketError"
1451
+ "webSocketError",
1452
+ "webSocketMessage"
1452
1453
  ];
1453
1454
  var WORKFLOW_ENTRYPOINT_KEYS = ["run"];
1454
1455
  var entryPath = "";
@@ -1513,7 +1514,7 @@ function createWorkerEntrypointWrapper(entrypoint) {
1513
1514
  if (value !== void 0) {
1514
1515
  return value;
1515
1516
  }
1516
- if (key === "self" || typeof key === "symbol" || DURABLE_OBJECT_KEYS.includes(key)) {
1517
+ if (typeof key === "symbol" || IGNORED_KEYS.includes(key) || DURABLE_OBJECT_KEYS.includes(key)) {
1517
1518
  return;
1518
1519
  }
1519
1520
  const property = getWorkerEntrypointRpcProperty.call(
@@ -1611,7 +1612,7 @@ function createDurableObjectWrapper(className) {
1611
1612
  if (value !== void 0) {
1612
1613
  return value;
1613
1614
  }
1614
- if (key === "self" || typeof key === "symbol" || WORKER_ENTRYPOINT_KEYS.includes(key)) {
1615
+ if (typeof key === "symbol" || IGNORED_KEYS.includes(key) || WORKER_ENTRYPOINT_KEYS.includes(key)) {
1615
1616
  return;
1616
1617
  }
1617
1618
  const property = getDurableObjectRpcProperty.call(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudflare/vite-plugin",
3
- "version": "0.0.0-2d776aeed",
3
+ "version": "0.0.0-2e12e6e6f",
4
4
  "description": "Cloudflare plugin for Vite",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -33,18 +33,19 @@
33
33
  "dist"
34
34
  ],
35
35
  "dependencies": {
36
- "@hattip/adapter-node": "^0.0.49",
36
+ "@cloudflare/unenv-preset": "2.3.2",
37
+ "@mjackson/node-fetch-server": "^0.6.1",
38
+ "@rollup/plugin-replace": "^6.0.1",
37
39
  "get-port": "^7.1.0",
38
40
  "picocolors": "^1.1.1",
39
41
  "tinyglobby": "^0.2.12",
40
- "unenv": "2.0.0-rc.15",
42
+ "unenv": "2.0.0-rc.17",
41
43
  "ws": "8.18.0",
42
- "@cloudflare/unenv-preset": "0.0.0-2d776aeed",
43
- "wrangler": "0.0.0-2d776aeed",
44
- "miniflare": "0.0.0-2d776aeed"
44
+ "miniflare": "0.0.0-2e12e6e6f",
45
+ "wrangler": "0.0.0-2e12e6e6f"
45
46
  },
46
47
  "devDependencies": {
47
- "@cloudflare/workers-types": "^4.20250321.0",
48
+ "@cloudflare/workers-types": "^4.20250525.0",
48
49
  "@types/node": "^22.10.1",
49
50
  "@types/ws": "^8.5.13",
50
51
  "magic-string": "^0.30.12",
@@ -53,10 +54,10 @@
53
54
  "typescript": "^5.7.2",
54
55
  "undici": "^5.28.5",
55
56
  "vite": "^6.1.0",
56
- "vitest": "~3.0.8",
57
- "@cloudflare/mock-npm-registry": "0.0.0",
57
+ "vitest": "~3.1.1",
58
+ "@cloudflare/workers-shared": "0.0.0-2e12e6e6f",
58
59
  "@cloudflare/workers-tsconfig": "0.0.0",
59
- "@cloudflare/workers-shared": "0.0.0-2d776aeed"
60
+ "@cloudflare/mock-npm-registry": "0.0.0"
60
61
  },
61
62
  "peerDependencies": {
62
63
  "vite": "^6.1.0",